• Resolved EntarteteMuzak

    (@entartetemuzak)


    Hi,

    I’m fairly fresh at PHP and would like some help on how to utilize this plugin. First off, when I activate the plugin I see no changes. No secondary thumbnail box.

    Where do I put this text? :

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
        )
    );

    Do I use a php markup tag to enclose it? (e.g. <?php and ?>)

    If I want more than one extra thumbnail (as stated in this post: http://wordpress.org/support/topic/plugin-multiple-post-thumbnails-more-than-2-thumbs?replies=2 ), I guess this is the required code?

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Tertiary Image',
        'id' => 'tertiary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Quaternary Image',
        'id' => 'quaternary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Quinary Image',
        'id' => 'quinary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Senary Image',
        'id' => 'senary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Septenary Image',
        'id' => 'septenary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Octonary Image',
        'id' => 'octonary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Nonary Image',
        'id' => 'nonary-image',
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Denary Image',
        'id' => 'denary-image',
        )
    );

    But what about

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image');
    endif; ?>

    Where do I add the extra thumbnails?
    I tried using (whit no success):

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'tertiary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'tertiary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'quaternary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'quaternary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'quinary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'quinary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'senary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'senary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'septenary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'septenary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'octonary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'octonary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'nonary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'nonary-image');
    && MultiPostThumbnails::has_post_thumbnail('post', 'denary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'denary-image');
    endif; ?>

    But I guess that ; ends the code string, right?

    Please help

    http://wordpress.org/extend/plugins/multiple-post-thumbnails/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Chris Scott

    (@chrisscott)

    @entartetemuzak

    You put the code to call the new MultiPostThumbnails object(s) in your functions.php file. If you don’t have one in your theme, add one and add the code after the opening PHP tag (you can omit the closing PHP tag which is recommended since leaving any whitespace after it will cause errors).

    Your code for creating more thumbnails is correct. Just put it in functions.php.

    For

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image');
    endif; ?>

    that would go in your template where you want to display the thumbnail. To add them all you in a template, I’d go with a loop like this to make it a bit easier:

    <?php if (class_exists('MultiPostThumbnails') {
    	$mpt_images = array(
    		'secondary',
    		'tertiary',
    		'quaternary',
    		'quinary',
    		'senary',
    		'septenary',
    		'octonary',
    		'nonary',
    		'denary',
    	);
    
    	foreach ($mpt_images as $mpt_image) {
    		if (MultiPostThumbnails::has_post_thumbnail('post', "{$mpt_image}-image")) {
    			MultiPostThumbnails::the_post_thumbnail('post', '{$mpt_image}-image');
    		}
    	}
    
    }
    ?>

    That just puts the size prefixes in an array first to loop over them to save typing (and typos…).

    Please, change the code to put in functions.php. When updating the plugin, I got a beautiful “error in line xxx in functions.php” where your code is inserted. Maybe it be better to get a “if function exists”…

    Plugin Author Chris Scott

    (@chrisscott)

    The readme was updated last night in v0.5

    mauricenaef

    (@mauricenaef)

    @chris scott

    Hi, can you please have a look at the loop code, because If I use it there seems to be an error, so It doesn’t display.

    Here is the code I’m useing to loop thru all images.

    <?php if (class_exists('MultiPostThumbnails') {
    	$mpt_images = array(
    		'1',
    		'2',
    		'3',
    		'4'
    	);
    
    	foreach ($mpt_images as $mpt_image) {
    		if (MultiPostThumbnails::has_post_thumbnail('post', "secondary-image-{$mpt_image}", $post->ID)) {
    			MultiPostThumbnails::the_post_thumbnail('post', secondary-image-'{$mpt_image}', $post->ID 'single-thumb','class=wp-post-image', true);
    		}
    	}
    
    }
    ?>

    If I paste them all in separate it works.
    Thanks for your update in advance.

    Regards Marcel

    btw Great Plugin!

    @chris Scott

    I think I’m having the same problem as mauricenaef, which is a blank page because of (a suspected) syntax error. I added another ) to the first line:

    <?php if (class_exists('MultiPostThumbnails')) {

    and the page will then display, but the images aren’t displaying. Going back to:

    <?php if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
    MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL, 'thumbnail'); endif; ?>

    for each works fine, but that gets to be a ton of code. It would be nice to have your posted loop work. Unfortunately, I don’t know enough to fix it.

    It never fails… once you post something you figure it out minutes later. It was a simple syntax thing. The code below works for me:

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

    Sorry about that formatting.

    mauricenaef

    (@mauricenaef)

    Hi Eric

    Any change we can have a look at the code which worked for you? Both links supplied don’t get to any code and there is no code “below”?

    Thanks for your help and best regards Maurice

    Ooops. I wasn’t aware of the rules regarding code. Here you go:

    http://pastebin.com/d4ukik2E

    I think the keys were, the additional ) in line 1 and using ” instead of ‘ around {$mpt_image}-image.

    Hey,

    I started using your plugin today and noticed it doesn’t really support using the thumbnail caption… with the normal thumbnail you just do this:

    Image: <?php the_post_thumbnail(); ?><br>
    Caption: <?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?>

    But I ended up having to do this to get the caption from a secondary featured image (note, I’m using this on pages):

    $second_thumbnail_id = get_post_meta(get_the_ID(), "page_secondary-image_thumbnail_id", false);
    $second_id = $second_thumbnail_id[0];
    
    // The thumbnail caption:
    echo get_post($second_id)->post_excerpt;

    I guess what’s needed really is for you to make get_post_thumbnail_id() return the post id for the thumbnail if you can.

    Btw, love the plugin, made my life easier!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Multiple Post Thumbnails] Newbe questions’ is closed to new replies.