WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] New Page to Display One Category + Main Blog to Exclude This Category - HOW? (5 posts)

  1. Tranny
    Member
    Posted 4 years ago #

    I would like to ask a kind developer to help me out with what I believe is a simple task for experienced coder, but a nightmare for a complete newb.

    I would like to add new category to my popular blog and would like to create a new page which would only display entries from that category. The main blog where all other entries are would then remain unaffected and would display all entries from all other categories, except from this new one.

    To be more specific, I have a busy blog with responsive readers. Some posts have more than 600 comments. I would like to offer a new feature for my readers, something to further enhance their experience on my blog. I was thinking of having a "Video of the Day" section where I would post one cool video per day. The idea would be to again allow readers to post comments so I want it to be a normal post (also for the sake for sitemaps I need it to be regular posts). However I don't want those videos mixed up with the rest of the blog which deals with different subject matter. So the best solution would be to create a new page and have only posts made in this category show up there. But that would also require an edit to main blog as I would need to have all posts from this category excluded.

    Can an experienced coder help and guide me through steps that need to be taken in order to achieve desired effect? Much obliged :)

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    1. Create your new category and make a note of its id. You can find the category id by placing your cursor over the title of the category in Admin/Posts/Categories. In the lower left of your browser window, you'll see a long url that ends with &cat_ID=nn. That 'nn' is the category id.

    2. You'll need to now create a category template specifically for this new category. Find your category.php file in your theme, copy it and name the new file 'category-nn.php' (without the quotes) where 'nn' is the category id you noted in Step 1.

    Congratulations - you now have a listing page for that category and that category only. Now you need to exclude this category from your main listings.

    3. Go back to your original category.php file. You're going to edit it. Make a copy first and call it "category.php.bak" (again without the quotes). Keep it to one side in case everything goes pear-shaped.

    Find the line:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Immediately after, on a new line, add:

    <?php if(is_category('nn')) continue; ?>

    (this time, the single quotes are needed).

    Save the file and try the whole thing out.

    Hope that helps.

  3. Tranny
    Member
    Posted 4 years ago #

    Hey esmi, it doesn't look like there is any category.php file in my theme. Any ideas?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    If you have an archive.php file, copy it and rename it category.php and then proceed from there. If you don't have an archive.php file, use index.php instead.

  5. Tranny
    Member
    Posted 4 years ago #

    Hey esmi,

    the category-nn.php advice was fantastic and helped me achieve great results. The code you have suggested however doesn't work. I found a solution that does though in the meantime. Thanks for the category-nn.php tip though. That's one of the best tips I have gotten on WP yet :)

Topic Closed

This topic has been closed to new replies.

About this Topic