WordPress.org

Ready to get started?Download WordPress

Forums

Filtering Main Post Loop & Themes (5 posts)

  1. ringmaster
    Member
    Posted 9 years ago #

    In my 1.2 blog I added $cat='-5'; before the require('./wp-blog-header.php'); to remove posts from that category.
    With the new template system, my main index file is in the wp-content/themes directory. The main $posts query is done by the main index.php provided in the core. If I have the code inserted in my theme, it does nothing.
    I'm assuming that I'll have to move my category filtering code to the main index.php, which will be overwritten each time I upgrade.
    Is this just a casualty of war, or is there a better way in 1.3?
    I also have some crafty code above that spot that redirects certain IP blocks elsewhere. I'd like to keep this intact, too.

  2. ringmaster
    Member
    Posted 9 years ago #

    Ok, so I wrote some code:
    <?php
    if(!preg_match('|\bcat=|i', $query_string)) {
    $query_string .= '&cat=-5';
    }
    $posts = query_posts($query_string);
    ?>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

    This fixes my problem but brings more questions to mind:
    Isn't it inefficient to do the unused query in wp-blog-header first?
    This code seems to cause a problem with the category cache. The update_category_cache() function gets called twice and all of the categories for each post are doubled up. So when they're displayed, the category should read "General" but instead it reads "General General". I think this is a problem with update_category_cache() not clearing the cache before it starts storing the values. At least, adding a line to clear the cache fixed the issue.
    After I got this to work, I used a second loop (I set $query_string completely myself for this one) to display the latest 3 posts from category 5 in a different location on the page.
    Anyone else have thoughts on this? Is there a better way to do it?

  3. Anonymous
    Unregistered
    Posted 9 years ago #

    What do you want done? When is the other cat you don't want to show About me, Downloads or something like that? If so, 1.3 has a built in page builder that makes, sort of static pages. That means, the about me and other things will not show in a cat and you can set links up for the aboutme like wordpress/site/aboutme. Is that what you wanting. You can edit the pages in wordpress also. Just like a post but not showing as a regular post.
    I think that is a very nice thing for wordpress to do. 1.3 is so far ahead of other blogs, cms it isn't funny. I have a test blog and it works just like I have always wanted. I have tried every other one out there even.
    Try a test 1.3 blog and see if that is what you want. If so just wait until it is done developing.
    Hope that helps

  4. ringmaster
    Member
    Posted 9 years ago #

    My original message only applies to the 1.3 blog I have currently installed.
    I don't want static pages.
    I want to display all posts in the main content area except for those in one specific category. On the same page in the sidebar, I want to display only the last 3 posts from that same specific previously-excluded category.
    I want a running list of links and I don't want to use the WordPress link manager. I want to run "asides" actually aside from the main content.
    Moreover, I want to know the correct way to implement querying a set of posts for display using the new WP_Query object. The object seems to cause a couple failure issues when you use it more than once on a page, so I thought I would bring these to light, since it's possible I'm doing it wrong.

  5. Anonymous
    Unregistered
    Posted 9 years ago #

    OH, I don't really know what you are talking about at all there. lol. I hope you get it though. It's way over my head.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.