WordPress.org

Ready to get started?Download WordPress

Forums

Page ordering not working on live page (9 posts)

  1. JaanMatti
    Member
    Posted 1 year ago #

    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();?>
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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

  3. JaanMatti
    Member
    Posted 1 year ago #

    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?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

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

  5. JaanMatti
    Member
    Posted 1 year ago #

    When using 'rand' , it started listing them by alphabetical order

  6. esmi
    Forum Moderator
    Posted 1 year ago #

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

  7. JaanMatti
    Member
    Posted 1 year ago #

    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

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    So it sounds like that plugin was causing your ordering problem. :-)

  9. JaanMatti
    Member
    Posted 1 year ago #

    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.

  10. esmi
    Forum Moderator
    Posted 1 year ago #

    Glad I could help :-)

Topic Closed

This topic has been closed to new replies.

About this Topic