如何编辑“发布到类别” Wordpress 帖子“linkify”的一部分整个短语而不仅仅是类别?
嘿伙计们,我有一个非常基本的问题(尽管我知道标题听起来很混乱),最好解释如下。这段代码是我目前拥有的:
<?php if (!is_page()): ?><?php ob_start(); ?><?php printf(__('Posted to %s', 'kubrick'), get_the_category_list(', ')); ?>
生成此 HTML 代码:
Posted to <a href="http://www.example.com/category/" title="View all posts in Category" rel="category tag">Category</a>
如您所见,该类别是通过此代码“链接”的,但是我希望整个短语成为链接的锚文本,如下所示
<a href="http://www.example.com/category/" title="View all posts in Category" rel="category tag">Posted to Category</a>
:我修改原始 PHP 代码以在超链接的锚文本中包含“发布到”文本吗?非常感谢! :)
Hey guys, I have a pretty basic question (even though I know the title sounds confusing) which is best explained as follows. This code is what I currently have:
<?php if (!is_page()): ?><?php ob_start(); ?><?php printf(__('Posted to %s', 'kubrick'), get_the_category_list(', ')); ?>
Which generates this HTML code:
Posted to <a href="http://www.example.com/category/" title="View all posts in Category" rel="category tag">Category</a>
As you can see, the category is 'linkified' by this code, however I would like the entire phrase to be the anchor text for the link, like this:
<a href="http://www.example.com/category/" title="View all posts in Category" rel="category tag">Posted to Category</a>
How would I modify the original PHP code to include the "Posted to" text in the hyperlink's anchor text? Much appreciated! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
get_the_category()
和get_category_link()
函数,如下所示:但是,您可能想考虑当帖子属于多个类别时会发生什么:您的原始代码将显示以逗号分隔的类别链接列表(例如“Posted in foo, bar, qux”),而此代码将为每个类别显示“Posted in [name]”(例如“Posted in foo Posted in bar Posted in qux”) )。
还应该注意的是,这个答案没有使用 WordPress 的
__()
在适当的情况下翻译结果文本的功能:您可能想考虑如何最好地支持非英语使用者。另外,没有必要在每个连续命令之后关闭并重新打开 PHP 标签 - 只需用分号分隔它们即可。
You can use
get_the_category()
andget_category_link()
functions as follows:However you may like to consider what happens when a post is in more than one category: your original code will show a list of category links separated by commas (e.g. "Posted in foo, bar, qux"), whereas this code will show "Posted in [name]" for each category (e.g. "Posted in foo Posted in bar Posted in qux").
It should also be noted that this answer does not use WordPress's
__()
function to translate the resulting text where appropriate: you may like to consider how best to support non-English speakers.Also, it's not necessary to close and reopen PHP tags after each contiguous command - just separate them with semicolons.