这是我的代码,它显示了子页面的所有标题,但我还想要子页面的所有精美图像。我不知道如何做到这一点。我有包含page.php和我的function.php脚本。我知道很多人都问过这样的问题,但我似乎想不通。
Page.php
<?php
get_header();
if(have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post page">
<?php
if ( has_children() OR $post->post_parent > 0 ) { ?>
<nav class="site-nav children-links clearfix">
<span class="parent-link"><a href="<?php echo get_the_permalink(get_top_anestor_id); ?>"><?php echo get_the_title(get_top_ancestor_id()); ?> </a> </span>
<ul>
<?php
$args = array(
'child_of' => get_top_ancestor_id(),
'title_li' => ''
);
?>
<?php wp_list_pages($args); ?>
</ul>
</nav>
<?php } ?>
</article>
<?php endwhile;
else :
echo '<p> No content found</p>';
endif;
get_footer();
?>Function.php
function get_top_ancestor_id() {
global $post;
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
return $ancestors[0];
}
return $post->ID;
}
// Does page have children?
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);
}发布于 2018-12-18 19:55:57
所以我终于找到了同样步履蹒跚的人的答案:
<?php
$args = array(
'child_of' => get_top_ancestor_id(),
'title_li' => ''
);
?>
<?php $our_pages = get_pages($args); ?>
<?php if (!empty($our_pages)): ?>
<?php foreach ($our_pages as $key => $page_item): ?>
<div class="col-*-* product-object">
<a class="product-article" href="<?php echo esc_url(get_permalink($page_item->ID)); ?>">
<div class="product-image" style="background: url(<?php echo get_the_post_thumbnail_url($page_item->ID,'product-image');?>); ">
<h2 class="product-h2"><?php echo $page_item->post_title ; ?></h2>
</div>
</a>
</div>
<?php endforeach ?>
<?php endif ?>
</article>
</div>
<?php https://stackoverflow.com/questions/53812795
复制相似问题