[resolved] what code will make only one category of post show on template page (7 posts)

  1. nohl
    Posted 8 years ago #

    Hi all,

    I'm building a couple of template pages.

    I've got a site with a bunch of pages. I want to put posts from one category on one page and posts from another category on a second page.

    I tried this code:

    <?php if (have_posts()) : ?>
    		<?php $cat = get_the_category(); $cat = $cat[6]; ?>
    		'cat'=> $cat->cat_ID,
    		) );
    		<?php while (have_posts()) : the_post(); ?>
    			<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
    			<?php the_title(); ?></a></h2>
    			<span class="post-date" title="Date"><?php the_time('F j, Y') ?></span>
    			<span class="post-cath" title="Category"><?php the_category(', ') ?></span>
    			<span class="post-comm">
    			<?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    			<span class="post-edit"><?php edit_post_link('Edit','',''); ?></span>
    			<span class="entry"><?php the_content('Read the rest...'); ?></span>
    			<?php comments_template(); ?>
    		<?php endwhile; ?>

    But that shows all posts.

    can someone suggest a better way to select only one category?

  2. ZachBroChill
    Posted 8 years ago #

    don't make seperate pages for each category.
    where you want all the links to be, just make a link like this:
    <a href="/?cat=3">page 3</a>

    but replace the number in "cat=3" to something else, like 2 or 3948 or whatever.

  3. whooami
    Posted 8 years ago #

    umm, actually, what the OP ought to be doing is using individual category templates, as is described in the codex.

  4. ZachBroChill
    Posted 8 years ago #

    ohh, you want different templates. i didn't really read your codex that thoroughly. i'm not sure if you can do what you want, unless you uploaded wordpress to different directories.

  5. whooami
    Posted 8 years ago #

    of course you can do that, though reading what he wrote *again* im more confused than the first time.

    I read pages as wordpress pages, for starters.

    nohl, in the future, understand that pages have a distinct meaning when referred to in WP-land. They are those things that are not posts.

    You cannot, in WP-land, put a post on a page.

    Categories are already done the way you describe -- and unless you want to have the categories look different, I dont get what you are trying to do.

  6. SimonJ
    Posted 8 years ago #

    IF you want to use wordpress page

    1- make a page template
    2- upload it in your theme directory
    3- wp-admin -> write page
    4- Write a page with only a title, choose the template you made.
    5- In your template file, use this for the loop :

    <?php query_posts('cat=5&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    ---DO YOUR STUFF (author, title, date, etc...)---
    <?php endwhile; ?>

    NOTE : In this example, we show 5 posts from category 5...



  7. nohl
    Posted 8 years ago #

    SimonJ <= the man (I am of course assuming)

    That did exactly what I wanted.

    Much thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic