Page listing wordpress (order by desc)

I have a self-created WordPress gallery which list page thumbnails. I have 3 (editorial, personal, fashion) Parent Pages for Child Pages (galleries).

I tried to list page Thumbnails from these 3 Parent Pages, but my listing has one problem. It is first listing all child thumbnails (pages) from the first id(editorial), then all child pages from id(personal) and finally it is listing all children of id(fashion). When I am adding a new gallery(page) (category : fashion), it is listing at the end of personal and at the beginning of its category. I need to list it at the beginning (by postdate) of the listing.

Read More

I’ll show what I have and attach a screenshot to make my question clearer. Will be happy for any help.

My current code:

<div class="base-content">

<div id="archive-thumbnails-listing" >
<?php $pages = array();
foreach (array(403, 414, 417) as $id) {
$pages = array_merge($pages, get_pages(array('child_of' => $id ,'sort_column' => 'post_date', 'sort_order' => 'desc' )));
} ?>
<?php foreach ($pages as $page): ?>
<div class="thumb12wrap"> 
<a href="<?php echo get_the_permalink($page->ID); ?>"> 
<?php echo get_the_post_thumbnail($page->ID, 'full'); ?></a> 
<div class="thumbwrapper88"> 
<div class="shade23desc" ><a class="desc" href="<?php echo get_the_permalink($page->ID); ?>"><?php echo $page->post_title; ?></a></div> 
<a class="descarea" href="<?php echo get_the_permalink($page->ID); ?>"></a> 
</div>
</div>   
<?php endforeach; ?>
</div>
<div style="float:left;height:50px;width:100%;position:relative;"></div>
</div>

http://i.stack.imgur.com/ACmOH.jpg IMAGE

Related posts

1 comment

  1. Your issue would appear to be that you are adding child pages to your $pages array in the order you are looping the parent IDs, then iterating over that array without sorting it.

    If you want all thumbnails of the children of the parent pages in order of date, it would be better to do it in a single query.

    This should work, but obviously can’t test it! The WP_Query uses post_parent__in to specify the parent IDs, and then sort all child results by date. I’ve used ‘the loop’ to iterate over the results.

    <div class="base-content">
    <div id="archive-thumbnails-listing" >
        <?php
        $gallery = new WP_Query(array(
            'post_type'       => 'page',
            'posts_per_page'  => -1,
            'post_parent__in' => array(403, 414, 417),
            'order'           => 'DESC',
            'orderby'         => 'date'
        ));
        ?>
        <?php while ($gallery->have_posts()) : $gallery->the_post() ?>
            <div class="thumb12wrap">
                <a href="<?php echo get_the_permalink(); ?>">
                    <?php echo get_the_post_thumbnail(get_the_ID(), 'full'); ?></a>
                <div class="thumbwrapper88">
                    <div class="shade23desc" >
                        <a class="desc" href="<?php echo get_the_permalink(); ?>">
                            <?php echo get_the_title() ?>
                        </a>
                    </div>
                    <a class="descarea" href="<?php echo get_the_permalink(); ?>"></a>
                </div>
            </div>
        <?php endwhile ?>
        <?php wp_reset_query() ?>
    </div>
    <div style="float:left;height:50px;width:100%;position:relative;"></div>
    

Comments are closed.