WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get only the latest post from all my network site (3 posts)

  1. sugarFornaciari
    Member
    Posted 2 years ago #

    Hi Guys,
    I am here to ask some help in order to succeed in this development.

    I am trying to get only the most recent article from all the articles I have on the netword. I wish use code. No plugin and at the moment what I have done it is publish the latest post from each blog.

    In other word I need help just to select and publish the article most recent from a list of recent articles.

    Here the code

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. sugarFornaciari
    Member
    Posted 2 years ago #

    Inside the function there is comment:
    // here I have the recent post for each blog

    This is the place where it is possible get the recent post from each blog.
    So My idea is that I could store this data and order by most recent data.

    Could anyone help?
    Cheers

  3. sugarFornaciari
    Member
    Posted 2 years ago #

    Hi Guys I have solved...
    Ok having the list of recent articles of all the network that you may build yourself by reading here
    http://wordpress.org/support/topic/how-to-create-a-list-of-all-multi-sites-or-blogs-within-one-site

    and here
    http://codex.wordpress.org/Template_Tags/get_posts

    you can put every thing in an array and after that sorting dates with this function that give the most recent date

    $mostRecent= 0;
    	$date_c =0;
    	$post_c =0;
    	foreach($post_date_ar as $date){
    	  $curDate = strtotime($date);
    	  if ($curDate > $mostRecent) {
    		 $mostRecent = $curDate;
    			$post_c = $c;
    	  }
    	  $c++;
    	}

    and after that, i will use this info to get the item from the list of post

    $recent_post_c = 0;
    	foreach($recent_post_ar as $post) : setup_postdata($post);
    		if($recent_post_c==$post_c){
    	?>		
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    
    		</div>
    		<hr />
    
    	<?php
    		}
    	$recent_post_c++;
    	endforeach;

    The code is not very elegant but it works...
    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic