What do you mean by ‘can’t get it to work ‘ ?
Errors ? More than one cat showing ?
Thread Starter
poper
(@poper)
I mean that nothing happens, all categories are shown (as usual). No error messages.
Try just this:
<?php
$blog = 1;
$cat=”1″;
/* Don’t remove this line. */
require(‘./wp-blog-header.php’);
?>
If that doesn’t work, you could try mootkitty’s show categories plug-in:
http://mookitty.co.uk/devblog/category/show-categories/
Thread Starter
poper
(@poper)
I’ve tried show-categories and it just works really fine. Thanks a lot!
It seems that the “show one category” hack (from the wiki) is broken in the latest build of 1.3.
http://www.wiki.wordpress.org/ShowOneCategory
Anyone know how to fix it? I really need this implementation, because as far as I can tell the “show-categories” plugin doesn’t seem to have the same functionality. What I want is the ability to have index.php show the default category only when no other category is selected, not to permanently exclude any categories.
Thanks!
It is broken in 1.2 also.
Best way to do this is like so:
if (!isset($cat)) {
$cat = "X";
}
Where X is the category you want to show. If you want to show more than on then it’s “X,Y, Z,….” If you want to exclude a category – and at the moment, at least in 1.2 – you can only exclude one category, it’s like this: $cat = “-X”; Again, where X is the category you want to exclude.
TG
TG –
Where do you put that code? In the loop?
Thanks,
Hal Atkins
no no no no. IMMEDIATLY after the $blog=1; which should be the second line in the index.php file. Like so:
<?php
$blog = 1;
if (!isset($cat)) {
$cat = "X";
}
/* Don't remove this line. */
require('./wp-blog-header.php');
TG
Thanks, TG-
Works well, and appreciate your help. I understand, setting the $cat variable – out of interest, what is the $blog variable? Is it for multiple blogs on the site?
Hal
Not sure…. it’s something that has been there since I’ve been using WP. Don’t really know what it’s for. If it isn’t there, I wouldn’t worry about it.
TG
I had the same dilemma, but instead of searching the forums here (as I should have!), I went and created an index.html which just redirects to index.php?cat=1. So far, it works, but is there any downside to using such a “dirty trick” to get only one category shown?
Cheers, Joey (aka Pepe)
some of the links generated by WP point right to the index.php file, which would skip your redirect. Also, it is possible to disable redirects in a browser (I’ve known people to do this) and so they would never get to your file. Also, I don’t know how you feel about it, but you may also run into problems with search engines indexing the site properly -some people care about such things, others don’t, I meerly point it out.
TG