随机缩略图 Wordpress
Random thumbnails Wordpress
我正在尝试在 Wordpress 每个 post 的末尾加载 4 个随机缩略图,每个缩略图应该 link 到其各自的 post。我不知道如何正确地做到这一点,因为我对 PHP 知之甚少。我在获取缩略图和标题的主题中找到了这个代码片段:
<div class="col-sm-4 col-md-4 col-lg-4 tiles" id="post-<?php the_ID(); ?>" <?php post_class( 'post' ); ?> itemscope="" itemtype="http://schema.org/BlogPosting">
<?php
if ( has_post_thumbnail() ) {
echo '<div class="post-thumbnail">';
echo '<a href="' . esc_url( get_permalink() ) . '">';
echo get_the_post_thumbnail( $post->ID, 'shop_isle_blog_image_size' );
echo '</a>';
echo '</div>';
}
?>
<div class="tile_title">
<a class="post-title"><a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title(); ?></a></a>
</div>
</div>
此外,缩略图应与当前 post 来自同一类别。例如。如果有人正在阅读来自 "Travel" 类别的博客post,则 4 个缩略图应该仅来自该类别,其余类别也是如此。是否有可能做到这一点?
这称为 "related posts" 功能。为此有很多插件,例如 YARPP 就是这样一个插件。
如果你想避免插件,你可以在模板本身中获得具有此功能的主题。例如,我的博客使用 Ribbon theme 并包含此代码。
我正在尝试在 Wordpress 每个 post 的末尾加载 4 个随机缩略图,每个缩略图应该 link 到其各自的 post。我不知道如何正确地做到这一点,因为我对 PHP 知之甚少。我在获取缩略图和标题的主题中找到了这个代码片段:
<div class="col-sm-4 col-md-4 col-lg-4 tiles" id="post-<?php the_ID(); ?>" <?php post_class( 'post' ); ?> itemscope="" itemtype="http://schema.org/BlogPosting">
<?php
if ( has_post_thumbnail() ) {
echo '<div class="post-thumbnail">';
echo '<a href="' . esc_url( get_permalink() ) . '">';
echo get_the_post_thumbnail( $post->ID, 'shop_isle_blog_image_size' );
echo '</a>';
echo '</div>';
}
?>
<div class="tile_title">
<a class="post-title"><a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title(); ?></a></a>
</div>
</div>
此外,缩略图应与当前 post 来自同一类别。例如。如果有人正在阅读来自 "Travel" 类别的博客post,则 4 个缩略图应该仅来自该类别,其余类别也是如此。是否有可能做到这一点?
这称为 "related posts" 功能。为此有很多插件,例如 YARPP 就是这样一个插件。
如果你想避免插件,你可以在模板本身中获得具有此功能的主题。例如,我的博客使用 Ribbon theme 并包含此代码。