WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display One Post from a Category in a Page (2 posts)

  1. goxu
    Member
    Posted 7 years ago #

    Hi,

    I did search and found lots of similar questions but couldn't find exactly what I'm looking for.

    What I'd like to do is to show only one latest post from a particular category "in a page". I mean, I have several pages corresponding to categories and I'd like to display one post with the excerpt from a choosen category in the page.

    There are bunch of plugins for archive listing but most of times those listed entires got original styles applied and hard to edit them. Some strip html tags and do not get displayed properly.

    It would be greatly appreciated if this could be done.

  2. goxu
    Member
    Posted 7 years ago #

    I did it!

    I created a new template named posts.php and made it list posts by category, and included the posts.php from the wp-page templage.

    Here is the part of the new template.

    $cat_id = $_GET[cat_id]
    $num_d = $_GET[num_d]
    $param = 'category_name=' . $cat_id . '&showposts=' . $num_d;
    query_posts($param);
    <?php if (have_posts()) : ?>
    // the loop continues...

    When I use the include() from the wp-page, I added the following. I use the permalink by the way.

    <?
    $cat_id = $pagename;
    $num_d ='1';
    require("http://mywebsite.com/wordpress/wp-content/themes/mytheme/posts.php?cat_id=$cat_id&num_d=$num_d");
    ?>

    The only thing I'm not satisfied with it is it's kind of slow.

Topic Closed

This topic has been closed to new replies.

About this Topic