• I use two templates for two pages to distribute my posts in. Therefor I copied the ‘pageofposts’ template that only displays those categories in the frontend specified in the template. Very useful. Now, for one page I would like to change the order of appearance. Not the newest first but the oldest, and add the newer ones at the end of the page. Like sort of archive. Could this ne achieved in a ‘simple way’? thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this form of the loop for an oldest first post page; the difference from a “standard” WP loop is the <?php query_posts($query_string . '&orderby=date&order=ASC'); ?> line:

    <?php get_header(); ?>
    
    (html stuff)
    
    <?php query_posts($query_string . '&orderby=date&order=ASC'); ?>
    
    <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>"> (etc, more html)
    
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php else : ?>
    
    (html stuff)
    
    <?php endif; ?>

    Should work, but there might be other loop stuff that conflicts, depending on your theme.

    Thread Starter foxeye

    (@foxeye)

    can’t get it to work still. What piece of the template do i need to alter? this is the code:

    <?php
    // page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
    if (is_page('111') ) {
    $cat = array(1);
    } elseif ( is_page('54') ) {
    $cat = array(6);
    } elseif ( is_page('28') ) {
    $cat = array(17);
    } else {
    $cat = '';
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    <h1><?php the_title(); ?></h1>
    <div class="clearfix"></div>
    
    	<?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<h2><?php the_title(); ?></h2>
    <div class="entry">
    					<?php the_content('Read the rest of this entry ?'); ?>
    				</div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change sortorder posts for one page’ is closed to new replies.