我是新来的Wordpress,我想知道,我可以添加属性“阅读更多”的链接。我可以添加属性到“阅读更多”吗?
<?php the_content('Read more'); ?>
//This creates the "read more" link
<a href="/" class="read-more">Read more</a>
所以我想添加一个类,但我不知道该怎么做。请帮忙。
p.s.我不想使用JavaScript,因为它会非常难看。
我是新来的Wordpress,我想知道,我可以添加属性“阅读更多”的链接。我可以添加属性到“阅读更多”吗?
<?php the_content('Read more'); ?>
//This creates the "read more" link
<a href="/" class="read-more">Read more</a>
所以我想添加一个类,但我不知道该怎么做。请帮忙。
p.s.我不想使用JavaScript,因为它会非常难看。
我虽然不改变核心功能的支持,您可以通过在wp-includes/post-template.php
编辑get_the_content
功能做到这一点:
function get_the_content($more_link_text = null, $stripteaser = 0) {
// ...
$output .= apply_filters('the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link whatever-you-want\">$more_link_text</a>", $more_link_text);
// ...
}
您不能直接向链接添加类,但可以在链接内添加一个跨度。从WordPress Codex:
<?php the_content('<span class="moretext">...on the edge of
your seat? Click here to solve the mystery.</span>'); ?>
我需要一个类添加到链接本身。 ..不在里面。 – 2012-03-13 03:20:19
@Derek为什么?任何你对链接进行造型的方式,你都可以做到这一点。无论如何,如果你真的需要这样做,你必须编写自己的函数来处理内容,或者可能有插件。 – steveax 2012-03-13 03:25:25
我在我的网站中使用了HTML5 popState,我使用类名来检测哪个链接将使用AJAX,并且我想让“read more”链接使用ajax。 – 2012-03-13 03:55:21
这样做会让您踏上升级跑步机。任何时候该文件在WordPress更新,你必须重新应用更改。更好的做法是在[函数文件]中定义你自己的函数(http://codex.wordpress.org/Theme_Development#Functions_File) – steveax 2012-03-13 04:34:50
像魅力一样工作!谢谢! – 2012-03-13 04:35:36
@Derek不会感到惊讶,如果WordPress更新打破您的网站。修改核心文件是一个非常脆弱的做法。 – steveax 2012-03-13 04:38:39