WordPress.org

Ready to get started?Download WordPress

Forums

A unique request (10 posts)

  1. peiqinglong
    Member
    Posted 7 years ago #

    I'm not sure if this is even possible, but here goes:

    I would like to have in the sidebar, have 1 post, the most current post from a single category. For example, I want to create an Announcement in the sidebar, and any time a post is made to the Announcement category, that post will show up and replace the previous Announcement post in the sidebar. I have an idea it would using the call up specific category code, but I'm not sure how to make it display only 1 post. Thanks for any and all help!

  2. moshu
    Member
    Posted 7 years ago #

    You can use a "recent posts" plugin and set it to show 1 post from a certain category
    http://codex.wordpress.org/Plugins
    You can use a "mini" Loop with the same settings:
    http://codex.wordpress.org/The_Loop

    Probably there are other ideas, too, search here and/or the Codex.

  3. RadoVleugel
    Member
    Posted 7 years ago #

    This plugin is also able to suit your need: http://guff.szub.net/2005/01/27/get-a-post/

    Use the following code:
    <?php if(is_category ('GETPOST') : ?> //GETPOST will show the most recent post
    <?php get_a_post(10); ?>
    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    <?php endif; ?>

  4. moshu
    Member
    Posted 7 years ago #

    Sorry, RV, I don't think that's correct.
    The original poster (OP) stated very clearly it always should be the most recent post of the category not a "fixed" post.

    The code you quoted from Kaf's site is for a category archive (or category template) and it will always display the post with the ID# 10.
    So, your reply is wrong.

  5. RadoVleugel
    Member
    Posted 7 years ago #

    Thanks Moshu,
    You are right. (After 12 hours of work I am a little tired ;-)

    Here is the correction:

    Use the following code:
    <?php if(is_category (1); ?> //Replace '1' with the category ID

    <?php get_a_post('GETPOST'); ?> //GETPOST will show the most recent post

    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    <?php endif; ?>

  6. TonyGeer
    Member
    Posted 7 years ago #

    I think the OP should also look into using query_post if he doesn't want to use a plugin, I've found it to be very powerful.

  7. iand
    Member
    Posted 7 years ago #

    Maybe:
    <?php $posts = get_posts('numberposts=1&category=999'); foreach ($posts as $post) : ?>
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_content(); ?>
    <?php endforeach; ?>

    Amend the contents of the mini-loop to suit.

  8. peiqinglong
    Member
    Posted 7 years ago #

    Thanks all for the replies! I'm going to try each and everyone of them to find the best that suits my needs.

    Moshu is correct, I'm looking for a way to show the most recent post and only that 1 specific post.

    Thanks all!

  9. peiqinglong
    Member
    Posted 7 years ago #

    IanD: your suggestion fit the best of what I was looking for, except, it pulls the body from the wrong post. Here it is in the sidebar:

    http://www.funnymonkeycomics.com/wordpress/

  10. peiqinglong
    Member
    Posted 7 years ago #

    Website is now located at http://www.funnymonkeycomics.com. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.