• I have been trying to implement the Show One Category Hack but it hasn’t been working. Previously I have used the following code in my-hacks.php

    <?php
    if (!isset($cat) && !isset($p)) $cat = -6;
    ?>

    This worked in that the posts were not on the first page, but the calendar and search functions do not work. So I was hoping that the Show One Category Hack would help. My-Hacks is enabled and Post Pages is set. I have upgraded to 1.02. Any ideas? Thanks.
    Mark

Viewing 14 replies - 1 through 14 (of 14 total)
  • I think that’s because that hack was designed for people who didn’t want a particular category to show on the first page, but still be accessable through the rest of the system. It sounds like you want to completely hide an entire category from everywhere. Not sure what can be done about that. Anyone got any ideas?
    TG
    ps: My next thought is… why even have the category if you are going to completely hide it?

    Try this code, instead:
    if (empty($_GET['cat'])) $cat = '-6';
    Depending on what you’re doing, you may want to put that at the top of wp-blog-header.php, instead of in index.php: with the above code in index.php, the “hidden” category posts will still be published in syndicated feeds (RSS, ATOM). But if you put it in wp-blog-header.php, hidden category posts will be suppressed everywhere they’re not specifically requested.

    TechGnome:
    I have a hidden category because I want to be able to post stuff in my blog, but not have to weed through _everything_ in the admin Edit screen. Using my blog gives me a quick-and-dirty way to draft up content.

    I guess I still don’t get it. By hiding it everywhere, it’ll never get viewed….. so that would be the point?
    TG

    Using the code above, it’s only hidden when not specifically reqeuested. For example, visit:
    http://www.skippy.net/blog/index.php
    and then visit:
    http://www.skippy.net/blog/index.php?cat=8
    I can create and edit rough drafts of articles, and share the link with anyone who I’d like to review my work, while preventing the work-in-progress from being published or syndicated. It’s just a convenience, really.

    Hi skippy,
    Perhaps the only problem I see in using:
    if (empty($_GET['cat'])) $cat = '-6';
    Is that the edit page in administration will also reflect that code and display only one category.
    Fixing that, I added:
    if ((empty($_GET[‘cat’]))&&(!preg_match(‘/wp-admin/’, $_SERVER[‘REQUEST_URI’]))) $cat = ‘1’; //Replace 1 with your category
    By using a match, I am able to exclude the wp-admin folder from applying this hack. However, there is probably a small execution time hit by using the preg_match function. It shouldn’t be anything concerning though.
    ~mikeXstudios

    mikexstudios – if you put it in index.php that isn’t an issue. Depends on where/when you do want it to display.
    TG

    Ah, good point. I was thinking in terms of the my-hacks.php file. So yeah, if the code goes in index.php, preg_match isn’t needed. In fact, that’s probably a better idea than putting it in my-hacks.php….
    *runs off to ponder*
    Thanks TG for the enlightenment.
    ~mikeXstudios

    Thread Starter Anonymous

    Nobody seems to like category 6 🙁

    hey,
    I am using the above code (the one wiht preg_match) in my-hacks.php. It does hide the category i want to hide, but it creates a problem: the posts-per-page setting is not respected anymore. How can i correct this?
    thanks

    Maybe it is not just this that is causing the posts_per_page setting to be ignored, anatman. Are you sure it works without it?

    I must be lucky or something, it works for me just fine, I have a category excluded from my main page, and yet my posts are limited to 5 per page…. um… as I think about it, I also have it set to “posts paged”(Options -> Reading -> Front Page -> Show the most recent….) Maybe that’s the diff???
    TG

    @’unregistered’: The only category that is displayed on my frontpage happens to be number six 🙂

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Show One Category Hack – Not working’ is closed to new replies.