ThemeShaper Forums » Thematic


Show excerpts of latest posts on front page

(4 posts)
  • Started 11 years ago by gino
  • Latest reply from gino
  • This topic is resolved


  1. gino

    Hi everybody

    Is there a way to show a limited number of post excerpt (2 for example) from the latest posts of a specific category onto the front page, just before the footer?

    I have other content on the page which I need to keep and that is why I am having problems.



    Posted 11 years ago #
  2. // display 2 recent posts from cat=9 (category 9), see link below for full list of parameters.
    function childtheme_recent_posts_query () {
        if ( is_front_page() ) {
            echo '<div class="recent-posts">';
            $my_query = new WP_Query( array( 'cat=9', 'posts_per_page' => 2 , 'ignore_sticky_posts' => 1) );
                echo '<ul class="featured-posts">';
                    while ($my_query->have_posts()) : $my_query->the_post(); ?>
                            $posttitle = '<h3><a href="';
                            $posttitle .= get_permalink();
                            $posttitle .= '" title="';
                            $posttitle .= the_title_attribute('echo=0');
                            $posttitle .= '" rel="bookmark">';
                            $posttitle .= get_the_title();
                            $posttitle .= "</a></h3>\n";
                            echo $posttitle;
                            if ( has_post_thumbnail() ) { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
                            <?php }
                            else { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute('echo=0'); ?>"><img height="120" width="210" src="<?php bloginfo('stylesheet_directory'); ?>/images/testimage.png" /></a>
                            <?php }
                            echo '<a href="'. get_permalink() . '">' .__('View &raquo;', 'thematic') . '</a>';
                echo '</ul>';
            echo '</div>';
    add_action ('thematic_abovefooter', 'childtheme_recent_posts_query');

    Don't say I never did anything nice for you. Just Kidding. Obviously needs styling and you can heavily modify this however you want, but it should include enough to get you started.

    Posted 11 years ago #
  3. ^works well.

    Posted 11 years ago #
  4. gino

    Hi Scott

    Many thanks for this- I shall remember that!



    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.