Joomla教程菜鸟教程显示帖子缩略图而不是特色图片

我希望我能解释我在这里的目的。 在我当前项目的主页上,我显示了每个帖子的特色图片缩略图,以及帖子内容的摘录。 在每个实际的帖子页面中,都有一个默认的 WP 图库,里面有 2 到 4 张图片。

我想做的是让我的客户不必总是在每个帖子中使用特色图片,这样缩略图就会始终显示在主页上。 换句话说,现在,他必须选择一张图片作为特色图片,以便主页循环中的每个帖子都有代表性的缩略图。

我可以做到即使他没有为帖子选择特色图片,仍然有缩略图来代表帖子吗? 如果没有选择特色图片,我可以让它自动选择帖子图库中的第一张图片吗?

为了以防万一,以下是我正在使用的一些代码:

 <div id="image-wrap"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?> </div><!--end image-wrap--> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php the_title('<h2 class="entry-title"><a href="'%20.%20get_permalink()%20.%20'" title="' . the_title_attribute('echo=0') . '" rel="bookmark">', '</a></h2>'); ?> <div class="entry-content"> <?php the_content(__('Continue reading', 'example')); ?> <?php wp_link_pages('before=<p class="pages">' . __('Pages:','example') . '&after=</p>'); ?> </div> </div> <?php endwhile; ?> <?php else : ?> <p class="no-posts"><?php _e('Sorry, no posts matched your criteria', 'example'); ?></p> <?php endif; ?> <?php wp_reset_query(); ?> 

然后这是在我的函数文件中:

 // This theme uses post thumbnails add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 150, 100, true ); // Automatically makes featured image thumbs a clickable link add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 ); function my_post_image_html( $html, $post_id, $post_image_id ) { $html="<a href="" . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>'; return $html; } // This theme displays full size featured image on the Post's page function InsertFeaturedImage($content) { global $post; $original_content = $content; if ( current_theme_supports( 'post-thumbnails' ) ) { if ((is_page()) || (is_single())) { $content = the_post_thumbnail('page-single'); $content .= $original_content; } } return $content; } add_filter( 'the_content', 'InsertFeaturedImage' ); 

http://dependablecarcompany.com 是地址,如果您想了解我在说什么。 在查看标题为“1991 GMC Sierra”的帖子时,您会明白我的意思。 我没有在帖子中使用特色图片,因此没有显示缩略图。 提前致谢!

原文链接:https://www.wordpresshy.com/370954

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享