Forums

[resolved] Archive page results sorted by page order? (8 posts)

  1. Kahil
    Member
    Posted 11 months ago #

    Ok... I've been searching for hours using all kinds of key words and I can't find a single result that works. I've found code for sorting posts in ascending or descending order...or ordering by page title alphabetically, etc...but not page/post order.

    I have pages that all have specific tags (using a plugin that lets me assign tags to pages). My archive page returns the results correctly for the specific tag, but I want to make sure the results are in a specific order using the page order. I've tried everything I can think of , but nothing seems to work. Either nothing happens or I get an error. Any thoughts/ideas?

    Here's my archive page code:

    <?php get_header(); ?>
    <div id="pagename">
            <div class="inside">
    		<?php if (have_posts()) : ?>
    
    		<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    		<?php /* If this is a category archive */ if (is_category()) { ?>
    		<h2>Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>
    		<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    		<h2><?php single_tag_title(); ?></h2>
    		<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    		<h2>Archive for <?php the_time('F jS, Y'); ?></h2>
    		<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    		<h2>Archive for <?php the_time('F, Y'); ?></h2>
    		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    		<h2>Archive for <?php the_time('Y'); ?></h2>
    		<?php /* If this is an author archive */ } elseif (is_author()) { ?>
    		<h2>Author Archive</h2>
    		<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    		<h2>Blog Archives</h2>
    		<?php } ?>
            </div>
          </div>
        </div>
        <!-- container END here -->
      </header>
      <!-- header END here -->
      <!-- content START here -->
      <div id="content">
        <!-- container START here -->
        <div class="container">
          <!-- main-colum START here -->
          <div id="full-width">
    		<?php while (have_posts()) : the_post(); ?>
    		<div id="post-<?php the_ID(); ?>" style="float:left;">
            <a href="<?php the_permalink() ?>" rel="bookmark"><div class="portfolio"><?php the_post_thumbnail(); ?><br /><?php the_title(); ?></div></a>
            </div>
    		<?php endwhile; ?>
            <?php else : ?>
          <h3>Not Found</h3>
          <p>Try using the sidebar to navigate yor way around the site.</p>
          <?php endif; ?>
          <?php  wp_pagenavi();  ?>
          </div>
          <!-- main-colum END here -->
        </div>
        <!-- container END here -->
      </div>
      <!-- content END here -->
    </div>
    <!-- site-wrapper END here -->
    <?php get_footer(); ?>
  2. vtxyzzy
    Member
    Posted 11 months ago #

    I think you can do what you want using a filter on the query. Add this code to functions.php:

    function mam_posts_orderby ($orderby) {
       global $mam_global_orderby;
       if ($mam_global_orderby) $orderby = $mam_global_orderby;
       return $orderby;
    }
    add_filter('posts_orderby','mam_posts_orderby');

    and modify your archive page code by changing this:

    <?php get_header(); ?>
    <div id="pagename">

    to this (UNTESTED!!):

    <?php get_header(); ?>
    <?php if ( is_tag() ) {
       global $wpdb;
       $mam_global_orderby = "$wpdb->posts.menu_order ASC";
    }
    ?>
    <div id="pagename">
  3. Kahil
    Member
    Posted 11 months ago #

    I'll see if that'll work....but it does seam like an over complicated solution...

  4. vtxyzzy
    Member
    Posted 11 months ago #

    Sorry, I left out the step of re-issuing the query. Your archive page code should be this:

    <?php get_header(); ?>
    <?php if ( is_tag() ) {
       global $wpdb, $wp_query;
       $mam_global_orderby = "$wpdb->posts.menu_order ASC";
       query_posts($wp_query->query);
       $mam_global_orderby = '';
    }
    ?>
    <div id="pagename">
  5. Kahil
    Member
    Posted 11 months ago #

    That didn't work....still orders them in the order they were created... Guess I can go in and change the dates on everything, but that is just very time consuming.

  6. Kahil
    Member
    Posted 11 months ago #

    Here's what works! :) I just did a small mod to the loop. So...In combination with this lil snippet of code and using a plugin that lets me drag and drop page order and a plugin that lets me tag pages....it makes it really easy to manage a large portfolio with lots of pages, etc.

    Hope this helps others in the future...

    <?php $posts = query_posts($query_string . '&orderby=menu_order&order=asc&posts_per_page=-1'); while (have_posts()) : the_post(); ?>
  7. belindajohnstone
    Member
    Posted 8 months ago #

    I have just spent a day searching all kinds of keywords also, and I finally found this thread.

    I have also installed a plugin that adds tags to pages, and now I want to list excerpts for each tag in alphabetical order.

    I tried your final solution Kahil, and it does produce the correct order, but somehow it is pulling in the category archive from my posts not my tag archive from my pages??

    link to site

    This is the code that gets me closest. I put together this loop-tag.php through trial and error from the loop.php on twentyten, my PHP is not great.

    I'm almost there though, just need to know what to replace
    tag=presbyterian-schools with so that I can get each tag archive ordered alphabetically on it's own page.

    <?php
    /**
     * The loop that displays tags.
     *
     * The loop displays the posts and the post content.  See
     * http://codex.wordpress.org/The_Loop to understand it and
     * http://codex.wordpress.org/Template_Tags to understand
     * the tags used in it.
     *
     * This can be overridden in child themes with loop-page.php.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.2
     */
    ?>
    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    $posts = query_posts($query_string .
    '&orderby=title&order=asc&tag=presbyterian-schools&posts_per_page=-1'); ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    			<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
    	<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
    			<div class="entry-summary">
    				<?php the_excerpt(); ?>
    			</div><!-- .entry-summary -->
    		<?php endif; ?>
    
    			<div class="entry-utility">
    				<?php if ( count( get_the_category() ) ) : ?>
    					<span class="cat-links">
    						<?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
    					</span>
    					<span class="meta-sep">|</span>
    				<?php endif; ?>
    				<?php
    					$tags_list = get_the_tag_list( '', ', ' );
    					if ( $tags_list ):
    				?>
    					<span class="tag-links">
    						<?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
    					</span>
    					<span class="meta-sep">|</span>
    				<?php endif; ?>
    						<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    						<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
    					</div><!-- .entry-content -->
    				</div><!-- #post-## -->
    
    <?php endwhile; // end of the loop. ?>
  8. belindajohnstone
    Member
    Posted 8 months ago #

    Actually I've done it... a lot of trial and error, but the code on the following tag.php works perfectly.(the previous one must have had php problems that I just can't work out at my level.

    <?php
    /**
     * The template for displaying Tag Archive pages.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    
    get_header(); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    $posts = query_posts($query_string .
    '&orderby=title&order=asc&posts_per_page=-1'); ?>
    	<?php if (have_posts()) : ?>
    
    	<?php /* If this is a tag archive */ if (is_tag()) { ?>
    	<h1><!--Archive for the--> <?php single_tag_title(); ?></h1>
    	<?php } ?>
    
    		<!--<p><?php next_posts_link('&laquo; Older Entries') ?> | <?php previous_posts_link('Newer Entries &raquo;') ?></p>-->
    
    		<?php while (have_posts()) : the_post(); ?>
    
    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    			<div class="entry-content">
    			<?php the_excerpt() ?>
    			<p><<?php the_tags('Tags: ', ', ', ' '); ?><br/>
    			<?php edit_post_link('<br/> Edit', '', '  '); ?></p>
    		</div>
    
    		<?php endwhile; ?>
    
    		<!--<?php next_posts_link('&laquo; Older Entries') ?> | <?php previous_posts_link('Newer Entries &raquo;') ?>-->
    
    	<?php else :
    
    		if ( is_tag() ) { // If this is a tag archive
    			printf("<h2>Sorry, but there aren't any schools in the %s category yet.</h2>", single_tag_title('',false));
    		} else {
    			echo("<h2>No posts found.</h2>");
    		}
    		get_search_form();
    
    	endif;
    ?>
    </div><!-- #content -->
    <?php get_sidebar(); ?>
    		</div><!-- #container -->
    <?php get_footer(); ?>

Reply

You must log in to post.

About this Topic