Title: Recent Posts Script
Last modified: August 19, 2016

---

# Recent Posts Script

 *  [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * (@daenterpri)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-script/)
 * Hello!
 * Does anyone know how I can get the following recent posts code to work for 3.0
   MU? My sub-domain sites will NOT have their own blogs, but I would like all of
   them to display recent posts from the root domain:
 *     ```
       <ul>
                           <?php
                             $number_recents_posts = 6;//Can be how much you want
                             $recent_posts = wp_get_recent_posts( $number_recents_posts );
                             foreach($recent_posts as $post){
                               echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a><br /><div class="newsdate">Posted: '.$post["post_date"].'</div></li> ';
                             } ?>
                           </ul>
       ```
   
 * Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [David Sader](https://wordpress.org/support/users/dsader/)
 * (@dsader)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625669)
 *     ```
       <?php
       switch_to_blog(1);
                             $number_recents_posts = 6;//Can be how much you want
                             $recent_posts = wp_get_recent_posts( $number_recents_posts );
                             foreach($recent_posts as $post){
                               echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a><br /><div class="newsdate">Posted: '.$post["post_date"].'</div></li> ';
                             }
       restore_current_blog();
       ?>
       ```
   
 * [http://codex.wordpress.org/WPMU_Functions/switch_to_blog](http://codex.wordpress.org/WPMU_Functions/switch_to_blog)
 *  Thread Starter [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * (@daenterpri)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625833)
 * Thank you so much! That works perfect!
 *  Thread Starter [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * (@daenterpri)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625974)
 * Do you happen to know how I could filter the recent posts by tags?
 *  Thread Starter [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * (@daenterpri)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625976)
 * Does anyone know how I can get the above Recent Posts code to display only posts
   with certain tags?
 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [15 years, 7 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625977)
 * Change
 *     ```
       $number_recents_posts = 6;//Can be how much you want
                             $recent_posts = wp_get_recent_posts( $number_recents_posts );
                             foreach($recent_posts as $post){
                               echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a><br /><div class="newsdate">Posted: '.$post["post_date"].'</div></li> ';
                             }
       ```
   
 * to something from this: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 * Maybe
 *     ```
       <ul>
        <?php
        global $post;
        $myposts = get_posts('numberposts=5&offset=1&category=1');
        foreach($myposts as $post) :
          setup_postdata($post);
        ?>
           <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endforeach; ?>
        </ul>
       ```
   
 *  Thread Starter [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * (@daenterpri)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625978)
 * Thank you! That worked!
 * Here is the format for tags:
 *     ```
       <ul>
        <?php
        global $post;
        $myposts = get_posts('numberposts=5&offset=1&tag=tagslug,tagslug2');
        foreach($myposts as $post) :
          setup_postdata($post);
        ?>
           <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endforeach; ?>
        </ul>
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Recent Posts Script’ is closed to new replies.

## Tags

 * [multisite](https://wordpress.org/support/topic-tag/multisite/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 6 replies
 * 3 participants
 * Last reply from: [daenterpri](https://wordpress.org/support/users/daenterpri/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/recent-posts-script/#post-1625978)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
