I want to show pictures in search results
-
I want to show pictures in search results
use template nomos
https://phone-shelter.com/?s=iphoneThe page I need help with: [log in to see the link]
-
It sometimes depends on the theme.
Sometimes the theme has this as a customizable feature under Customizer.Otherwise, you can edit the content-search.php (or sometimes just search.php) file in your child theme, and output the featured image like this:
<?php
if ( has_post_thumbnail() ) { // check if the post Thumbnail
the_post_thumbnail();
} ?>So it would look something like this:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> if ( has_post_thumbnail() ) { // check if the post Thumbnail the_post_thumbnail(); } <header class="entry-header"> <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> </header><!-- .entry-header -->
Can you edit the file please?
<?php $blog_full_content = nomos_get_option( 'blog_full_content', 'no' ); $width = '1040'; $height = '640'; ?> <?php if ( have_posts() ) : ?> <div class="blog-content classic"> <?php while ( have_posts() ) : the_post(); ?> <article <?php post_class( 'post-item' ); ?>> <div class="post-info"> <div class="header-info"> <h3 class="post-title"><?php if ( is_sticky() && is_home() && ! is_paged() ) { printf( '<i class="fa fa-bookmark" aria-hidden="true"></i>', nomos_esc_text_html( '', 'nomos' ) ); } ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <div class="nomos-post-meta"> <a class="nomos-post-date" href="<?php the_permalink(); ?>"><span><?php echo get_the_date(); ?></span></a> <span class="nomos-post-author"> <span><?php echo nomos_esc_text_html( 'posted by: ', 'nomos' ) ?></span> <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) ?>"> <?php the_author() ?> </a> </span> <div class="nomos-comment-count"> <?php comments_number( nomos_esc_text_html( '0 Comments', 'nomos' ), nomos_esc_text_html( '1 Comment', 'nomos' ), nomos_esc_text_html( '% Comments', 'nomos' ) ); ?> </div> </div> </div> <div class="nomos-footer-info"> <div class="nomos-cat-post"> <?php $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { printf( nomos_esc_text_html( 'Categories: %1$s', 'nomos' ), $categories_list ); // WPCS: XSS OK. } ?> </div> <div class="nomos-tag-post"> <?php the_tags(); ?> </div> </div> </div> </article> <?php endwhile; ?> <?php wp_reset_postdata(); ?> </div> <?php nomos_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?>
Try this:
https://pastebin.com/aqm6LDRfIn this case, the image needs to come from a post type, and needs to be in the Featured Image field of your post.
Unfortunately the code does not work when I insert it I get a message
There has been a critical error on this website.Is there a net can do this feature the appearance of images in the search
Thank you so muchYou can use this php syntax checker to see there are no errors:
https://extendsclass.com/php-tester.htmlthat I posted here:
https://pastebin.com/aqm6LDRfIf you are throwing an error, maybe you didn’t copy and paste all the code into your file? You can see the raw code here:
https://pastebin.com/raw/aqm6LDRfOtherwise, the theme may not have access to the the_post_thumbnail() function in WordPress. However, it is native:
https://developer.www.ads-software.com/reference/functions/the_post_thumbnail/
- The topic ‘I want to show pictures in search results’ is closed to new replies.