Support » Themes and Templates » Customized display of LATEST 3 POSTS

  • Hello everybody, i was wondering if this is possible, displaying the latest 3 posts within a current STATIC design , more exactly in a <div> structure that looks like this:

    <div class="box1">
    <h3 class="date">01.06.2009</h6>
    <h3 class="title"><a href="#">Post title</a></h3>
    <p>Post text</p>
    </div>
    
    <div class="box2">
    .
    .
    </div>
    
    <div class="box3">
    .
    .
    </div>

    Is this possible? Thanks in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • To be more specific:
    <div class=”box1″> – should display the LAST post
    <div class=”box2″> – should display the second latests post
    <div class=”box3″> – should display the third latest post

    Okay, i managed to simplify things up a bit by reducing this to only one .CSS style, so i just need a code to display the latest 3 posts within a div structure:

    <div class=”box1″>
    <h3 class=”date”>01.06.2009</h6>
    <h3 class=”title”>Post title</h3>
    <p>Post text</p>
    </div>

    I searched up and down the forums, but i only found a way to display latest posts within a styled UL , not withing a <DIV> structure.

    I tried with the following code, but it obviously doesn’t work, i cannot insert the <div> scheme in the printf statement

    <?php
    $how_many=5; //How many posts do you want to show
    require_once('wp-config.php'); // Change this for your path to wp-config.php file ?>
    <ol id="whats-new">
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"%s\">%s</a></li>", get_permalink($np->ID),$np->post_title);
    } ?>
    </ol>

    Progressing with my WordPress experience 🙂 I managed to get it to work in this form:

    <?php
    $how_many=3; //How many posts do you want to show
    require_once('wp-config.php'); // Change this for your path to wp-config.php file ?>
    <?php
    global $post;
    $myposts = get_posts('numberposts=3');
    foreach($myposts as $post) :
    ?>
    
    			 <div class="box1">
    					<h6 class="date"><?php the_time('M d, Y') ?></h6>
    					<h3 class="title"><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
    					<p class="text">a few words</p>
    			 </div>
    
    <?php endforeach; ?>

    However, now i need to have an excerpt , displaying a few words from the posts, and i have no ideea how to do that.
    <?php the_excerpt(); ?>< returns nothing.
    same for the_content()

    Thanks for posting this code.

    As I’ve been sitting here messing with it, and trying to get the content to show up I finally found something that works!

    <?php the_content(); ?>

    That function only works inside of “The Loop.” I’m sure the same goes for the_excerpt()

    After I applied that concept, everything worked. The only problem I had after adding the loop was everything showing up twice. To fix that, just take out the foreach() function, and change the $myposts variable to $post. Voila! Works like a charm.

    <?php $counter = 3;
           $recentPosts = new WP_Query();
           $recentPosts->query('showposts=3');
    ?>
    
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    
    <div class="box<?php echo $counter--; ?>">
    <h3 class="date"><?php the_date(); ?></h6>
    <h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_content(); ?>
    </div>
    <?php endwhile; ?>

    Cheers rainemaida, works a treat, just had to correct
    <h3 class="date"><?php the_date(); ?></h6>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Customized display of LATEST 3 POSTS’ is closed to new replies.