• Uncategorized
  • 0

WordPress -Show all pages in a category

This code is very helpful if you want to create an overview page that shows a link to each item within that category.
This also shows the Featured Image thumbnail if one is available.

$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT');

if ( $child_pages ) :
    foreach ( $child_pages as $pageChild ) :
        setup_postdata( $pageChild );
        $thumbnail = get_the_post_thumbnail($pageChild->ID, 'thumbnail');
        if($thumbnail == "") continue; // Skip pages without a thumbnail
        <div class="child-thumb">
          <a href="<?= get_permalink($pageChild->ID) ?>" rel="bookmark" title="<?= $pageChild->post_title ?>">
            <?= $pageChild->post_title ?><br /><?= $thumbnail ?>
<div style="clear:left;"></div>

Comment out the if($thumbnail ==””) line if you would like to show lines to all sub pages even if there is no thumbnail


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *