ThemeShaper Forums » Thematic


Successful dynamic list of multiple blogs on frontpage of multisite

(1 post)
  • Started 2 years ago by D.Lo
  • This topic is not a support question
  1. D.Lo

    I had been working on a way to dynamically display multiple blogs on the front-page of a multi-site setup but was having some difficulty customizing it to make a true showcase page. After spending time in the forums I came up with a pretty easy way to do it, so I thought I'd share my success in case others might benefit.

    It really required two parts:

    1. WordPress MU Sitewide Tags Pages Plugin
    2. 2 functions in functions.php

      Part 1 is a no-brainer and a great plugin. Anyone who has done any research on pulling together content from multiple blogs in multisite learns quickly that this really shouldn't be done dynamically unless you like watching your server smoke. The idea is that this plugin creates duplicate posts in a catch-all blog that you can then use as your cross-blog base.

      Part 2 ended up being relatively few lines of code, but many hours of trying to figure it out. I'll give you the code first and then walk you through it:

      <?php //Remove post footer from sitewide blog
      function babson_remove_sitewide_postfooter($postfooter) {
      if (get_current_blog_id() != 1) { return $postfooter; };
      <?php //Add link to blog source on sitewide blog homepage
      function babson_add_sitewide_bloglink() {
      if (get_current_blog_id() == 1) {
      $intCurrentBlogId = get_post_meta(get_the_ID(), 'blogid', true);
      $strCurrentBlogName = get_blog_option($intCurrentBlogId, 'blogname');
      $objCurrentBlogDetails = get_blog_details($intCurrentBlogId);

      echo "<h1 class='sitewide_blogtitle'>siteurl."'>".$strCurrentBlogName."</h1>";
      add_action('thematic_abovepost', 'babson_add_sitewide_bloglink');

      There's two functions. The first removes the post footer. This is subjective but I opted to do this because the front page of our multisite is basically supposed to showcase how much diverse content we have. The post footer took up space. But, even more annoying was that every post (even the newest ones) showed "comments closed" which was misleading to the reader. Commenting was actually encouraged and open where the blogs originated, but in practice they needed to be closed on the sitewide blog. Since we are just trying to get people to read and click-through, it just wasn't necessary.

      The second function is my personal success. Basically what it does is add the title and link to the originating blog for every post. In searching multiple forums I saw this to be a common request/challenge to people without a great solution. The big problem is out of the box Wordpress doesn't provide the blog_id associated with an individual post. Why would it? The assumption is that the post is being viewed within a blog and you can get the blog ID that way. BUT, what happens when this post is a copy and the copy is being viewed from the sitewide blog. Problems, buddy. There's a couple different ways to do this, but I opted to try and keep it simple and keep it efficient so as not to significantly harm performance.

      The key that made this happen is that the Sitewide plugin above happens to add the blog ID associated with a post as a custom metadata. So it is actually easy peasy to get. Use a few built-in WordPress functions and you are good to go. But, I'm telling you folks, finding out this information was SO HARD. Or I suck. Either way, I was very happy to see this work and meet my performance goals. Querying 10 posts on a homepage and I hardly saw a blip.

      Hopefully this helps some folks. Or if it catches the eye of some of the experts here and they want to chime in with an alternative or an improved approach I welcome it. I'm a total noob who is two months into my WP experience, but I was pretty proud of taming the Loop on this one.



    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.