• Basically I’m looking for a plugin that will automatically sort posts how I want. Say, for example, I have category-6.php for a specific category. I’d like to sort that differently than other categories, say order ASC rather than DESC. Or perhaps on the home page I’d like to exclude a category or two.

    Any plugins that do this? TIA

Viewing 6 replies - 1 through 6 (of 6 total)
  • 1. Then use a customized Loop in the category-6.php template file.
    2. For hiding: http://ryowebsite.com/?p=46

    Thread Starter wyrd33

    (@wyrd33)

    So that’d be a no? 🙂 The problem with doing a customized loop in “category-6.php” would be that WordPress would have to query the database twice. Unless I’m way off base, when WordPress loads up category-6.php, it’s already done the query for the posts to display. If I wanted to display them in a different order, I’d have to requery the database. That’s not very efficient.

    Edit that existing loop in the category-6.php to do what you want. Why a second query? I don’t understand.

    I’d have to go trace the code again. I was also under the belief that you’d be doing a second query.

    A plugin would allow changing the original query on the fly… that’s certainly more work. 😉

    -d

    Thread Starter wyrd33

    (@wyrd33)

    moshu:

    Perhaps you could give an example of “edit the existing loop”. Or maybe point me to a link in the codex that explains it. Looking through the source code, there’s no reasonable way to do that. By the time WordPress gets to your category-6.php template, the posts have already been queried. Altering anything, including the order, would require another post retrieval from the database, thus another query.

    From the source code, this is how the logic goes:

    wp-blog-header
    -> wp-config
    -> -> wp-settings

    wp-settings creates the 3 main objects, $wp, $wp_query, and $wp_rewrite

    The functions.php for your template is then loaded. Here’s the kicker though. There’s been no query parsing yet, so you can’t use the conditional checks to see what page is being loaded. In fact, setting anything here in relation to the current request is useless, because when the $wp object is initialized, it will totally erase what you set.

    Now after wp-settings is done loading, we go back to wp-blog-header. The reason of the logic is as such:

    wp-blog-header

    -> the $wp object is initialized.
    -> wp-template-loader

    As you can see the $wp object is initialized before the templates are loaded, thus querying the database at the same time for the appropriate posts.

    As far as I can tell, to properly change the way your posts are being displayed without doing a second database hit (different order, whatever), you’ll have to either create a plugin, or add an action in your template’s functions.php page. You can then hook into the “pre_get_posts” action, which will allow you to change the query vars in $wp_query.

    So basically, no, I don’t believe you can just “edit the existing loop”.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Are there any plugins that allow sorting/costumization of posts?’ is closed to new replies.