Support » Fixing WordPress » index.php – single category hack?

  • I’m playing around with trying to hack WP 1.3-alpha 4 into a CMS, the way I did for 1.2, and I find some of my old hacks don’t work. Specifically, I don’t know how to make index.php default to a specific category or post.
    I used to use this:
    if (!isset($cat)) {
    $cat = "1";

    But I don’t know where that would go in the new code.
    It used to go after
    $blog = 1;


Viewing 15 replies - 1 through 15 (of 29 total)
  • If I read you right, you want to force the category only on the main blog page. If that’s the case, try this just before require('./wp-blog-header.php');):
    if (empty($_SERVER['QUERY_STRING'])) {
    $cat = "1";

    That’s right. If someone loads the root directory, or “index.php” I want it to default to the category “1”. Then they can choose other categories. I used this in conjunction with another hack which displayed a menu of all the posts in each category. That way I can add content to each section of the site by simply assigning it a category. There are no category links – just links to the welcome page post in each category, from where people can navigate using the menu.
    Unfortunately, the code you provided doesn’t seem to do anything.
    Looking around the 1.3-a4 code, I see that they use something like this on occasion:
    <?php /* If this is the frontpage */ if (is_home()) { ?>
    <?php } ?>

    However, I can’t seem to get this to work for me either (replacing the ellipsis with $cat="1";).
    Any ideas?

    Well, I’m using a “theme” so it is “header.php” but yes, the same idea. I tried placing the code you specified after the following, to no avail:
    <?php /* Don't remove this line. */ require(ABSPATH . 'wp-blog-header.php'); ?>

    It’s supposed to be before wp-blog-header

    Sorry, I should have said before. But I tried it both ways to be safe and neither worked.

    Does variable $cat exist in WP 1.3? *shrug*

    It must, as I use it quite a bit. However, I’m not using 1.3’s template scheme. Can’t say why it’s not working for Luhmann.

    Ryan Boren


    WordPress Dev

    You have to place it at the beginning of the index.php that lives in home/root. Not the one in your theme. Or, you can try this plugin. However, for that plugin to work, you need a fix I just checked in to CVS. You’ll have to CVS update or wait for the next nightly.
    BTW, theme templates do not need to require wp-blog-header.php. This is done before the theme is loaded. That’s why $cat must be added to the index.php in home/root. Yes, this is confusing.

    Thanks! Adding it to index.php in root instead of the theme worked. The plugin looks great, I’ll switch to that after the next nightly build comes out.



    That’s great Ryan…
    Using this plug makes my Links list disappear though. Is there an easy way to add that back in?
    I’m using your port of Kubrick for 1.3A5

    Ryan Boren


    WordPress Dev

    When you set $cat or use that plugin, home page queries end up looking like category queries. Kubrick thinks a category is being queried and loads the archive template instead of the home page template. The archive template doesn’t include the links list. I’m going to create another version of the plugin that injects the front page category query without making the theme system think that a category archive was requested. Instead, it will treat the query like a regular home page query. I’ll work on that tomorrow.

    Ryan Boren


    WordPress Dev

    A new version of the plugin is up. You’ll need the latest nightly, 2004-12-02, for it to work.





    Version 0.2 of Rboren’s plugin is excellent. It does exactly what I want my WP 1.3 + Kubrick site to do… display one category, not as an archive, on my front page. Unfortunately, this plugin also limits my “Manage Posts” page to only the category I’ve coded into that plugin, when the plugin is active. 🙂
    Rboren, will you be able to fix? Or should I modify something in your code? Thank you!



    Thank you.
    your plugin works where everything else i have tried totally failed for so many reasons.
    Thank You.
    Not to detract from my sincere graditude, but i would like to better understand how you accomplished this.
    My index.php is sorted out perfectly now from the plug, but to achieve this in “pages” and other areas of my site is really important.
    I’ve looked at your dode. Literally, sat, thoughtless, staring at it. and it’s way over my head.
    You said that adding the $cat=x code to the index.php at the root of the site was the key, and yet all the code i’ve added there (when it worked) simply delivered an archive page instead of the index.
    so understand or not… thanks!

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘index.php – single category hack?’ is closed to new replies.