Title: index.php &#8211; single category hack?
Last modified: February 7, 2017

---

# index.php – single category hack?

 *  [luhmann](https://wordpress.org/support/users/luhmann/)
 * (@luhmann)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/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 <?php  $blog = 1;  Thanks!

Viewing 15 replies - 1 through 15 (of 29 total)

1 [2](https://wordpress.org/support/topic/index-php-single-category-hack/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/index-php-single-category-hack/page/2/?output_format=md)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111569)
 * 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"; }
 *  Thread Starter [luhmann](https://wordpress.org/support/users/luhmann/)
 * (@luhmann)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111574)
 * 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?
 *  Thread Starter [luhmann](https://wordpress.org/support/users/luhmann/)
 * (@luhmann)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111577)
 * 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'); ?>`
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111578)
 * It’s supposed to be before wp-blog-header
 *  Thread Starter [luhmann](https://wordpress.org/support/users/luhmann/)
 * (@luhmann)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111579)
 * Sorry, I should have said before. But I tried it both ways to be safe and neither
   worked.
 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111584)
 * Does variable `$cat` exist in WP 1.3? *shrug*
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111585)
 * 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](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111593)
 * 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](http://boren.nu/downloads/front_page_cats.phps).
   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.
 *  Thread Starter [luhmann](https://wordpress.org/support/users/luhmann/)
 * (@luhmann)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111604)
 * 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.
 *  [motoed](https://wordpress.org/support/users/motoed/)
 * (@motoed)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111992)
 * 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](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111993)
 * 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](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111995)
 * A new version of the plugin is [up](http://boren.nu/downloads/front_page_cats.phps).
   You’ll need the latest nightly, 2004-12-02, for it to work.
 *  [asknight](https://wordpress.org/support/users/asknight/)
 * (@asknight)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-111997)
 * see also : [http://wordpress.org/support/index.php?action=vthread&forum=3&topic=10759&page=-1#post-102779](http://wordpress.org/support/index.php?action=vthread&forum=3&topic=10759&page=-1#post-102779)
 *  [gsoli](https://wordpress.org/support/users/gsoli/)
 * (@gsoli)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-112003)
 * Version 0.2 of Rboren’s [plugin](http://boren.nu/downloads/front_page_cats.phps)
   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!
 *  [dss](https://wordpress.org/support/users/dss/)
 * (@dss)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/#post-112007)
 * **rboren**:
    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)

1 [2](https://wordpress.org/support/topic/index-php-single-category-hack/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/index-php-single-category-hack/page/2/?output_format=md)

The topic ‘index.php – single category hack?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 29 replies
 * 14 participants
 * Last reply from: [rdub](https://wordpress.org/support/users/rdub/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/index-php-single-category-hack/page/2/#post-112116)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
