网站管理员和博主不断寻找方法让他们的读者在他们的网站上保持活跃的时间越来越长。 他们采用的最常用技术之一是在每篇文章的末尾显示相关文章。 这是一种非常简单的技术,可以让您的访问者留在您的网站上。
显示相关文章/产品/视频会增加人们在您的网站上花费的时间。 这也是亚马逊等电子商务公司以及 YouTube 和 Netflix 等视频托管公司投资复杂的机器学习算法以创建有效推荐系统的原因。
虽然新创建的博客无法承受如此先进的技术,但在每篇文章的末尾显示相关文章是一个简单的技巧,可以帮助访问者在您的博客或网站上停留更长时间。 访问者在您的网站上花费的时间越长,他或她就越有可能进行购买。
让我们不要忘记它的 UI 方面,推荐系统在帮助人们找到正确的内容方面非常有帮助。 我不记得我连续观看推荐系统提供的 YouTube 视频的次数了。 显示相关帖子将减少导航时间并帮助将读者连接到正确的内容。
使用 Jetpack 相关文章模块
此相关帖子功能会遍历您的所有帖子并根据上下文对其进行分析,以找到可能激起访问者好奇心的正确相关帖子。
我更喜欢使用 Jetpack 的这个模块而不是运行额外的插件,因为分析和处理是从他们的云服务器执行的,这意味着您的服务器资源不会被用于相同的用途。
关于这个模块如何实际操作的一些事情:
- 至少需要显示 3 个相关的好帖子。 如果没有这三个帖子,则帖子末尾不会显示任何相关内容。
- 相关内容是根据标签、类别和帖子本身的内容生成的。
- 图像缩略图可以是以前帖子的特色图像,也可以是附加到要显示的相关帖子的图像。 它们被裁剪为 350px 宽 x 200px 高,儿子在选择特色图像时考虑这些尺寸,并确保它们能很好地转换为该尺寸。
此外,如果您想进一步修改模块的操作,您必须修改您的functions.php 文件中的一些代码。 大多数这些功能都涉及修改 Jetpack 相关的帖子过滤器。
- 更改显示的相关帖子的数量。 更改选项大小计数。
function jetpackme_more_related_posts( $options ) { $options['size'] = 6; return $options; } add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_more_related_posts' );
- 对于特定帖子,将其中一个相关帖子替换为自定义结果。 帖子 ID 是指相关的特定帖子。
function jetpackme_append_related_post( $hits, $post_id ) { // $post_id is the post we are currently getting related posts for if ( 2194 == $post_id ) { // Add 1036 to the front of the hits array array_unshift( $hits, array( 'id' => 1036 ) ); // Remove the last element of the array array_pop( $hits ); } return $hits; } add_filter( 'jetpack_relatedposts_filter_hits', 'jetpackme_append_related_post', 20, 2 );
- 从相关帖子结果中排除特定帖子。 再次识别帖子 ID 以排除它。
function jetpackme_exclude_related_post( $exclude_post_ids, $post_id ) { // $post_id is the post we are currently getting related posts for $exclude_post_ids[] = 1037; // Exclude post_id 1037 $exclude_post_ids[] = 1038; // Also exclude post_id 1038 return $exclude_post_ids; } add_filter( 'jetpack_relatedposts_filter_exclude_post_ids', 'jetpackme_exclude_related_post', 20, 2 );
- 将整个类别排除在相关帖子结果中。 将 category.slug 更改为您不想在相关帖子中看到的类别。
function jetpackme_filter_exclude_category( $filters ) { $filters[] = array( 'not' => array( 'term' => array( 'category.slug' => 'dogs' ) ) ); return $filters; } add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );
- 选择性地禁止相关帖子显示在选定帖子上。 is_single 数组包含许多未显示相关帖子的帖子 ID。
function jetpackme_no_related_posts( $options ) { if ( is_single( array( 17, 19, 1, 11 ) ) ) { $options['enabled'] = false; } return $options; } add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_no_related_posts' );
- 在相关内容的搜索结果中包含页面。
function jetpackme_add_pages_to_related( $post_type, $post_id ) { if ( is_array( $post_type ) ) { $search_types = $post_type; } else { $search_types = array( $post_type ); } // Add pages $search_types[] = 'page'; return $search_types; } add_filter( 'jetpack_relatedposts_filter_post_type', 'jetpackme_add_pages_to_related', 10, 2 );
- 如果在帖子中找不到图像,请添加默认后备图像。
function jeherve_custom_image( $media, $post_id, $args ) { if ( $media ) { return $media; } else { $permalink = get_permalink( $post_id ); $url = apply_filters( 'jetpack_photon_url', 'YOUR_LOGO_IMG_URL' ); return array( array( 'type' => 'image', 'from' => 'custom_fallback', 'src' => esc_url( $url ), 'href' => $permalink, ) ); } } add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 3 );
- 隐藏相关帖子上的发布日期。
.jp-relatedposts-post-date { display: none; }
您可以在他们的博客上阅读更多可以使用 Jetpack 使用相关帖子模块添加或修改的功能。
相关文章插件
如果您更愿意使用独立插件来执行显示相关帖子的功能,那么有两个免费插件应该可以完成任务。
- WordPress 的相关文章 – 不会降低您的网站速度并使用自己的缓存来执行任何繁重的工作。 自动创建相关帖子,插件允许手动编辑。 该插件有一个高级版本,它提供多站点支持和对相关帖子模板样式的更大控制。
- 分类法的相关帖子 – 此插件使用缓存查询来查找相关帖子。 按日期和分类/个人帖子向相关帖子匹配添加约束。 使用您自己的 HTML 模板,以便进行更多自定义。 短代码有助于使用小部件显示特定数量的相关帖子。
增加网站粘性
显示相关帖子肯定会增加访问者在您的网站上花费的时间。 利用它的力量,告诉我它是怎么回事。