Итак, это мой код, он показывает все заголовки дочерних страниц, но мне также нужны все изображения дочерних страниц. И я понятия не имею, как этого добиться. У меня есть incldue 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);
}
Итак, я наконец нашел ответ для людей, которые тоже нанизывают:
<?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