Support » Fixing WordPress » Page ordering not working on live page

  • Hi,

    I found a custom child pages code from this forum that allows to display the featured image and first couple of sentences of child pages on the parent page. It’s working beautifully, but I can’t seem to get the page ordering to work. Does anyone notice the flaw here?

    <?php
    /*
    Template Name: Child pages
    */
    
     get_header();?>
      <div id="main">
    		<div id="maintext">
          <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    			<header class="entry-header">
    				<h1 class="entry-title"><?php the_title(); ?></h1>
    			</header>
    
    			<div class="entry-content" style="clear:both;">
    
    				<?php the_content(); ?>
    
    				<?php
    				$args = array(
    					'post_parent' => $post->ID,
    					'post_type'   => 'page',
    					'post_status' => 'publish',
    					'numberposts' => -1
    				);
    
    				$postslist = get_posts($args);
    				?>
    
    				<?php foreach ( $postslist as $post ) : ?>
    
    					<?php setup_postdata( $post ); ?>
    
    					<div class="project">
    
    					<a href="<?php the_permalink(); ?>" style="float:left; padding: 0px 15px 0px 0px;"><?php if( has_post_thumbnail() ) the_post_thumbnail('Project'); ?></a>
    
    					<div class="project-meta">
    						<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    					</div><!-- project-meta -->
    
    					<div class="project-summary">
    						<?php the_excerpt(); ?>
    					</div><!-- project-summary -->
    
    					</div><!-- project -->
    
    				<?php endforeach; ?>
    
    			</div><!-- entry-content -->
    
    		<?php endwhile; endif; ?>
           </div><!-- end of maintext -->
    		</div><!-- end of main -->
    		<?php get_sidebar();?>
    		<?php get_footer();?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • You need to add the orderby parameter to your get_posts() arguments if you want to change the default ordering by date. See http://codex.wordpress.org/Function_Reference/WP_Query#Order_.26_Orderby_Parameters

    Thank You very much the quick answer, esmi . I tried to add the orderby ID parameter like this:

    $args = array(
    					'post_parent' => $post->ID,
    					'post_type'   => 'page',
    					'post_status' => 'publish',
    					'numberposts' => -1,
    					'orderby' => 'ID',
    
    				);
    
    				$postslist = get_posts($args);
    				?>

    So I just added the ‘orderby’ => ‘ID’, to the existing array, but it didnt change the result. Did I do something wrong?

    Ordering by ID and ordering by date (the default) could result in identical listings in some cases. What happens if you use 'orderby' => 'rand'?

    When using ‘rand’ , it started listing them by alphabetical order

    What theme are you using? Where did you download it from?

    I’m using the Centita theme from themeforest. I just remembered I also had the “simple page ordering” plugin enabled, so I disabled that. Now using ‘ID’ seems to give out an order based on page entry time and ‘rand’ seems to be random

    So it sounds like that plugin was causing your ordering problem. 🙂

    Actually it was my inexperience – I thought that ID means menu order, while in fact, there was a special tag for it 🙂 And the menu order plugin just added to the confusion. Thank You so much, esmi – you have been a huge help. The world would be awesome if there were more people like you.

    Glad I could help 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Page ordering not working on live page’ is closed to new replies.