WordPress.org

Ready to get started?Download WordPress

Forums

How to have posts with different categories, display posts on different pages (2 posts)

  1. amarchauhan
    Member
    Posted 2 years ago #

    Hi WordPress people,

    I have created different categories and named them News, Blog, Articles, I have then created 3 Posts and assigned each post to a different category.

    What I want to do is display a single category on a page. This would display a list of all the posts within that category with a title, a bit of the text and a link to take it to a page which will show the full Post.

    Im not sure which template i need to copy and hack,

    Someone please help, google has not been good to me

    Amar

  2. amarchauhan
    Member
    Posted 2 years ago #

    In the code below you'll find 'cat' => 4, change the 4 to the category id. you can ge the category id if you hover over the category and look at the link at the bottom of your URL. I used this code:

    <?php
    /*
    template name: articles
    */
    ?>

    <?php get_header(); ?>

    <div class="container">

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    'cat' => 4,
    'paged' => $paged
    );
    query_posts($args);

    /*<?php query_posts('cat=4'); PAGINATION DOES NOT WORK WITH THIS STANDARD CODE */

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

    <div class="post" id="post-<?php the_ID(); ?>">

    <h2>" title="<?php the_title(); ?>"><?php the_title(); ?></h2>

    <div class="entry">

    <?php content('25'); ?>

    </div><!--end entry-->

    </div><!--end post-->

    <div class="hr"><span class="hide"><hr /></span></div>

    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    </div>

    <?php else : ?>

    <div class="post">
    <h2><?php _e('Not Found'); ?></h2>
    </div>

    <?php endif; ?>

    <div class="clear"></div>

    </div><!--end container-->

    <?php
    include(TEMPLATEPATH . '/sidebar_articles.php');
    ?>

    <div class="clear"></div>

    <?php
    include(TEMPLATEPATH . '/foot_panel.php');
    ?>

    <?php get_footer(); ?>

    Hope this helps anyone with the same issue.

Topic Closed

This topic has been closed to new replies.

About this Topic