0

I'm trying to display tags of child pages on the parent page.

In my functions.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');

In my page template:

<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>

This displays the thumbnails and titles of the child pages, but not the tags. What could be the issue?

0

I modified my code based on this posting's answer, and the page displays everything I want now.

<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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.