• I want to use a “category template” instead of “Archive.php” page.
    When someone clicks on a category (showing in sidebar) of ID=12, then the result page should be shown thru category.php
    On the result page,
    1) all the posts under category=12 should be shown as links (last post’s link on top and oldest post link in last)
    2) the links should be limited to 15 in number, per page. i.e. more than 15-links should not be shown on a single page.

    I have tried the following code, but it returned links of posts from all categories ….

    <?php if (is_category()) { ?>
    <ul>
    <?php $recent = new WP_Query("cat=&showposts=15"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php the_title(); ?>
    </a></li>
    <?php endwhile; ?>
    </ul>
    <?php } else { ?>
    <p>No Result found</p>
    <?php } ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • first: make a file category-12.php

    <ul>
    <?php $recent = new WP_Query($query_string . "&post_per_page=15"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php the_title(); ?>
    </a></li>
    <?php endwhile; ?>
    </ul>
    <?php } else { ?>
    <p>No Result found</p>
    <?php } ?>

    (no need to check ‘if(is_category())’ because you are usign a category template; using ‘$query_string’ should do the rest.)
    to get access to the posts beyond the 15 shown, you may need to add ‘next_posts_link()’ and ‘previous_posts_link()’ to your code.

    Thread Starter syed544

    (@syed544)

    Thanks alchymyth.
    ‘if(is_category())’ is used b’coz I dont want to create 30 category.php files like … category-1.php, category-2.php, category-3.php etc.
    If someone has more than 10 categories then it is cumbersome to make more that 30 category.php files.

    Thread Starter syed544

    (@syed544)

    can anyone help me please?
    how can I use for_each function?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘category template – how to show posts links’ is closed to new replies.