WordPress.org

Ready to get started?Download WordPress

Forums

Allow user to sort post (3 posts)

  1. DarioDN
    Member
    Posted 4 years ago #

    Hi guy... by query_posts I've listed my posts.
    So, I would allow user to change order the list by parameters like "author" or "custom field".
    Now, I'm writing this code:

    <?php $sort= $_GET['order'];
    if($sort == "A")
    {
    $order= "orderby=title";
    }
    if($sort == "B")
    {
    $order= "orderby=author";
    }
    ?>
    
    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn" role="main">
    
    <h2><?php the_title(); ?></h2>
    
    <a href="?sort=A">title</a>
    <a href="?sort=B">author</a>
    
    <?php query_posts($order.'&order=ASC');  ?>
    
    <ul>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <li>	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></li>
    
    		<?php endwhile; endif; wp_reset_query();?>
    </ul>

    But it doesn't works... How can I do!?

  2. tugbucket
    Member
    Posted 4 years ago #

    your first line is wrong. Try this:

    <?php $sort= $_GET['sort'];

    you want to GET the the value of SORT

  3. DarioDN
    Member
    Posted 4 years ago #

    tnx :)

Topic Closed

This topic has been closed to new replies.

About this Topic