WordPress.org

Ready to get started?Download WordPress

Forums

Output List Of Posts From Category On A Page? (5 posts)

  1. wp3678
    Member
    Posted 6 years ago #

    I have a WordPress page and I would like to output a list of posts on this page when it is displayed.

    Is there some kind of [listposts display="title", category="test", orderfld="pubdate", order="desc"] command (I have just made this up) I can use within the editor of the page?

    The title should be a hyperlink to the actual post.

    Thanks

  2. cheese apples
    Member
    Posted 6 years ago #

    You could make a page template, add the code needed to it, then create a new page leaving it blank and assign the template to that page under page template.

    Make a file called whatever_template.php and put it in your theme directory. In the top of the file put:

    <?php /*
    Template Name: whatever_template
    */ ?>

    In the rest of the file you can copy the contents from your page.php, then just alter the loop so it shows whatever category you want, something like this:

    <?php if (have_posts()) : ?>
    <h2>YOUR_CATEGORY</h2>
    <?php $temp_query = $wp_query; ?>
    <?php query_posts('category_name=YOUR_CATEGORY&showposts=109'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <ul><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li></ul>
    <?php endwhile; ?>
    <?php else : ?>
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
  3. wp3678
    Member
    Posted 6 years ago #

    I have inserted the below code in my existing page.php just after the <?php the content.....> line. I am using the Default theme (WordPress v2.5.1)

    This half works as a list of the posts from the category are output but then the full text of the first post in the list is output and then a full list of the posts from the category again repeated until the browser hangs/slows and you need to press the stop button.

    Can anyone help further and tell me how to fix the problem?

    Thanks

    <?php query_posts('category_name=mycatname&showposts=109'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <ul><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li></ul>
    <?php endwhile; ?>
  4. wp3678
    Member
    Posted 6 years ago #

    Got this virtually sorted now.

    Does anyone know how to limit the execution of some code to a specific page? e.g. if pageid=1 then dothis1 elseif pageid=2 then dothis2 else dothis3.

    The original code snippet by jbrndt is missing the following line at the end.

    <?php $wp_query = $temp_query; ?>

    Thanks

  5. wp3678
    Member
    Posted 6 years ago #

    Answering my own question again but the following URL has an example on how to detect page http://wordpress.org/support/topic/125439?replies=9

Topic Closed

This topic has been closed to new replies.

About this Topic