• Hi

    After some hours of forumreadings, I finally decided to post the question myself, even if I’m certain somebody else already have had this question.

    What I want to do is to create multiple pages each showing a set number of full posts filtered by one or more categories.
    Preferably I’d like to do this via a plugin, but if somebody can provide the code to insert on each page I’ll try that!

    I have found plugsins that actually say that they can filter out page content based on categories, but it seems I need to create the page myself in these cases, and i dont know how to.. (write the code to show so many posts that is)

    Pleas point me in the right direction, or just name a plugin that actually would create the correct code for me 🙂

    Regards Patrick`

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi

    The code to do it without a plugin is not difficult.
    http://codex.wordpress.org/Template_Tags/query_posts

    You add one line before the WP loop in your page.php template
    query_posts('cat=4&showposts=7'); displays 7 posts from cat #4
    or
    query_posts('cat=2,6,17,38&showposts=7');
    displays the 10 most recent posts from categories 2, 6, 17, 38 combined.

    You can combine all your pages in one template like this

    <?php if (is_page('news')) {
      query_posts('cat=4&showposts=7');
    } elseif (is_page('shopping')) {
      query_posts('cat=2,6,17,38&showposts=7');
    }

    *** loop starts here

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

    If you prefer to use a separate template for each page, see
    http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    Thread Starter pahvi

    (@pahvi)

    stvwlf

    Thanks for your reply!

    This is pretty much how far I got when reading around to..
    BUT..
    I’d rather not mess around that much in my team.
    1st It’s one of them customizable teams out there, so no php-file look as it “should”
    2nd It’s a commercial team, with automatic upgrades etc, so if I mess with it I’ll loos my own customization every time there’s an upgrade.

    I guess I’m looking for a more simple solution..

    With the plugin “Category Page” it seems that I can select valid categories for each page, but that one also requires me to change stuff in the theme, and I just don’t want that 🙂

    /patrick

    I dont know what youre talking about when youre using the term “team” but YOU have to create the page. Nothing is going to magically create any pages for you.

    You mean theme, apparantly.

    Thread Starter pahvi

    (@pahvi)

    Sorry about the misspelling.
    Obviously I mean theme…

    Regarding creating the pages – I guess you’re right, and I overestimated the plugin-functionality a bit.
    I have seen plugins generating pages of all sorts for me, so I thouthg that it would be possible to have code (rather than themes) generating blog-pages as well..

    I have now sent the question for theme-modification to my theme-supplier instead, and hope they can/will provide the features I want at a reasonable cost.

    Thanks!

    /patrick

    There’s a better solution: child-themes.

    This way, you can create your custom page and it will be stored in it’s own folder. So, when you update your theme your modifications will remain untouched.

    Search for “child themes” and you you’ll see how easy they are.

    Ugh! I’m sorry, I’m not a programmer and don’t want to delve into themes, templates, etc. However, this is the best solution I have seen so far – thank you.

    I have the plug-in “Front Page Excluded Categories” which keeps the unwanted posts off of the main blog page. New Posts are assigned to unique Categories and I can get to those Categories via the built in WordPress URL http://www.site.com/?cat=5. But, how can I make a “Page” link to a Category Page? I see that I can edit a Page and give it a title and text, but how do I make a page a URL? When someone click the Page tab/link, how do I keep them from going to http://www.site.com/?page_id=15 and instead send them to http://www.site.com/?cat=6?

    I want to give featured writers their own pages and each writer will get a unique Category when they blog on my site. And no, I do not want to do this with Links.

    I hope this makes sense. I just really wish someone had a plug-in for this. Is the concept that insanely foreign? People have been asking for this for years.

    The “Category Page” plug-in requires template editing. It does have the “[catlist]” entry, but that just gives the headers of the posts in that category in a list, not the actually posts themselves. That plug-in author really needed a “[catposts]” option which could go in the text of a page. Then I would be done.

    Thanks,
    Brad

    Okay, it is very simple. Go to your /wp-content/themes/[theme] directory and copy page.php to page.php.old and then edit your page.php to look similar to the following:

    <?php get_header(); ?>
    <?php sy_pre_content(); ?>
    <div id="content">
    
    //This is the important part here
    <?php
    //Put Category 3 items on page 19 (My second page of blog posts)
     if(is_page('19')){query_posts("cat=3");}
    //Remove Category 3 items from page 8 (My Home Page)
     elseif(is_page('8')){query_posts("cat=-3");}
    ?>
    //That is all there is to it and it can be done for multiple pages
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
            <div class="entry">
            <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>

    And they can’t make this functionality part of the product! Argh!!!

    The “Exclude” was not working for me until I activated and then deactivated the “Frontpage Exclude Categories” plug-in. Not sure, maybe a fatfinger thing there.

    Thanks,
    Brad

    Actually, I cannot get the EXCLUDE statement to work:

    elseif(is_page('8')){query_posts("cat=-3");}

    I’ve had to use the plugin ‘Frontpage Exclude Categories’.

    Anyhow, all is good, just not perfect.

    Found an even more elegant solution to excluding items from the front page at http://blogmum.com/2009/04/how-to-exclude-categories-from-the-home-page-of-your-wordpress-blog/

    Firstly, you need to find the number of the category you want to exclude:

    * go into Posts > Categories
    * click on the relevent category name
    * the URL of the next page should end &cat_ID=xx, where xx is a number. Make a note of it.

    Next, go into Appearance > Editor, and open functions.php. Add the following function at the very end of the file just before ?>:

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

    where xx is the number of your category. Don’t forget the minus sign in front of it! Save it, and you’re done. You can exclude multiple categories with ‘-xx,-yy,-zz…’

    Cheers,
    Brad

    Jeez,

    Doesn’t work for $query->is_page(‘x’) instead of $query->is_home. Can somebody PLEASE add the multiple page functionality or make a decent plugin based on Category Page which doesn’t require any external editing?

    Thanks,
    Brad

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Creating multiple category-based blog pages’ is closed to new replies.