How to sort pages alphabetically?

Discussion in 'WordPress' started by Carl29, May 31, 2011.

  1. #1
    Hi, I need to sort pages alphabetically,
    here's my code
    
    <div id="all-pages">
    <ul>
    <?php
        global $post;
        $args = array('include' => array(453,471,1248,459,458,469,457,463,465,473,475,494,477,479,481,487,489,491,
    	'sort_order' => 'ASC',
        'sort_column' => 'post_title',
    	)); 
        $posts = get_pages($args);
        foreach($posts as $post):
            setup_postdata($post);
    ?>
        <li>
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post->ID, 'full'); ?></a>
        </li>
    <?php endforeach; ?>
    </ul>
    </div>
    
    what am I missing?
    
    PHP:

     
    Carl29, May 31, 2011 IP
  2. joshpeyton

    joshpeyton Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you sorting pages or posts on a page? It looks like you are trying to list posts by alphabetical order. You would do that like this:

    <?php
    $args = array( 'numberposts' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?> 
    	<div>
    		<?php the_date(); ?>
    		<br />
    		<?php the_title(); ?>   
    		<?php the_excerpt(); ?>
    	</div>
    <?php endforeach; ?>
    PHP:
     
    joshpeyton, Jun 7, 2011 IP
  3. Carl29

    Carl29 Active Member

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    that is for posts, right?
    I want to list pages and only those ids 453,471,1248,459,458,469,457,463,465,473,475,494,477,479,481,487,489,491,
     
    Carl29, Jun 7, 2011 IP
  4. joshpeyton

    joshpeyton Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    something like

    <div id="all-pages">
    <ul>
    <?php
    
    $args = array('include' => array(453,471,1248,459,458,469,457,463,465,473,475,494,477,479,481,487,489,491,
        'sort_order' => 'ASC',
        'sort_column' => 'post_title',
        ));
    	$mypages = get_pages($args);
    
    	foreach($mypages as $page)
    	{		
    		$content = $page->post_content;
    		if(!$content) // Check for empty page
    			continue;
    
    		$content = apply_filters('the_content', $content);
    	?>
        <li>
    		<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
            <a href="<?php echo get_page_link($page->ID) ?>"><?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?></a>
            <div class="entry"><?php echo $content ?></div>
         </li>
    	<?php
    	}	
    ?>
    
    </ul>
    </div>
    PHP:
     
    joshpeyton, Jun 9, 2011 IP