似乎这应该超级简单,但我找不到合适的API函数来使其正常工作...
我想使用帖子标签来填充关键字元内容...
<meta name="keywords" content="tags from post go here seperated by commas">
我已经尝试过了,但是它创建了每个帖子标签的链接列表...
<meta name="keywords" content="<?php echo the_tags('',' , '); ?>" />
尝试类似的东西:
<?php
$postTags = get_the_tags();
$tagNames = array();
foreach($postTags as $tag) {
$tagNames[] = $tag->name;
}
?>
<meta name="keywords" content="<?php echo implode(",", $tagNames); ?>" />
您需要使用模板函数get_the_tags
来获取数据,而不是让WordPress为您输出数据。然后,您可以遍历此数组并输出列表,但是您需要:
get_the_tags
the_tags()自动显示每个帖子标签的链接。您可以使用<?php
if ( $posttags = get_the_tags() ) {
foreach($posttags as $tag)
echo $tag->name . ' ';
}
?>
返回标签对象的数组,然后可以循环遍历并获取标签的名称。
您可以尝试使用此方法:
get_the_tags()
Oneline warriant for amercader版本。
<meta name="keywords" content="<?php if(is_single()) {
$metatags = get_the_tags($post->ID);
foreach ($metatags as $tagpost) {
$mymetatag = apply_filters('the_tags',$tagpost->name);
$keyword = utf8_decode($mymetatag); // Your filters...
echo $keyword.",";
}
}
?>your,key,words" />