// 假设你要查询的标签名称是 'example-tag'
$tag_name = 'example-tag';
$term = get_term_by( 'name', $tag_name, 'post_tag' );
'tag_id' => $term->term_id,
'posts_per_page' => 5, // 调用的文章数量
$posts = get_posts( $args );
foreach( $posts as $post ) {
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php
// 假设你要查询的标签名称是 'example-tag'
$tag_name = 'example-tag';
// 获取标签对象
$term = get_term_by( 'name', $tag_name, 'post_tag' );
// 检查标签是否存在
if ( $term ) {
// 根据标签ID获取文章
$args = array(
'tag_id' => $term->term_id,
'posts_per_page' => 5, // 调用的文章数量
);
$posts = get_posts( $args );
if ( $posts ) {
// 输出文章
foreach( $posts as $post ) {
setup_postdata( $post );
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php
}
wp_reset_postdata();
} else {
echo '没有找到相关文章。';
}
} else {
echo '标签不存在。';
}
?>
<?php
// 假设你要查询的标签名称是 'example-tag'
$tag_name = 'example-tag';
// 获取标签对象
$term = get_term_by( 'name', $tag_name, 'post_tag' );
// 检查标签是否存在
if ( $term ) {
// 根据标签ID获取文章
$args = array(
'tag_id' => $term->term_id,
'posts_per_page' => 5, // 调用的文章数量
);
$posts = get_posts( $args );
if ( $posts ) {
// 输出文章
foreach( $posts as $post ) {
setup_postdata( $post );
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php
}
wp_reset_postdata();
} else {
echo '没有找到相关文章。';
}
} else {
echo '标签不存在。';
}
?>