Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am wondering how to add a column to my homepage that shows the five most recent posts from the blog page located under the "Latest News" heading.

Here is the link to my development site.

http://pur-vent.29kdev.com/

and below is the code that I believe I must edit to achieve this.

If anyone could offer any advice I would greatly appreciate it.

Thanks in advance.

  • Mike

“”

<?php if ( get_option('modest_featured') == 'on' ) get_template_part('includes/featured'); ?>

<?php if ( get_option('modest_blog_style') == 'false' ){ ?>
    <div id="blurbs" class="clearfix">
        <?php 
            $blurbs_number = get_option('modest_use_third_page') == 'on' ? 3 : 2;
            if ( get_option('modest_use_third_page') == 'on' ) $blurbs_number = 3; 
        ?>
        <?php for ($i=1; $i <= $blurbs_number; $i++) { ?>
            <?php query_posts('page_id=' . get_pageId(html_entity_decode(get_option('modest_home_page_'.$i)))); while (have_posts()) : the_post(); ?>
                <?php 
                    global $more; $more = 0;
                ?>
                <div class="blurb<?php if ( $i == 3 ) echo ' last'; ?>">
                    <h3 class="title"><?php the_title(); ?></h3>                        
                    <?php the_excerpt(''); ?>



                </div> <!-- end .blurb -->
            <?php endwhile; wp_reset_query(); ?>
        <?php } ?>

        <?php if ( $blurbs_number == 2 ) { ?>
            <div class="blurb last">
                <h3 class="title"><?php esc_html_e('Examples of Our Work','Modest'); ?></h3>
                <?php query_posts("showposts=".get_option('modest_work_number')."&cat=".get_cat_ID(get_option('modest_work_cat')));
                    if (have_posts()) : while (have_posts()) : the_post(); ?>
                        <?php 
                        $width = 56;
                        $height = 56;
                        $titletext = get_the_title();

                        $thumbnail = get_thumbnail($width,$height,'item-image',$titletext,$titletext,true,'Work');
                        $thumb = $thumbnail["thumb"];
                        $fancybox_title = get_post_meta($post->ID,'Customtitle',true) ? get_post_meta($post->ID,'Customtitle',true) : get_the_title(); ?>
                        <div class="thumb">
                            <a rel="gallery" title="<?php echo esc_attr($fancybox_title); ?>" href="<?php echo esc_attr($thumbnail['fullpath']); ?>" class="fancybox">
                                <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'item-image'); ?>
                                <span class="overlay"></span>
                                <span class="zoom-icon"></span>
                            </a>
                        </div>  <!-- end .thumb -->
                    <?php 
                    endwhile; endif; 
                wp_reset_query(); ?>
            </div> <!-- end .blurb -->
        <?php } ?>
    </div> <!-- end #blurbs -->
<?php } else { ?>
    <div id="left-area">
        <?php get_template_part('includes/entry','home'); ?>
    </div>  <!-- end #left-area -->
    <?php get_sidebar(); ?>
<?php } ?>

share|improve this question

1 Answer 1

Try the following using WP_Query:

<div class="news-column">
    <h3>Latest News</h3>
    <ul>
        <?php
        //get news
        $args->posts_per_page = 5;

        //query
        $query = new WP_Query($args);
        while($query->have_posts()):$query->the_post();
            ?>
            <li class="news-item">
                <h4><?php the_title(); ?></h4>
                <p><?php the_date('F jS, Y'); ?></p>
                <?php the_excerpt(); ?>
                <p class="footnotes"><a href="<?php the_permalink(); ?>">Continue reading</a></p>
            </li>
            <?php
        endwhile;
        wp_reset_postdata();
        ?>
    </ul>
</div>

You can read more about other params to use here: codex.wordpress.org/Class_Reference/WP_Query

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.