我正在尝试在父页面上显示子页面的标记。
在我的功能中。php:
// add tag support to pages
function tags_support_all() {
register_taxonomy_for_object_type(\'post_tag\', \'page\');
}
// ensure all tags are included in queries
function tags_support_query($wp_query) {
if ($wp_query->get(\'tag\')) $wp_query->set(\'post_type\', \'any\');
}
// tag hooks
add_action(\'init\', \'tags_support_all\');
add_action(\'pre_get_posts\', \'tags_support_query\');
在我的页面模板中:
<div id="masonry-loop" class = "group">
<?php
$pages = get_pages(\'child_of=\'.$post->ID.\'&sort_column=menu_order\');
$count = 0;
foreach($pages as $page)
{
$content = $page->post_content;
$images = get_field(\'gallery\', $page->ID);
$thumbnail = $images[0];
?>
<div class="artist_thumb">
<div class="artist_thumb_img"><a href="<?php echo get_page_link($page->ID) ?>" target="_blank"><img src="<?php echo $thumbnail[\'url\'] ?>"/></a></div>
<h3><a href="<?php echo get_page_link($page->ID) ?> "target="_blank"><?php echo $page->post_title ?></a></h3>
<p><?php echo $page->post_tag ?></p>
</div>
<?php
}
?>
</div>
这将显示子页面的缩略图和标题,但不显示标记。可能是什么问题?
最合适的回答,由SO网友:Jaeeun Lee 整理而成
我根据这篇帖子的答案修改了代码,页面显示了我现在想要的一切。
<div id="masonry-loop" class = "group">
<?php
global $post;
$child_pages_query_args = array(
\'post_type\' => \'page\',
\'post_parent\' => $post->ID,
);
$child_pages = new WP_Query( $child_pages_query_args );
if ( $child_pages->have_posts() ) : while ( $child_pages->have_posts() ) : $child_pages->the_post(); ?>
<?php $images = get_field(\'gallery\'); $thumbnail = $images[0]; ?>
<div class="artist_thumb">
<div class="artist_thumb_img"><a href="<?php the_permalink(); ?>" target="_blank"> <img src="<?php echo $thumbnail[\'url\'] ?>"/></a></div>
<h3><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></h3>
<p><?php the_tags(); ?></p>
</div>
<?php endwhile; endif; ?>
</div>