Forums

how to get latest post in a page (7 posts)

  1. jeevaa81
    Member
    Posted 1 year ago #

    I am creating a news website using wordpress, i want to create a front page that should display latest 2 post from each category , how can i create that?

  2. MAS
    Member
    Posted 1 year ago #

    <?php
     $categories = get_categories();
     foreach($categories as $cat):
       query_posts("cat=".$cat->term_id."&showposts=2");
       while(have_posts()): the_post();
        echo "<h2><a href='".the_permalink()."' rel='Bookmark of {the_title()}'>". the_title()."</a></h2>";
        echo '<p class="'.post_class().'">'.the_content("Read more...").'</p>';
       endwhile;
     endforeach;
    
    ?>

    Write this code in your front page file.

  3. jeevaa81
    Member
    Posted 1 year ago #

    i set a static page as front page , can i write this code in html tag

  4. MAS
    Member
    Posted 1 year ago #

    first include the wp_blog_header.php file in your front page file. file should be .php file not .html file.

  5. jeevaa81
    Member
    Posted 1 year ago #

    if i use a wordpress page as home page , whre i have to write above code then where i have to save ? or can i create an external file for this?

  6. jeevaa81
    Member
    Posted 1 year ago #

    i want to publish 2 latest post from each category in front page. i am new to wordpress and php , please guide me

  7. keesiemeijer
    moderator
    Posted 1 year ago #

    Put this code in the page template file you are using for your static front page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags