WordPress.org

Ready to get started?Download WordPress

Forums

Troubleshoot my Recent Posts From 1 Category (3 posts)

  1. Dgold
    Member
    Posted 9 years ago #

    Help? I had this working, but I messed it up somehow. I was testing other code in this area, maybe I accidently deleted something small that I don't understand. I've searched for the original thread here that taught me how to do this (goal is: to include 3-most-recent posts from 1 category, at the end of my Kubrick sidebar) and I added the part for making the whole excerpt text link to that post's permalink).

    <?php /* If this is the frontpage */if ( is_home() || is_page() ) { ?>
    <li><h2>3 Recent Radio Setlists</h2>
    <ul>
    <?php
    $posts = get_posts('numberposts=3&category=2');
    foreach ($posts as $post) :
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>">
    <?php
    endforeach; ?>
    </ul></li>
    <?php } ?>
    </ul>
    </div>

    That is the last thing in my sidebar. It was displaying 3 posts, now it's only displaying my headline "3 Recent Radio Setlists" and nothing below that. What did I mess up? Some unclosed tag that I don't see? I'm new at this.

    Thank you!

  2. Joshua Sigar
    Member
    Posted 9 years ago #

    <?php /* If this is the frontpage */if ( is_home() || is_page() ) { ?>
    <li><h2>3 Recent Radio Setlists</h2>
    <ul>
    <?php
    $posts = get_posts('numberposts=3&category=2');
    foreach ($posts as $post) :
    setup_postdata($post);
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
    endforeach; ?>
    </ul></li>
    <?php } ?>
    </ul>
    </div>

  3. Dgold
    Member
    Posted 9 years ago #

    Thanks Alpha. You helped me fix it. I see my problem was really an unclosed
    </a>
    and possibly no text for the permalink to attach to.

    Alpha's method offered me the post-title. I actually want the excerpt, so I've changed the important line to:
    <a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a>
    and it works again.

    I have another quasi-related question, I think I'll make a new thread to find out how I can get 3 posts from this-month 1 year ago, and 3 posts from this-month 2 years ago, and so on.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags