WordPress.org

Forums

page template show posts (3 posts)

  1. razzera
    Member
    Posted 2 years ago #

    Hey
    i have this little bit of code that get's all my current posts and display them on a page. I was wondering how i insteed of showing all posts in total show all post from a certain category. Anyone that can help me please?

    <?php
    /*
    Template Name: All posts
    */
    ?>
    <?php
    $debut = 0; //The first article to be displayed
    ?>
    <?php while(have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <ul>
    <?php
    $myposts = get_posts('numberposts=-1&offset=$debut');
    foreach($myposts as $post) :
    ?>
    <li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <?php endwhile; ?>
  2. jamesg40
    Member
    Posted 2 years ago #

  3. Vichet Sen
    Member
    Posted 2 years ago #

    To do show posts from a specific category, you need to modify your while loop and WordPress has WP_Query to help you do like that.

    Here is the link: http://codex.wordpress.org/Class_Reference/WP_Query

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.