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 Page with Custom template. In this template I have index all posts of a category with many more modification. I know i can do this by creating Category specific template but this is different and I don't want to create category based template for every category.

Everything is fine but I'm trying to achieve post order by URL on this custom page template post. ASC order by URL working on Category page but not on custom page template.

  1. Example (with custom page) : http://www.projuktiteam.com/illustrator-tutorial/?order=asc (not working)
  2. Example (with category page) : http://www.projuktiteam.com/category/video-tutorials/illustrator-tutorial/?orderby=asc (working)

I also can order ASC the posts on this custom page from loop but i want to do this by URL. Because i want to provide user to sort the post by ASC, DESC, Title, Date etc.

<?php get_header(); ?>

    <iframe class="featured-trailer" width="950" height="534" src="//www.youtube.com/embed/<?php echo get_post_meta( get_the_ID(), 'trailer', true ) ?>" frameborder="0" allowfullscreen></iframe>

<?php get_template_part('cat-featured'); ?>

</div><!-- end .carousel -->

ID, "tut-category", true); ?>

<div id="content" role="main"><?php  ?> 
<div class="loop-header">
            <h1 class="tut-cat-title"><?php echo get_the_title(); ?></h1>
            <div class="tut-cat-count"><?php echo 'Total Posts = ' . $category->count; ?></div>
        </div><!-- end .loop-header --> 
<?php               

    if (have_posts()) :     
        query_posts("category_name=$tutcatname&showposts=25");  
        get_template_part('loop-actions');          
        get_template_part('loop-content');
        get_template_part('loop-nav');

    else :
        get_template_part('loop-error');
    endif; 

    wp_reset_query();
?>
</div><!-- end #content -->

share|improve this question
add comment

1 Answer

When you run an additional query, WordPress isn't going to automagically parse get vars, that only works for the main query. You have to fetch and add them manually.

Also, don't use query_posts, use WP_Query instead.

$args = array(
    'category_name' => $tutcatname,
    'posts_per_page' => 25,
);

if( isset( $_GET['order'] ) ){
    $args['order'] = $_GET['order'];
}

$query = new WP_Query( $args );
share|improve this answer
    
Thank you very much for your answer. I tried above code but that didn't work. Query function not working. So the page is showing no posts form category. This is how i pasted your code: <?php if (have_posts()) : $args = array( 'category_name' => $tutcatname, 'posts_per_page' => 25, ); if( isset( $_GET['order'] ) ){ $args['order'] = $_GET['order']; } $query = new WP_Query( $args ); get_template_part('loop-actions'); get_template_part('loop-content'); get_template_part('loop-nav'); else : ..... previous code ..... ?> –  Saiful Islam Nov 10 '13 at 19:40
add comment

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.