• Hello!

    I am using HTML5 Blank WordPress Theme for a to build a WordPress based website. I need to exclude all posts in a category (named “Locations”) from the blog posts list.

    That is not difficult in a simple, classic theme but, as I said above, I am using the HTML5 Blank theme and I don’t know how to perform that task. Can anyone tell me?

    Thank you!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    First of all, don’t edit the theme code, your changes will be lost when the theme is updated. Create a child theme or a simple plugin instead, details are in the Codex. Neither task is that difficult.

    There’s a number of approaches, this is probably the most efficient and works with any theme. You hook the ‘pre_get_posts’ action to alter all post queries run by WP. You want to place a conditional block so the exclusion is only applied to certain pages, or even admins will not be able to access the Locations posts. There is a long list if is_*() functions available for use in conditionals. Start with something like
    if ( is_home() || is_archive())
    Add in other identity functions as needed where Locations should be excluded, all related by the OR operator ||.

    Determine the category ID for Locations from either phpMyAdmin or by temporarily placing something like <?php echo 'Locations ID: '.get_cat_ID('Locations'); ?> on a theme template somewhere.

    Your action callback is passed the current WP_Query object. In the conditional block, use the object’s set() method to set “category__not_in” to an array containing the previously determined ID.

    A lot of words, but the final code is actually quite simple. I don’t provide code solutions here because it takes away from those trying to make a living. But all you need to know is in the Codex, and I’m willing to take the time to help you learn, the only other thing needed here is your desire to learn.

    If you don’t want to, that’s fine, there may be a plugin out there that might help you. I know little of available plugins though. The above outline still might help someone.

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude posts in a category from the posts page – HTML5 Blank WordPress Theme’ is closed to new replies.