Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a site that I'm having so much trouble to try to sort the order of a list of Pages based on their tag.

I've build this site over a year ago, with wordpress at the time there isn't any tag support for Page, so I used the plugin called tags4page. And I believe they still don't have tag support for pages ? Anyhow, my problem is if you go this page http://www.patentable.com/index.php/lawyers/ the list of Lawyers are in the right order. I can do this with wordpress build in order by giving each page a different weight.

However the problem is if you try to sort the list of Lawyers by selecting the drop down manual it will return a list of lawyers that are belong to this tag that you have selected. PROBLEM is the order are in reversed order for the lawyers. Is there any way to fix this ?

Right now my code is simple, basically is the following:

<?php if (have_posts()) : ?>

<?php /* If this is a tag archive */ if( is_tag() ) { ?>
  <h2>Lawyers in <i><?php single_tag_title(); ?></i> Practice Area:</h2>
<?php } ?>

<?php while (have_posts()) : the_post(); ?>
 <li>
 <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
 <?php the_title(); ?></a></li>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
share|improve this question
    
anybody any ideas ? –  Jonathan Dec 14 '10 at 8:17

1 Answer 1

up vote 1 down vote accepted

You could merge order parameters into the query when it's a tag page..

Replace the following lines.

<?php /* If this is a tag archive */ if( is_tag() ) { ?>
  <h2>Lawyers in <i><?php single_tag_title(); ?></i> Practice Area:</h2>
<?php } ?>

with..

<?php 
if( is_tag() ) { 
    $args = array_merge( 
        array( 'order' => 'asc', 'orderby' => 'title' ), 
        $wp_query->query
    );
    query_posts( $args ); ?>
    <h2>Lawyers in <em><?php single_tag_title(); ?></em> Practice Area:</h2>
<?php } ?>
share|improve this answer
    
Thank YOU soo much !! you are genius I changed orderby ID works out better :P Thanks again ! –  Jonathan Dec 14 '10 at 17:23
    
Happy to help.. :) –  t31os Dec 14 '10 at 17:54
    
hey by the way, what sort of attribute can i use to sort in the orderby ? I know "title" and "ID" works, can I try to sort them by the "order" value inside the wordpress Page ? –  Jonathan Dec 14 '10 at 23:51
1  
See here for possible orderby parameters: codex.wordpress.org/Function_Reference/… –  t31os Dec 15 '10 at 0:15
    
@t31os thanks once again !!! you saved my day can't thankful enough for this ! orderby menu_order is exactly what i needed :) –  Jonathan Dec 15 '10 at 0:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.