Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to list recent 25 blogs in the network with their title. How to edit this code ?

$bcount = get_blog_count();

  global $wpdb;
  $blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
   if(!empty($blogs)){
?><ul class="menu"><?php
foreach($blogs as $blog){
    $details = get_blog_details($blog->blog_id);
    if($details != false){
        $addr = $details->siteurl;
        $name = $details->blogname;
        if(!(($blog->blog_id == 1)&&($show_main != 1))){
            ?>
            <li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
                <a href="<?php echo $addr; ?>"><?php echo $name;?></a>
            </li>
            <?php
        }
    }
}
?></ul><?php
}
share|improve this question
    
If you're stealing someone else code, at least be so kind to give proper credit. You're not an author of the code in your question. It comes from this answer to this question. –  trejder Nov 9 '12 at 21:15

1 Answer 1

You just have to modify your query to get only first 25 matches SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1' limit 25.

The result is already order by id what is incremented automatically, you don't have anything to bother about there.

Also please note, it is not a good practice to do such queries on every request, you should cache them.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.