WordPress.org

Forums

Option for showing one categorie on home page (17 posts)

  1. gijs25
    Member
    Posted 10 years ago #

    Hello,

    I am looking for an option that wil allow me to set one catagory to show on the main/home page, still the categorie list remains but the start page only shows for example the "General" Categorie.

    I found from kitten plugins:
    http://mookitty.co.uk/devblog/category/show-categories/

    But i can't find any plugin or code there.

    Thanks for any assistance
    G

  2. Kafkaesqui

    Posted 10 years ago #

    Kitten's Show Categories is here:

    http://mookitty.co.uk/devblog/downloads/

    ShowCats does not work with 1.5. For that, look here:

    http://wordpress.org/support/6/17139#post-98340

    Or, you can place this in index.php (the one in your blog's root, and not your theme's) before require('./wp-blog-header.php');:

    if (is_home()) {
    $cat = "CATEGORYNUM";
    }

    Replace CATEGORYNUM with the numeric ID of the category you want displayed on the home page.

  3. Lara
    Member
    Posted 10 years ago #

    For some reason this will not work for me?

  4. Bert
    Member
    Posted 10 years ago #

    Hi,

    I was about to post a similar question, when I found this thread.
    My problem : When opening the site, shouldn't it open the default page, called "general" in WP-default? Right or wrong?

    Please have a look at my (foetus;-)) site:

  5. http://www.greentoilets.org
  6. It does open in the "general" category (here called "news"), but it shows the entries in the other categories as well. However after clicking another categoty in the menu-bar and then going back to the "news" (ex-'general') page, it only shows the posts in "news", as it should be.

    So, what could be wrong? Or do I need the piece of code mentioned in the above thread?

    Thanks!
    Bert

  • Kafkaesqui

    Posted 10 years ago #

    Lara: What version of WordPress are you using? The code above is meant for 1.5. For 1.2, try:

    if (empty($_SERVER['QUERY_STRING'])) {
    $cat = "CATEGORYNUM";
    }

    Bert: When WordPress displays all categories on the home or front page, it's working as intended.

  • Lara
    Member
    Posted 10 years ago #

    I am using 1.2.2. I will try that. Thank you :)

  • Lara
    Member
    Posted 10 years ago #

    Yay, it works. Thank you Kafkaesqui.

  • Bert
    Member
    Posted 10 years ago #

    Thank you Kafka,

    "When WordPress displays all categories on the home or front page, it's working as intended."

    I understand this is useful for a pure blogging site, but for a more classic site, containing articles, gallery, static pages, ect, it would be necessary to define one category as the frontpage.

    Guess the work-around for this, is to use the Links for these "categories", and have only one real category, showing as startpage?

    Regards,
    Bert

  • Kafkaesqui

    Posted 10 years ago #

    Bert: I wouldn't call it a workaround so much as a choice in structuring how and when content is displayed on your blog; but yes, that would be a good way of handling things.

  • Bert
    Member
    Posted 10 years ago #

    Kafkaesqui,

    Nice. So there are two solutions possible: either adding the code you proposed to Lara, or have only one Category as frontpage and use Links for the rest of the navigation menu.

    Am I right to conclude that with the added code, all categories stay in the loop, so remain blogs within the same css, while using the Links would mean the wp-layout is no longer automatically included? ( as links can point to anything, except the WP-code?)

    To simplify my question : how is this site ( http://wordpress.org) structured? It behaves exactly as I want my site to behave: one blog and all other categories sort of static pages, while the whole site is one layout-design.

    Thanks for your help!
    Bert

  • Kafkaesqui

    Posted 10 years ago #

    To make things clear about the site, http://wordpress.org/ is not a blog -- that is, the whole of it is not running on top of WordPress. The links along the top (About, Docs...) are separate sections of the site, and not categories as on a blog.

    http://wordpress.org/development (Dev Blog link) is a blog running WordPress.

    In simplest terms a WordPress blog is a collection of posts under one or more categories. When you visit the home page of a blog, WordPress as designed will display the most recent or newest posts, independent of category. When you click a link to a category page, you're passing the $cat variable (for that category) to WordPress. So by setting the $cat variable for the home page, as done in the PHP code above, we're in effect turning the home page into a category page. Issues of layout and content may likely crop up, but only if they normally do so for category pages on your site.

    To have *static* pages that exist outside the normal flow of blog posts and categories (which it sounds like you may be after), see this page:

    http://www.tamba2.org.uk/wordpress/static/

    Version 1.5 of WordPress will offer this as a built-in feature called Pages. For that, see:

    http://codex.wordpress.org/Pages

  • Bert
    Member
    Posted 10 years ago #

    Thank you Kafkaesqui, that was really helpful!

  • Bert
    Member
    Posted 10 years ago #

    Hi again Kafka and all,

    Meanwhile upgrated to Wp 1.5. When inserting the first piece of code in this thread : ((((( if (is_home()) {
    $cat = "CATEGORYNUM";
    } ))))), -and replacing 'categorynum' with "1"-,

    I get this error :

    Fatal error: Call to undefined function: is_home() in /home/greentoilets/www/www/index.php on line 4

    Any help much appreciated!
    Bert

  • Kafkaesqui

    Posted 10 years ago #

    Bert, ignore that method. I don't know why I suggested it (and I've done so a few times), as it can't work until wp-blog-header.php loads (and then it's too late to set the $cat variable). Instead use the method for 1.2, or better yet use rboren's plugin to take care of things:

    http://wordpress.org/support/6/17139#post-98340

  • Nick Momrik
    Member
    Posted 10 years ago #

    If you are using the default theme or a theme that has pieces to handle things (that is, index.php just handles the home page), you can do it like this....

    Find this line in index.php of the theme
    <?php while (have_posts()) : the_post(); ?>

    Add this line right before it
    <?php $posts = query_posts($query_string . '&cat=5'); ?>
    Change the 5 to whatever the ID # of the category is that you want to display on the front page.

  • Bert
    Member
    Posted 10 years ago #

    Thanks Kafkaesqui and MtDewVirus,

    I added the line MtDewVirus proposed. Perfect!

    Bert

  • paperlion
    Member
    Posted 10 years ago #

    The link is down for the categories plug-in. I found it at this first link. The second may have a newer version, also with some added explanations and uses...

    http://www.coldforged.org/archives/2004/11/15/wordpress-asides-coldforged-style/
    http://flickr.com/groups_topic.gne?id=6421#comment46452

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.