WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Listing subpages with their thumbnails (6 posts)

  1. jigowatt
    Member
    Posted 4 years ago #

    Hi,

    I'm using the following code to display a pages subpages;

    <?php
    					// If CHILD_OF is not NULL, then this page has a parent
    					// Therefore, list siblings i.e. subpages of this page's parent
    					if($post->post_parent){
    						wp_list_pages('title_li=&include='.$post->post_parent);
    						wp_list_pages('title_li=&child_of='.$post->post_parent);
    						}
    					// If CHILD_OF is zero, this is a top level page, so list subpages only.
    					else{
    						wp_list_pages('title_li=&include='.$post->ID);
    						wp_list_pages('title_li=&child_of='.$post->ID);
    						}
    					?>
    					</ul>

    And it's working perfectly. However, these subpages are galleries and I would love to display the page thumbnail in the outputted list so that the user catches a glimpse of the gallery instead of just seeing a text link.

    Surely there's any easy way to do this!

  2. jigowatt
    Member
    Posted 4 years ago #

    Sorted it myself using the following code:

    <ul class="subpages">
    <span style="display:none;"><?php the_ID(); ?></span>
    <?php $parent = $post->ID; ?>
    <?php
    query_posts('posts_per_page=15&post_type=page&post_parent='.$parent);
     while (have_posts()) : the_post();
    ?>
    
    <?php $image_thumb = get_post_meta($post->ID, 'image-thumb', true); ?>
    <li><?php the_post_thumbnail(); ?>
    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4></li>
    
    <?php endwhile; ?>
    </ul>
  3. tinygiantstudios
    Member
    Posted 4 years ago #

    Fantastic - thanks for the post - works perfectly!

  4. aravere
    Member
    Posted 3 years ago #

    Do you have a link to show what this looks like?

    Also, where do you place this code? (what directory/file)?

    I'm trying to do the same thing- have a parent page with thumbnail links to the child pages/posts.

    Thanks!

  5. Auroris_Design
    Member
    Posted 3 years ago #

    This lists out the subpages, but I can't get the thumbnails to show up.

    I'm getting this error:
    Fatal error: Call to undefined function the_post_thumbnail()

    Could you show us what you're entire template code looks like?

  6. post@asbjornpettersen.com
    Member
    Posted 3 years ago #

    If you put the code inside the_loop it will output the entire page, but if you put this code outside the loop, this is most likely after / below the last <?php endif; ?> this will create only a list of subpages with thumbnail.

    on my customers page i did it like this:

    <?php endwhile; else : ?>
    <?php endif; ?>
    
    <ul class="subpages">
    <span style="display:none;"><?php the_ID(); ?></span>
    <?php $parent = $post->ID; ?>
    <?php
    query_posts('posts_per_page=15&post_type=page&post_parent='.$parent);
     while (have_posts()) : the_post();
    ?>
    
    <?php $image_thumb = get_post_meta($post->ID, 'image-thumb', true); ?>
    <li><?php the_post_thumbnail('single-blog-thumbnail'); ?>
    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4></li>
    
    <?php endwhile; ?>
    </ul>

    I hope this is understandable...

Topic Closed

This topic has been closed to new replies.

About this Topic