Sort items in archive.php

  • Unknown's avatar

    I am trying to allow a user to sort the posts on the archive.php file by most commented or most recent. If I change the archive.php page to include this code based a querystring parameter, it doesn’t respect the month and year in the URL; it just displays all posts.

    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $args= array(
    ‘orderby’ => ‘comment_count’,
    ‘order’ => ‘DESC’,
    ‘paged’ => $paged
    );
    query_posts($args);

    Is there a way for me to grab the month and year out of the URL so that I can display just the posts for that month and year? If so, I can add it to the arguments in the $args array.

    PS — I am using the out of the box archive widget to get to the site.com/year/month page (which displays the archive.php from the site theme).

  • Unknown's avatar

    You did not specify a blog address or reason for posting when you created this topic.

    This support forum is for blogs hosted at WordPress.com. If your question is about a self-hosted WordPress blog then you’ll find help at the WordPress.org forums.

    If you don’t understand the difference between WordPress.com and WordPress.org, you may find this information helpful.

    If you forgot to include a link to your blog, you can reply and include it below. It’ll help people to answer your question.

    This is an automated message.

  • The topic ‘Sort items in archive.php’ is closed to new replies.