Making BP Social Featured Block use posts from any blog

Well... looks like the forum didn't like my post. How do you post actual code here?

  • JohnR

    Well, anyway, the gist of the post was that I'm making the home page Featured Block fetch posts from any blog, not just the root blog. I do this by using, in the "Insert the post id for your featured post" field, items of the form e.g. 3.7 to mean post 7 of blog 3.

    I decode these in a modified gallery.php, and then use them to fetch data from wp_site_posts, which is maintained by the Post Indexer plugin. I also made it use the Featured Image if there is one.

    I see now I can attach a file - I'm a bit hesitant to right now as it only half works (the article version, not the gallery version). If there's any interest I can try cleaning it up and posting it. Mostly at this point I was hoping to get comments on some obviously better way to do it :wink:

    Thx

    JohnR

  • drmike

    How do you post actual code here?

    bbpress is notorious for eating code, even with the html code plugins available. You can try it if you want. As noted try putting code between backticks. That's the key above the tab key and to the left of the '1' key on most keyboards.

    edit: If there's any length to the code, say over 15 lines or so, pastebin would probably be better. Either that or as an attachments as a *.txt file.

  • JohnR

    Thank Mike - I'm not sure what pastebin is but I'll post a .txt file for the revised gallery.php when I get it polished up a bit. (Right now I'm trying to figure out why it doesn't load if I put it in a child theme...)

    Anyway, the first part of the puzzle was getting the Featured Image from a post in any blog. Here's the function that would need to be put into e.g. functions.php:

    /***
    Get the featured image thumbnail if there is one, otherwise get the first attachment
    ***/
    function dez_get_thumbnail($the_blog_id, $the_post_id, $the_permalink, $open_class = '', $close_class = '') {
      global $wpdb;
      // HACK HACK
      if ($the_blog_id == 1) {
        $the_posts = 'wp_posts';
        $the_postmeta = 'wp_postmeta';
      } else {
        $the_posts = 'wp_' . $the_blog_id . '_posts';
        $the_postmeta = 'wp_' . $the_blog_id . '_postmeta';
      }
      $get_post_thumbnail = $wpdb->get_var("SELECT meta_value FROM $the_postmeta WHERE post_id = '$the_post_id' AND meta_key = '_thumbnail_id' LIMIT 1");
      if ($get_post_thumbnail) {
        $get_post_attachment = $wpdb->get_var("SELECT guid FROM $the_posts WHERE ID = '$get_post_thumbnail' AND post_type = 'attachment' ORDER BY menu_order ASC LIMIT 1");
      } else {
        $get_post_attachment = $wpdb->get_var("SELECT guid FROM $the_posts WHERE post_parent = '$the_post_id' AND post_type = 'attachment' ORDER BY menu_order ASC LIMIT 1");
      }
      if(!$get_post_attachment) {
        $attach_img =  get_bloginfo('template_directory');
        $sImgString =  $open_class . '<a href="' . $the_permalink . '">' . '<img src="' . $attach_img . '/_inc/images/header.jpg' . '" class="full" />' . '</a>' . $close_class;
        echo "$sImgString";
      } else {
        $sImgString =  $open_class . '<a href="' . $the_permalink . '">' . '<img src="' . $get_post_attachment . '" alt="ui" class="full" />' . '</a>' . $close_class;
        echo "$sImgString";
      }
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.