WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Custom Post Widget] featured image support

[Plugin: Custom Post Widget] featured image support

  • I have Custom Post Widget installed an working OK under WP 3.2. I have one Content Block in a sidebar widget. The title and content are output OK.

    The Custom post has a featured image loaded and I want it to show in the display.

    I have these present in functions.php

    add_theme_support( 'post-thumbnails' );
    
    function InsertFeaturedImage($content) {...}

    However this is not displaying the image.
    This is in a custom theme.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I did a bit more work – it seems like this line is not being triggered:

    if ('content_block' == get_post_type()) {

    Printing the $post array shows it is holding the main page and not the custom post. ie: [post_type] => page.

    Is my theme behaving incorrectly or am I missing something?

    Thanks

    Hi mjpg, did you use the code that is on the FAQ page: http://wordpress.org/extend/plugins/custom-post-widget/faq/

    Johan

    Yes – although I got it from the readme.txt file.

    I’m assuming it’s perhaps an issue with the loop – the function seems to be getting the $posts object from the previous widget.

    Thanks for replying.

    Martin

    Hi Martin,

    I have been trying to fix this but hit a brick wall..

    The issue is most likely caused by the fact that in version 1.6 of the plugin I switched from using query_post to get_post. Before this change the post thumbnails were working.

    The fix would be either switching back to using query_post (which I was told causes performance issues), or getting the thumbnail in the get_post by using setup_postdata($post);.

    Unfortunately I did not manage to get this to work. Hopefully someone else reading this will find the solution.

    Johan

    Many thanks for all your efforts.

    I’m still using your great plugin for other things, but for this one-off (a promo block on the home page) I created a custom post type called homepromo and wrote a short include to call it. An additional complication that may have caused another issue with your function is that I needed the image in the CSS background.

    This is the content of my include file in case it is of use to anyone else – themename-homepromo.php:

    <?php if( is_front_page() ) {  ?>
    
    	<?php
    	$args = array( 'post_type' => 'homepromo' , 'posts_per_page' => 1  );
    	$homepromoloop = new WP_Query( $args );
    	?>
    
    	<?php if ( $homepromoloop->have_posts() ) { ?>
    
    		<?php while ( $homepromoloop ->have_posts() ) : $homepromoloop ->the_post(); ?>
    
    			<?php
    			$featured_image_id = get_post_thumbnail_id( $post->ID );
    			$imgArray = wp_get_attachment_image_src($featured_image_id,'home_promo');
    			$imgsrc = $imgArray[0];
    			?>		
    
    			<div id="promo" style="background-image:url(<?php echo($imgsrc); ?>);">
    <div id="promotext">
    					<div id="promotextwrapper">
    						<?php // the_title() NOT USED; ?>
    						<?php the_content(); ?>
    					</div><!-- #promotextwrapper -->
    				</div><!-- #promotext -->
    			</div><!-- #promo -->
    
    		<?php endwhile; ?>
    
    	<?php } else echo(''); ?>
    
    <?php } // end is front page ?>

    I called it into the index.php with:

    <?php get_template_part( "themename", "homepromo" ) ?>

    Martin

    Hi there, I have the same issue, and have had to resort to inserting an image within the body which may become a little untidy.

    Are there any updates on this?

    Apart from that I think it’s a great little plugin. Thanks for spending your time to create and share it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Custom Post Widget] featured image support’ is closed to new replies.