Forums

Organize Posts by Category (5 posts)

  1. laurelf
    Member
    Posted 1 year ago #

    I am working with the website http://www.catchachapter.com and this site will have stories of various genres. I am trying to make it so that when I post a "mystery" story, for example, it will be pulled to the mystery page on the website, and not to the front page. I don't want to have to go in and keep adding chapters to the particular page. Is there a way to do this? Is more information on the problem needed?

  2. Posts are already organized by categories anyway :)

    Probably it would be easiest to make one category for your 'front page' posts (like 'featured' or 'news' or whatever), and edit your theme to only show that category on the front page. Then you can link people to catchachapter.com/category/mystery for the category mystery :)

  3. boyevul
    Member
    Posted 1 year ago #

    What are you wanting on the front page? If you want a "page" page instead of the latest page of posts, then set that in your options.

    If you want a regular page of posts but minus category x, then place this in your functions.php file:

    <?php
    function exclude_category($query) {
    if ( $query->is_home ) {
    $query->set('cat', '-xxx, -xxx, -xxx');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    ?>

    Where '-xxx' is, for example, '-12' (12 is the category ID of, say, short mysteries, etc.) If you only want one category excluded from the front page, then only have one -xxx listing.

    As far as posts being organized into categories, Ipstenu already answered that one: WordPress does that by default.

  4. laurelf
    Member
    Posted 1 year ago #

    I'm a little confused as to how I edit my theme to pull only mystery posts to only the mystery page, etc. Do I do that using the code you provided, Boyevul?

    Thank you so much for your help!

  5. boyevul
    Member
    Posted 1 year ago #

    Make a file, and call it "functions.php". Place that code into the file. Save it to your base theme folder.

    Go to your Categories listing, and hover over what categories you want to hide from the main page. In the bottom of the browser you'll see a link with a number. That number is your category ID. Write down the list of category IDs you would like to hide from the main page.

    Edit the code in "functions.php" by replace the "xxx" with the numbers. For example, if you have 5 categories that you want to keep from the front page, IDs 23, 45, 64, 34, 47 then your code would look like this:

    <?php
    function exclude_category($query) {
    if ( $query->is_home ) {
    $query->set('cat', '-23, -45, -64, -34, -47');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    ?>

    That's it.

Topic Closed

This topic has been closed to new replies.

About this Topic