Hi Sammiikins,
I would appreciate it if in the future you could use a tone in your messages that accounts for the fact that I built this plugin on a voluntary basis and that I have no obligation to respond to your particular support request. As you can see in the support threads, I do try my best to respond to all friendly support requests on this forum.
Also, as you can see that this plug has been downloaded almost 30.000 times you can safely assume that it is working correctly so I don’t understand why you are implying that the provided code is no longer working and that I should update the FAQ.
Just to be sure, I did test this code on a development install which is running WordPress 3.4.1 and that uses the Twenty Eleven theme. On line 48 of the functions.php file I have added the provided code and it is working as it is supposed to.
After making sure that you have set the featured image on the Content Block, please provide me with more details about the issue you are experiencing (theme name, plugin version, WP version, debug messages etc.) so I can test why this is not working for you.
Hi Johan,
I apologize if the tone of my message came across as rude; I was more confused than anything. Due to the fact that the thread I referenced was never resolved, and I am having the exact same issue as the others in that thread, all signs seemed to point to the Featured Image issue never being fixed. (Which would have been very frustrating to find out after the fact … I apologize for assuming that was the case!) I’m glad to hear the issue is with my code after all and not with the plugin, since hopefully that means it can be fixed. I really appreciate any help you can offer.
I am working with a custom theme on my localhost. Plugin version 1.9.5. WordPress version 3.4.1. I have created a post of the Content Block type and attached a Featured Image to it. I have added a “Content Block” widget to my sidebar and selected the Content Block that I created. The title and body copy of that post show up correctly in my sidebar, but even after adding the above code to my functions.php there is no image. I tried checking/unchecking the “Show Post Title” and the “Do not apply content filters” options, just in case. Here is the code that is being output from the widget:
<li class="widget widget_custom_post_widget" id="custom_post_widget-3">
<h2 class="widgettitle">Sidebar – About</h2>
Lorem ipsum dolor.</li>
In my template file, I am calling the sidebar with:
<?php dynamic_sidebar('Sidebar'); ?>
In my code from functions.php, if I insert an echo after this line:
if (current_theme_supports('post-thumbnails')) {
The echo is output at the beginning of the_content on all of my regular blog posts and my custom post types, but not anywhere in the sidebar. If I insert another echo after this line:
if ('content_block' == get_post_type()) {
It isn’t output anywhere.
Some of the other plugins that I’m using are:
- Advanced Custom Fields
- Advanced Excerpt (I just tried deactivating it but it made no difference.)
- Custom Post Type UI
- WYSIWYG Widgets
I can’t think of anything else that could be relevant; I hope that is helpful. Thanks so much!
Hi Sammiikins,
If you are not already using featured images in your regular posts, it might be that your theme does not support them yet.
In that case you will have to add the following code before the code from the FAQ: add_theme_support( 'post-thumbnails' );
Hi Johan,
I am actually extensively using Featured Images already in my posts without issue. I’m quite familiar with how they work … my code in the first post does show that I am already using the add_theme_support function.
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 583, 999, false );
add_image_size( 'dbl-col-img', 264, 999, false );
add_image_size( 'img-slider', 583, 350, true );
Also I am assuming that if Featured Images weren’t activated for the Content Block post type, I don’t think the Featured Image metabox would even be available on those posts would they?
I see, in that case you could try switching to the Twenty Eleven theme to rule out any theme issues.
Hi Johan,
I just tested it with the Twenty Eleven theme and it has the same behaviour. Here is the code output by the sidebar:
<div role="complementary" class="widget-area" id="secondary">
<aside class="widget widget_custom_post_widget" id="custom_post_widget-4">
<h3 class="widget-title">Sidebar – About</h3>
<p>Lorem ipsum dolor sit amet.</p>
</aside>
</div>
And for reference, the code I pasted into functions.php; tried it at both the very top and the very bottom.
function InsertFeaturedImage($content) {
global $post;
$original_content = $content;
if (current_theme_supports('post-thumbnails')) {
if ('content_block' == get_post_type()) {
$content = the_post_thumbnail('medium');
$content .= $original_content;
}
}
return $content;
}
add_filter('the_content', 'InsertFeaturedImage');
I also just tried deactivating ALL other plugins to no effect. 🙁
Since this issue does not seem related to your theme, I’m going to re-check my plugin code to see if there is anything I have missed.
Thanks for your help. It’s too bad you aren’t able to replicate it. Seems from my testing that this part of the code is not firing:
if ('content_block' == get_post_type()) {
$content = the_post_thumbnail('medium');
$content .= $original_content;
}
When I insert an echo in there it isn’t output anywhere.
I have rewritten the plugin code and now the featured image is not being added via a filter. This is a much more robust method which also allows you to specify on which widgets you would like to show the featured image.
You can download the new version here:
http://downloads.wordpress.org/plugin/custom-post-widget.1.9.7.zip
Note that you will have to remove the code from the FAQ that you added to the functions.php and select the checkbox ‘Show Featured Image’ on the widget settings.
Johan you are an absolute star!! It works perfectly. Thanks so much for all your hard work. 🙂
I’m glad this works for you. After some further testing I shall release this new version after the next WordPress update is released.
Please let me know if you find any other issues or if you have suggestions for further improving my plugin. (For example, I’m currently looking at a way to get rid of the ‘Do not apply filters’ checkbox as I think it can confuse novice users).
Hey Johan, Thank you so much for this great plugin.
And this new version 1.9.7 fixed my issue to display the featured image.
Just to help : The version in the WP plugin download page is still the old 1.9.5 version.
Should you put the last version 1.9.7 ??
Hi migswd,
I am glad this new version works well for you; unfortunately I have not had time to test the new release thoroughly so I cannot release it yet.
I’ll try to work on this during the coming Christmas holiday, but for now paid client work is given priority 😉
P.s. I would really appreciate it if you could rate my plugin!
hi sir ,
i am using KUBRIC theme…and modified it for my web site…
i created a category and added a post with an featured image …now i want to show this featured image with the post article in my side bar…i used many pluging but its only able to display the content…not the image..plzz help…i used plugin..post in side bar