ThemeShaper Forums » Thematic

[closed]

Show excerpts of latest posts on front page

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

Tags:

  1. gino
    Member

    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.

    Thanks!

    Gino

    Posted 2 years ago #
  2. // display 2 recent posts from cat=9 (category 9), see link below for full list of parameters.
    // http://codex.wordpress.org/Class_Reference/WP_Query
    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(); ?>
                        <li>
                        <?php
                            $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 }
    
                            the_excerpt();
    
                            echo '<a href="'. get_permalink() . '">' .__('View &raquo;', 'thematic') . '</a>';
                            ?>
                        </li>
                    <?php
                    endwhile;
                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 2 years ago #
  3. ^works well.

    Posted 2 years ago #
  4. gino
    Member

    Hi Scott

    Many thanks for this- I shall remember that!

    Regards,

    Gino

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.