My Writings. My Thoughts.
// September 8th, 2012 // Comments Off on New Website Look // Blog
We’ve been real busy lately with new websites, but have decided it was time we needed to update the look & feel of our portfolio, and incorporate some new technology we’ve learned. let us know what you think of the new look!
While working on a project, I had an idea I thought would be pretty simple (famous last words right?). I am using wpmu to have several blogs for different departments of a business, and wanted to have a news feed on the main site to display what is happening on the entire network. I wanted the 10 latest posts, no matter where they lived… I searched for it in every way I could think to word it, & came up with alot of people wanting to do the same thing, but no answer that was exactly what I wanted… I found code from Chase Crawford to make an array with the post object data, & tried looping through it & echoing out the data as needed, but if a post used shortcodes such as a gallery does, it just wrote out the shortcode exactly as it is written, & did not process it, so no gallery was shown. That wasn’t good, not what I was going for.
I tinkered with that code & instead of outputting an array with posts, I outputted an array with the blog_id, the timestamp (not really needed, but was part of the query) and the ID & processed with switch_to_blog() and query_posts(), and then processed with a normal loop. Works great! so if anyone is trying to do the same thing, here is the trick to success!
get code from Chase Crawford, edit $posts = get_blog_post( $row->blog_id, $row->ID ); to read $posts = $row;
next use this code to initiate loop
$posts = recent_mu_posts();
$totalposts = count($posts);
for($i=0; $i < $totalposts; $i++) :
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; endif; ?> <?php restore_current_blog(); ?> <div id="post_banner"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Under Post') ) : endif; ?> </div> <?php endfor; ?>
you can use whatever code you wish between if(have_posts and endwhile; endif;, just treat it like any other loop 🙂
It’s been a while since I’ve updated this page, I’ve been building a few sites, & still working full time. I added a new folio item today, & will be adding a few more over the next few weeks.
Oh! & I finished this site for now… Other than updates on my folio & blog.