-
-
以下代码会显示与当前文章具有相同标签的四篇文章,你可以把他加入到 single.php 模板中你想显示的位置上。
但是这段代码并不包含文章的展示样式,也就是说你需求的样式需要你自己写,因为每个主题都不一样,所以没办法提供通用的代码。不过这也不难,可以去文章列表页面复制已有的代码。
<?php $tags = wp_get_post_tags( $post->ID ); if ( $tags ) { $first_tag = $tags[0]->term_id; $args = array( 'tag__in' => array( $first_tag ), 'post__not_in' => array( $post->ID ), 'posts_per_page' => 4, 'caller_get_posts' => 1 ); $my_query = new WP_Query( $args ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php endwhile; } wp_reset_query(); } ?>
-
求!文章内页底部相关文章利用标签调用相关内容的代码
寻求帮助 / 46 / 2 / 发布于 2021-11-14 14:13:58 / 活跃于 2021-11-14 14:48:24