WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sitewide Tags - Thumbnails (5 posts)

  1. Jacob311
    Member
    Posted 11 months ago #

    I am using a theme called SportsMag. Here is a snippet of code from the index page that shows you that it uses both has_post_thumbnail and the_post_thumbnail:

    <?php if( has_post_thumbnail() ) { ?>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('smblock5_block_l'); ?></a>

    I have seen this, read it and the comments thoroughly. (http://wpmututorials.com/plugins/post-thumbnails-for-sitewide-tags/) There's no need to suggest that I go here or here: http://wpmututorials.com/plugins/using-the-sitewide-tags-plugin/
    I have them memorized ;)

    I have a multisite blog with a testing area at dsnamerica.com/test. It is successfully pulling and posting articles from other sites in the network, but like many, it is not displaying the thumbnail.

    A lot of what I've read indicates that I need to add <?php the_post_thumbnail(); ?> to my functions. Well, it is already using that (the code I posted above) so do I still need to add this code somewhere else?

    I do have "Include Post Thumbnails" under the global tags settings checked.

    Also, I tried installing the beta version of SWT from the code I found here:
    I'll be ready to respond all day if anyone (maybe the magician Andrea is online today?) is available to help me through this.

    What information do you need from me to help you know where I've gone wrong?

    Thank you guys

  2. Jacob311
    Member
    Posted 11 months ago #

    I've tried using the instructions here: http://mu.wordpress.org/forums/topic/18095

    I may have done it incorrectly though. First of all, I should've indicated that I've installed this plugin into the mu-plugins directory.

    Second, after I added the code from the link above, I no longer see a plugin settings page like I had before, which makes me think I added the code incorrectly.

    So he said:

    Just before the switch_to_blog() function within the sitewide_tags_post() function, add this:

    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    if( $thumbnail_id ) {
    $meta = get_post_meta( $thumbnail_id, '_wp_attachment_metadata' );
    $source_dir = wp_upload_dir();
    foreach( $meta[0]['sizes'] as $key => $value ) {
    $thumbnails[$key] = $source_dir['baseurl'] . '/' . substr($meta[0]['file'], 0, 8) . $value['file'];
    }
    }

    So I added it here under "//testing area 1"

    if ( $last_blog_id < $c ) {
    				wp_die( "Finished importing posts into tags blogs!" );
    			}
    			//testing area 1
    			$thumbnail_id = get_post_thumbnail_id( $post->ID );
    if( $thumbnail_id ) {
    $meta = get_post_meta( $thumbnail_id, '_wp_attachment_metadata' );
    $source_dir = wp_upload_dir();
    foreach( $meta[0]['sizes'] as $key => $value ) {
    $thumbnails[$key] = $source_dir['baseurl'] . '/' . substr($meta[0]['file'], 0, 8) . $value['file'];
    }
    }
    			switch_to_blog( $c );
    			while ( !$finished ) {
    				if ( $wpdb->blogid == $tags_blog_id ) { // not the tags blog

    Then he says:
    And at the end of the if() statement just before the restore_current_blog() function in that same function add this:

    if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    add_post_meta( $p, $key, $value );
    }
    }

    So I added that code here under "//testing area 2"

    switch_to_blog( $c );
    			while ( !$finished ) {
    				if ( $wpdb->blogid == $tags_blog_id ) { // not the tags blog
    					$c++;
    					if ( $last_blog_id < $c ) {
    						wp_die( "Finished importing posts into tags blogs!" );
    					}
    					//testing area 2
    					if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    add_post_meta( $p, $key, $value );
    }
    }
    					restore_current_blog();

    And finally, at the end of the if() statement of the //editing an old post portion, add this:

    if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    delete_post_meta( $global_post->ID, $key );
    }
    }

    Again, I added it under "//testing area 3"

    if( $global_post->ID != '' ) {
    			$post->ID = $global_post->ID; // editing an old post
    			//testing area 3
    			if( $thumbnails ) {
    foreach( $thumbnails as $key => $value ) {
    delete_post_meta( $global_post->ID, $key );
    }
    }
    			foreach( array_keys( $global_meta ) as $key )

    I tried to give you a bit of code above and below each area I worked on so you can see if I put it in the right spot. I tried to keep it short, but sometimes you just have to rock the Cmd+C / Cmd+V am I right?

    Thanks all

  3. David Sader
    Member
    Posted 11 months ago #

    Does the template you have show it's thumbnails in its original blog? Get the thumbs showing in their initial context in any thumb enabled theme first off. I wager that will be most of the battle.

    Do not "Rock the Cmd+C / Cmd+V", lol. You do not edit the Mu Sitewide Tags Pages plugin AFAIK. Only template files need a tinker to enable thumbs. You are pasting 2-3 year old code "fixes" into a plugin that as far as I can tell is up to date and supports thumbnails fine. (You have found the checkbox).

    I have made no tinkers to the Mu Sitewide Tags Pages plugin and I see thumbnails in my thumbnail enabled theme - in both the tags blog and the originating blog. Theme and Plugin are "out of the box" as they say.

  4. Jacob311
    Member
    Posted 11 months ago #

    Thank you David. I have my testing area set up here: http://dsnamerica.com/test/.

    The thumbnails that are showing are from the context of the main/original site. The thumbnail areas that have a gray box are those being pulled from other subsites like dsnamerica.com/test/minnesota for example. The content of the articles (text) pulls through. I'm just struggling with the thumbnails.

    I'll remove my Cmd+C/Cmd+V techniques and look closer at the theme's code. With this in mind, that my original site's thumbnails work, do you have any other suggestions I could try?

    I'll try what I know and post back here again if it doesn't work.

    I appreciate the help.

  5. Jacob311
    Member
    Posted 11 months ago #

    Got her running. The problem was that my theme's code was using:

    <?php
    
    if ( has_post_thumbnail() ) {
    	the_post_thumbnail();
    }
    else {
    	//some code
    }
    ?>

    The WordPress Codex warns that "The above code apparently fails in some instances and the below code is "recommended'":

    <?php 
    
    if ( '' != get_the_post_thumbnail() ) {
        // some code
    } else {
        // some code
    }
    
    ?>

    Turns out if you do as your told, things work better... I am now using get_the_post_thumbnail() rather than has_post_thumbnail() and everything is running like it should.

    Thank you for your help. Sometimes these forums are helpful to write out your thoughts even if you don't get the answer you needed from someone else. Piece of advice to all up-and-coming WP gurus: read the codex. Print it off, put in your bathroom, and commit your bathroom trips the good solid (*ha!) reading of the codex.

    Cheers David. This is resolved!

Reply

You must log in to post.

About this Topic