• yangt299

    (@yangt299)


    Hi,

    What I’m asking for is pretty simple. I need to read out the titles of all the posts in a certain category with PHP, and put that onto a page. I’m sure this is possible, somehow, using the index.php template, but I’m not sure exactly how to do it. Could anyone help me?

    Thanks!!

Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi

    (@esmi)

    What you’re describing is a category list – controlled by your theme’s category.php template file. If your theme doesn’t have a category.php file, then it will be using archive.php or index.php (in that order).

    Thread Starter yangt299

    (@yangt299)

    I don’t have a category.php or archive.php, I am using the iBlog2 theme, my blog is http://itracki.com. Please help!!

    Thread Starter yangt299

    (@yangt299)

    anyone?

    MichaelH

    (@michaelh)

    Then copy that theme’s index.php to category.php and delete the code you don’t want to display–for instance you would delete this so the post content would not display:
    <?php the_content(__('Continue reading &raquo;',TDOMAIN)); ?>

    Also review:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    Thread Starter yangt299

    (@yangt299)

    Thanks for the quick reply, MichaelH.

    So what you’re saying is that I have to create a template called category.php?

    Maybe I didn’t make myself clear, but what I actually wanted is to have the post titles of all the posts in a category to be displayed ON A PAGE THAT I CREATED using WordPress. How is this done?

    Thanks, please reply!

    MichaelH

    (@michaelh)

    Put this in your Page Template

    <?php
    $cat_id = 3; //change to your category ID
    $args=array(
      'cat' => $cat_id,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter yangt299

    (@yangt299)

    MichaelH, I tested your solution and it works, but the problem is that you have to put the code in the Page Template (page.php). What I need is to put it into a page. For example, I created a page called “List of posts in category uncategorized.” I then need to put code in my post that would read out all the posts in this category, and put them into the page. I am not doing anything whatsoever with the template.

    Could you please help?

    Thanks!!

    MichaelH

    (@michaelh)

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Read Categories’ is closed to new replies.