Disabling sub category posts and alphabetizing posts by title (5 posts)

  1. skunkbad
    Posted 5 years ago #

    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?

  2. David Gard
    Posted 5 years ago #

    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.

  3. skunkbad
    Posted 5 years ago #

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

  4. skunkbad
    Posted 5 years ago #

    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...

  5. skunkbad
    Posted 5 years ago #

    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:


Topic Closed

This topic has been closed to new replies.

About this Topic