1
我正在使用的主题Coral Dark一个博客的功能。这个主题有后缩略图的支持,我想从个人的帖子删除,并让他们在其他地方(在家,档案,类别等)。缩略图是使用可插入功能创建的,因此理论上我应该重写它。如果我将其添加到我的子主题的functions.php中:不能覆盖的帖子只有
function coral_dark_post_thumbnail() {}
缩略图会有效消失。但是,如果我使用条件运行帖子只:
if (is_single()) {
function coral_dark_post_thumbnail() {}
}
它什么都不做。缩略图仍然无处不在。我甚至可以用is_single
替换其他任何东西,因为WordPress简单地忽略它。如果我添加否定条件像这样:
if (! is_single()) {
function coral_dark_post_thumbnail() {}
}
缩略图消失,但无处不在。再次,我可以替换is_single
,因为结果是一样的。我不明白发生了什么事。
这是原来的功能:
if (! function_exists('coral_dark_post_thumbnail')) :
/**
* Displays an optional post thumbnail.
*
* Wraps the post thumbnail in an anchor element on index views, or a div
* element when on single views.
*
* Create your own coral_dark_post_thumbnail() function to override in a child theme.
*
*/
function coral_dark_post_thumbnail() {
if (post_password_required() || is_attachment() || ! has_post_thumbnail()) {
return;
}
if (is_singular()) :
?>
<div class="post-thumbnail">
<?php the_post_thumbnail('large'); ?>
</div><!-- .post-thumbnail -->
<?php else : ?>
<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
<?php the_post_thumbnail('post-thumbnail', array('class' => 'alignleft smallpostthumb', 'alt' => the_title_attribute('echo=0'), 'sizes' => '(max-width: 480px) 100vw, 210px')); ?>
</a>
<?php endif; // End is_singular()
}
endif;
提前非常感谢。 :)
不幸的是,这将无法工作,因为的封堵功能的一点是,如果有另一个同名的函数已经存在,它们不运行:'如果(function_exists(“coral_dark_post_thumbnail”)!):'所以,如果我把功能,无论我提出的条件内内的条件都无关紧要了,因为原来的功能将只是一个事实,即我声明了一个又一个具有相同名称的停止。这就是为什么我希望仅在个别帖子中宣布它(并因此被覆盖)。 – Stealth
我的另一个选项是复制/粘贴整个原有的功能,并把它的状态中,但是这不是我要找的。 – Stealth
你有没有试过按照上述方式做? – DpEN