WordPress.org

Ready to get started?Download WordPress

Forums

index.php - single category hack? (29 posts)

  1. Kafkaesqui

    Posted 9 years ago #

    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";
    }

  2. Kerim
    Member
    Posted 9 years ago #

    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?

  3. Kerim
    Member
    Posted 9 years ago #

    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'); ?>

  4. Joshua Sigar
    Member
    Posted 9 years ago #

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

  5. Kerim
    Member
    Posted 9 years ago #

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

  6. Joshua Sigar
    Member
    Posted 9 years ago #

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

  7. Kafkaesqui

    Posted 9 years ago #

    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.

  8. Ryan Boren
    WordPress Dev
    Posted 9 years ago #

    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.

  9. Kerim
    Member
    Posted 9 years ago #

    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.

  10. motoed
    Member
    Posted 9 years ago #

    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

  11. Ryan Boren
    WordPress Dev
    Posted 9 years ago #

    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.

  12. Ryan Boren
    WordPress Dev
    Posted 9 years ago #

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

  13. asknight
    Member
    Posted 9 years ago #

  14. gsoli
    Member
    Posted 9 years ago #

    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!

  15. dss
    Member
    Posted 9 years ago #

    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!

  16. nolageek
    Member
    Posted 9 years ago #

    I'm using the Front Page Category pluging and love it, although I noticed something that I dont like. I changed the number of posts in Options > General to 1, because I only want the last news article to apear on the front page - although this also seems to effect archive pages as well.
    How can I just make it so I only have 1 article on the home page, but 10 to a page in the archives?

  17. gsoli
    Member
    Posted 9 years ago #

    Isharra, thanks for the hack! It did the trick.

  18. gour
    Member
    Posted 9 years ago #

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

    rboren: Thanks a lot. It works with the 1.5beta (20050126 build).

    Sincerely,
    Gour

  19. gour
    Member
    Posted 9 years ago #

    Is it possible to include this plugin in a regular distribution?

    It is a very useful one.

    Sincerely,
    Gour

  20. Stephan_G
    Member
    Posted 9 years ago #

    You made my day! Thanks for that great plugin!

  21. pixelss
    Member
    Posted 9 years ago #

    This plug-in is great but, if i click on any other category of my left side menu, what i get is the post as archived ...

  22. rdub
    Member
    Posted 8 years ago #

    When I use this plug in I get the message Sorry, no posts matched your criteria.

  23. Joshua Sigar
    Member
    Posted 8 years ago #

    If you want to display Posts of certain categories on the frontpage, download the following plugin (probably more updated version). The instruction is in the file.
    http://dev.wp-plugins.org/file/front-page-cats/trunk/front_page_cats.php?rev=57&format=raw

  24. rdub
    Member
    Posted 8 years ago #

    That is the plug in I used. Changed the category to show to "idyllwild", which is my category, and I get the same message.

  25. rdub
    Member
    Posted 8 years ago #

    It appears there is only one variable to change in the plugin. Is that correct? Do I have to change any other file?

  26. moshu
    Member
    Posted 8 years ago #

    Shouldn't there be the cat ID# and not the cat name?

  27. rdub
    Member
    Posted 8 years ago #

    You are correct. Thank you.

    I see the topics no longer have a space between them. Is it simple to add that?

  28. moshu
    Member
    Posted 8 years ago #

    I don't see it :0
    What do you call a topic? I know there topics here in the forum.

  29. rdub
    Member
    Posted 8 years ago #

    Perhaps I should use the term post.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.