WordPress.org

Ready to get started?Download WordPress

Forums

Recent Posts Script (7 posts)

  1. daenterpri
    Member
    Posted 3 years ago #

    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!

  2. David Sader
    Member
    Posted 3 years ago #

    <?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

  3. daenterpri
    Member
    Posted 3 years ago #

    Thank you so much! That works perfect!

  4. daenterpri
    Member
    Posted 3 years ago #

    Do you happen to know how I could filter the recent posts by tags?

  5. daenterpri
    Member
    Posted 3 years ago #

    Does anyone know how I can get the above Recent Posts code to display only posts with certain tags?

  6. 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

    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>
  7. daenterpri
    Member
    Posted 3 years ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags