Forums

[resolved] new post widget for theme (3 posts)

  1. ciuncky
    Member
    Posted 2 months ago #

    Hello,

    I have a theme that in the footer has the most commented widget. The code looks like that:

    <li class="widget">
    <h3><?php _e('Most Commented'); ?></h3>

      <?php get_hottopics(); ?>

    Now, i would like instead of the most commented to appear the latests posts. how should i change the code?

    thanks a lot

  2. MichaelH
    moderator
    Posted 2 months ago #

    Either use a Recent Posts plugin or use code similar to:

    <li class="widget">
    <h3><?php _e('5 recent posts'); ?></h3>
    
    <?php
        $args=array(
          'showposts'=>5,
          'caller_get_posts'=>1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. ciuncky
    Member
    Posted 2 months ago #

    thanks a lot man...that works :)
    the theme wasn't supporting to add different widgets there, so i needed some code :)

Reply

You must log in to post.

About this Topic