Support » Themes and Templates » Disabling sub category posts and alphabetizing posts by title

Disabling sub category posts and alphabetizing posts by title

  • I’m using WordPress as a CMS, and have a need to alphabetize posts, and at the same time limit the posts to only the parent category (no sub category posts). I’ve been using the following code in my functions.php:


    That works fine, but if I try to do something like this so that the posts are alphabetized, then I seem to get every post, even ones that aren’t in the related category in any way:

    $posts = query_posts($query_string .

    I got that little bit of code from here:

    Anyone know what I’m doing wrong and how to fix it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • What is being printed by $query_string? It may be that it’s contents are not what you need and thus screwing up your query.

    To only include your parent category/categories use &category=1,2,3, where 1,2,3 is the comma seperated list of the categories you want to include.

    If I var_dump $query_string right before the “$posts =” line, it returns NULL.

    I actually checked all of that code inside the twentyten theme, and it works fine. I think the problem is with my sub category template redirect:

    function product_library_sub_template(){
    	if (is_category()){
    		if (cat_is_ancestor_of('3', get_query_var('cat'))){
    			load_template(TEMPLATEPATH . '/product-library-sub-template.php');
    add_action('template_redirect', 'product_library_sub_template');

    The problem is, I need all of this to work like it is, just sorted alphabetically…

    So, as it turns out, when using my sub-category templates through the function load_template, it breaks my ability to alphabetize posts via the method documented in the codex. I ended up intercepting the posts before the load_template function, and used php’s uasort and strcasecmp functions to alphabetize them. It’s working perfectly. For anyone else attempting to do this, check the code at pastebin:


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disabling sub category posts and alphabetizing posts by title’ is closed to new replies.
Skip to toolbar