WordPress.org

Ready to get started?Download WordPress

Forums

Order subpages by date (5 posts)

  1. Peter G.
    Member
    Posted 2 years ago #

    Hey folks, I'm tweaking a template and it has subpages within a page. I want to order the subpages by date (newest first).

    How can I do that?

    Here's what the code looks like:

    <div id="content">
        <?php if(is_front_page()) include( TEMPLATEPATH . '/lib/inc/slider.php'); ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="post">
          <h2<?php if(!has_post_thumbnail()) echo ' class="h2-nothumb"'; ?>>
            <?php the_title(); ?>
          </h2>
          <?php if((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
          <div class="post-img">
            <?php the_post_thumbnail('dli-large', array('alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
          </div>
          <?php endif; // endif post thumbnail ?>
          <?php the_content(); ?>
        </div>
        <?php endwhile; ?>
        <?php include( TEMPLATEPATH . '/lib/inc/subpages.php'); ?>
        <?php if(ts_get_option('ts_pages_comments')) comments_template('', true); ?>
      </div>
      <!-- end content -->
  2. vjpo
    Member
    Posted 2 years ago #

    The code that you want to edit is in the /lib/inc/subpages.php file :)
    You can learn about get_pages function and it's parameter 'sort_column' => 'post_date'.

  3. Peter G.
    Member
    Posted 2 years ago #

    Okay, here's what the subpages.php files looks like:

    <?php $subpages = new WP_Query('post_type=page&post_parent='.$post->ID.'&orderby=menu_order&order=ASC&showposts=-1'); ?>
    <?php if($subpages->have_posts()) : ?>
    
    <div id="subpages" class="con clearfix">
      <?php $subpages_title = get_post_meta($post->ID, 'subpages', true) ? get_post_meta($post->ID, 'subpages', true) : __('subpages', TS_DOMAIN); ?>
      <!-- <h3 class="h3-divider"><?php // echo $subpages_title; ?></h3> -->
      <?php $i=0; while ($subpages->have_posts()) : $subpages->the_post(); ?>
      <?php if($i%2==0) add_filter('post_class','ts_post_class_alt'); ?>
      <div class="subpage<?php if($i%2==0) echo ' post-alt'; ?>">
        <?php if((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
        <div class="post-img"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
          <?php the_post_thumbnail('dli-medium', array('alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'')); ?>
          </a> </div>
        <?php endif; // endif post thumbnail ?>
        <h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
          <?php the_title(); ?>
          </a></h3>
        <?php the_excerpt(); ?>
      </div>
      <!-- end post -->
      <?php $i++; endwhile; ?>
    </div>
    <!-- end subpages -->
    <?php wp_reset_query(); endif; // endif subpages ?>

    I tried changing order=ASC to order=DESC but it did nothing.

    Any ideas?

  4. vjpo
    Member
    Posted 2 years ago #

    Try to change
    WP_Query('post_type=page&post_parent='.$post->ID.'&orderby=menu_order&order=ASC&showposts=-1')
    to
    WP_Query('post_type=page&post_parent='.$post->ID.'&orderby= date&order=ASC&showposts=-1')

    orderby=date

    there is also modified among orderby parameters

  5. Peter G.
    Member
    Posted 2 years ago #

    That did the trick! Thank you, vjpo!

Topic Closed

This topic has been closed to new replies.

About this Topic