nanodesigns / nanosupport

Create a fully featured Support Center in your WordPress setup without any third party dependency, completely FREE. Get a built-in Knowledgebase too. The plugin is available on WordPress.org repository:
https://wordpress.org/plugins/nanosupport/
GNU General Public License v2.0
50 stars 13 forks source link

missing default image in the search result #53

Closed fang-yu closed 6 years ago

fang-yu commented 6 years ago

I ask the theme developer this question:

All of my knowledge base does not have image, but blog page does have. When I search, it return all the knowledge base post and blog post, how can I set default image for the knowledge base post? Cos currently the result page is ugly.

and they replied with:

Looks like featured image is disabled for this custom post type. Please contact the plugin developers to clarify where you can enable that.

Hope this can be added into the future version.

mayeenulislam commented 6 years ago

Without prior important of using a Featured Image we might not add this feature to the core.

BTW we can solve your problem.

Solution 1: Modifying the Plugins' functionality

The easiest way is using a filter hook: ns_nanodoc_arguments. Just copy and paste the following code into your theme's functions.php to add the "Featured Image" feature into Knowledgebase Docs.

/**
 * Add Featured Image to Knowledgebase Docs.
 * 
 * @param   array $args NanoSupport Knowledgebase CPT arguments.
 * @return  array       Modified arguments.
 * ---------------------------------------------------------------
 */ 
function add_featured_image_to_kb_docs_20171116( $args ) {
    $args['supports'] = array( 'title', 'editor', 'thumbnail' );
    return $args;
}
add_filter( 'ns_nanodoc_arguments', 'add_featured_image_to_kb_docs_20171116' );

Solution 2: Making child theme and modifying template

Regardless of WordPress themes, I'm here saying about a WP Core methodology of Template hierarchy. Suppose your theme's dealing the search result page with search.php. You can make a child theme based on your theme, and simply copy paste the search.php in your theme. Then within The Loop, you can custom design Knowledgebase Docs UI using the get_post_type() like below:

while( have_posts() ) : the_post();
   if( 'nanodoc' === get_post_type() ) :
      // change the display
   else :
     // theme code - default display
   endif; 
endwhile;

The above code can easily vary from the theme to theme and their code organizations.

fang-yu commented 6 years ago

Thanks for your help. I tried the solution 1 and in the kb post editor, I did see the feature image section for me to add the image.

but after I set the image in the kb post, I still could not see the feature image in the search result page.

and I also try the quick feature image plugin to bulk set the all fearture image for the kb post type, it did not work either.

mayeenulislam commented 6 years ago

Now the issue is in the theme. Because it's now displaying using the Template hierarchy, and NanoSupport is not modifying any search result. May be, I repeat may be, the theme is not compatible with custom post types (CPTs), and there are conditions like get_post_type() === 'post'. If so, then the search archive won't display images for CPT. You have to add conditions for CPT like nanodoc - as I mentioned earlier.

You can now contact with the Theme author that, your CPT now supports post_thumbnail, and has one for each of the posts. They will guide you on how to display the images modifying their templates (if necessary). You can mention this issue link as well. If necessary we both can work on the issue - if there's anything not maintained by NanoSupport. :smile:

fang-yu commented 6 years ago

Thank! I will try.

fang-yu commented 6 years ago

Hi, I have contact with theme deveopler, they provide the solution with:

please add this code to Extra\single.php file

<?php 
if ( get_post_thumbnail_id() ) {
$thumb_args = !empty( $thumb_args ) ? $thumb_args : array();
extra_the_post_featured_image( $thumb_args );
echo $score_bar;
}
?>

After this code:

<div class="post-wrap">

this works, but have to manually set the feature image one by one, so I use quick feature image plugin, but does work with the kn post, it is due to the plugin confliction?

mayeenulislam commented 6 years ago

I can see the featured image is visible to the detail page as well as the search result page. So the promise from the theme and from us is fulfilled. So from our plugin's POV we're closed here.

But, you want to bulk set featured image to all the posts you want, that's a different issue, and out of the scope of our plugin and our support. The plugin you are using to bulk set featured images might not work how WordPress core work for featured images. Here's a solution just as a well-wisher:

Before activating the plugin, edit the file and set your post thumbnail id on line # 19. Get the image id by clicking on the image from Media library. Get the id from the URL: eg. /wp-admin/upload.php?item=12.

Plugin: Set featured image on activation https://gist.github.com/mayeenulislam/bf0367616c9cedbd7dddda036dae540f


We'd love to have a star rating (:star::star::star::star::star:) with review: https://wordpress.org/support/plugin/nanosupport/reviews#new-post

fang-yu commented 6 years ago

Thanks, I will try to contact the plugin developer. another question is that the style of the kb post is different from the blog blog, which I think it should be inherit from the blog post which will make the whole style of the site more consistent.