wordpress用户中心插件主题 页面添加状态?请wp大神解惑 谢谢 谢谢 谢谢

wordpress标签页面Recently we were asked how to display a limited number of tags after each post in your WordPress theme. Normally, you use a function the_tags() to display a link to the tags a post belongs to. However that function does not have a parameter to limit the number of tags displayed. So if your post has 12 tags, and your theme only has space for 5, then it might not look so good in the design. A lot of folks just limit the usage of tags, or don’t even include it in the templates. But in this article, we will show you how you can limit the number of tags after posts in your WordPress theme without limiting the number of tags you add to each post. 最近,我们被问到如何在WordPress主题的每个帖子之后显示有限数量的标签。 通常,您可以使用the_tags()函数来显示帖子所属标签的链接。 但是,该函数没有参数来限制所显示标签的数量。 因此,如果您的帖子有12个标签,而主题只有5个空间,则在设计中可能看起来不太好。 许多人只是限制标签的使用,甚至不将其包括在模板中。 但是在本文中,我们将向您展示如何限制WordPress主题中帖子后的标签数量,而又不限制您添加到每个帖子中的标签数量。 Edit: Apparently after writing this article, the most awesome Otto (@otto42) replied on my Google+ account to let me know that there is a simpler way of accomplishing this. 编辑:显然在写完这篇文章之后,最厉害的Otto(@ otto42)在我的Google+帐户上回复,让我知道有一种更简单的方法可以完成此操作。 First you need to open your theme’s functions.php file and add this function: 首先,您需要打开主题的functions.php文件并添加以下功能:
add_filter('term_links-post_tag','limit_to_five_tags');
function limit_to_five_tags($terms) {
return array_slice($terms,0,5,true);
}
You can change the 5 number to maximum count you want. 您可以将5数字更改为所需的最大数量。 Then open your loop.php, single.php, index.php, or wherever you want to add these post tags (must be inside a post loop), then paste the following code: 然后打开您的loop.php,single.php,index.php或您想要添加这些post标签的任何位置(必须在post循环内),然后粘贴以下代码: <?php the_tags() ?>
This is definitely a lot simpler than what I had come up with which I will leave in this post for those who care. 这绝对比我想出的要简单得多,我将在这篇文章中留给那些关心的人。
旧的复杂方法 (Old Complicated Method)All you need to do is paste the following code in your theme file (inside the post loop): 您需要做的就是将以下代码粘贴到主题文件中(在post循环内):
<?php
$posttags = get_the_tags();
$count=0; $sep='';
if ($posttags) {
echo 'Tags: ';
foreach($posttags as $tag) {
$count++;
echo $sep . '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
$sep = ', ';
if( $count > 5 ) break; //change the number to adjust the count
}
}
?>
The code above will display 6 tags in the theme. If you want to show less tags or more tags, simply adjust the $count > 5 line with the number you want. Remember, even though the count number says greater than 5, we see 6 tags. That is because the count is starting at 0. So if you want to show only 4 tags, then the number would need to be 3. 上面的代码将在主题中显示6个标签。 如果要显示更少的标签或更多的标签,只需将$ count> 5行调整为所需的数字即可。 请记住,即使计数数字大于5,我们也会看到6个标签。 那是因为计数从0开始。因此,如果您只想显示4个标签,则该数字必须为3。 If you want to change the separator, then you need to change line 9. The current code will separate by commas. You can also customize the styling by adding divs, list elements, or anything else that you like. 如果要更改分隔符,则需要更改第9行。当前代码将以逗号分隔。 您还可以通过添加div,列表元素或其他所需的样式来自定义样式。
翻译自: https://www.wpbeginner.com/wp-themes/how-to-show-limited-number-of-tags-after-posts-in-your-wordpress-theme/
wordpress标签页面

选择擅长的领域继续答题?
{@each tagList as item}
${item.tagName}
{@/each}
手机回答更方便,互动更有趣,下载APP
提交成功是否继续回答问题?
手机回答更方便,互动更有趣,下载APP
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
为你推荐:
下载百度知道APP,抢鲜体验使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。扫描二维码下载
×个人、企业类侵权投诉
违法有害信息,请在下方选择后提交
类别色情低俗
涉嫌违法犯罪
时政信息不实
垃圾广告
低质灌水
我们会通过消息、邮箱等方式尽快将举报结果通知您。说明
做任务开宝箱累计完成0
个任务
10任务
50任务
100任务
200任务
任务列表加载中...

我要回帖

更多关于 Wordpress主题 的文章

 

随机推荐