• Resolved breakingball

    (@breakingball)


    I need to change the display order to ASC for a single blog category (ID=79), leaving all other categories displaying in descending order.

    I’m working with my theme’s archive.php file and I’m wondering if this is possible to do within is_category and if so, how to do it.

    I’ve also created a category-79.php file which I’ve copied from archive.php in case I need to achieve this with a custom template, although I’m not sure where to go from there, either.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You’re probably better off doing the category.php file. I’m not sure whether category-79.php will work, or whether you need to save in the format category-slug.php…

    Either way, make the separate category template file, and before the loop, call the query manually:
    query_posts('cat=79&order=ASC');
    The above should override the query defaults. You might have to add a few parameters to get the listing working precisely how you expect:

    query_posts() in Codex

    John

    Thread Starter breakingball

    (@breakingball)

    Thanks, John. First impression is that your suggestion worked perfectly. I went with category-slug.php, and reading the Codex article, I’m pretty sure that no other parameters are needed.

    I appreciate the help.

    Hopefully not LITERALLY category-slug.php — I meant replace ‘slug’ with whatever the slug of that category is. So if the cat slug is books, the file would be category-books.php. Sorry, should have been clearer about that.

    Thread Starter breakingball

    (@breakingball)

    ?? Thanks, but naming the template was the easy part.

    I seem to have a problem with pagination with the new template.

    This category has 7 posts, but where I display 6 posts per page, Page 2 of the category I’ve modified shows the same first 6 posts as Page 1 in the category rather than showing the 7th post as I’d expect.

    I’m wondering whether I need to include get_query_var( 'paged' ) somewhere in there, but I’m not clear about the syntax for including that in the query I inserted into the new template….

    Thread Starter breakingball

    (@breakingball)

    No sleep till Brooklyn.

    I finally figured out that I just needed to merge the original query array into the new parameter array, like so:

    global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => 79,
    			'order' => ASC),
    		$wp_query->query
    	)
    );

    Thanks to John and the Codex.

    Nicely done, and you’re welcome.

    In the interests of the portability of your theme, you might consider applying a variable for your cat number:

    $cat = get_query_var(‘cat’); // Gets the current ID number for the category

    And then making ‘cat’ => $cat instead. This will ensure that the query is being run in relation to the name of the category, rather than the ID.

    J

    Thread Starter breakingball

    (@breakingball)

    Thank you. I think that’s a good suggestion, but I’m not sure I understand how to implement it here. :\

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change display order for single category’ is closed to new replies.