wordpress - post_tags 不输出标签
我正在尝试使用 post_tags 引用来获取与帖子关联的标签并将其用作 div 的类。我似乎无法让它工作......有什么建议吗?
<div id="workarchives_items">
<?php
global $post;
$myposts = get_posts('numberposts=100&offset=news&category_name=portfolio');
foreach($myposts as $post) :
setup_postdata($post);
?>
<div class="workitem <?php $posttags = get_the_tags(); ?> ">
<div class="workitem_photo"><?php the_post_thumbnail('150,200'); ?></div>
<div class="workitem_title"><?php the_title();?></div>
<div class="workitem_description"><?php the_excerpt(); ?></div>
<a class="workitem_projectdetails" href="<?php the_permalink(); ?>" style="display:none;">Project Details</a>
</div>
<?php endforeach; ?>
</div>
我用过这个:
<?php
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
echo $tag->name . ' ';
}
}
}
?>
但它只显示第一个标签,我如何修改它以显示全部标签。
I am trying to use the post_tags reference to get the tag associated with a post and use it as a class for a div. I just cant seem to get it working... any advice?
<div id="workarchives_items">
<?php
global $post;
$myposts = get_posts('numberposts=100&offset=news&category_name=portfolio');
foreach($myposts as $post) :
setup_postdata($post);
?>
<div class="workitem <?php $posttags = get_the_tags(); ?> ">
<div class="workitem_photo"><?php the_post_thumbnail('150,200'); ?></div>
<div class="workitem_title"><?php the_title();?></div>
<div class="workitem_description"><?php the_excerpt(); ?></div>
<a class="workitem_projectdetails" href="<?php the_permalink(); ?>" style="display:none;">Project Details</a>
</div>
<?php endforeach; ?>
</div>
I've used this:
<?php
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
echo $tag->name . ' ';
}
}
}
?>
But it only shows the first tag, how can I modify it to show them all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试去掉这一行(以及等效的右大括号):
if (1 == $count) {
Try getting rid of this line (and the equivalent closing curly brace):
if (1 == $count) {