【发布时间】:2016-10-17 14:27:45
【问题描述】:
我有一个 Wordpress 24 的儿童主题,我希望在主博客区域上方的网格中显示特色帖子,而不是在博客区域中消失。所以应该出现在网格和博客循环中。
我已经搜索了主题的文件,但我没有找到线索,在哪里过滤了精选帖子。
我还试图摆脱不必要的复杂性并为子主题创建了一个新的 index.php:
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
the_title( '<h1 class="entry-title">', '</h1>' );
endwhile;
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
但即使有特色帖子也不见了。 (它只显示主循环)。
知道在哪里做这个把戏吗?
提前致谢!
24.10 更新: 在最近两个答案都解决不了问题后,我进一步研究了原来的二十四主题,找到了文件inc/featured-content.php,其中的精选内容被过滤掉了。
ll 中的函数 pre_get_posts。第 231 页负责这个问题 - 故意但没有提示,如何不过滤。
我假设,由于 inc/featured-content.php 包含一个类,我可以扩展它并 覆盖 pre_get_posts 方法?
但实际上,我不是 php-guru,我看不到原始类在哪里初始化...?有什么想法吗?
后续更新: 在functions.php,ll。 514 ff.,相关类是必需的:
/*
* Add Featured Content functionality.
*
* To overwrite in a plugin, define your own Featured_Content class on or
* before the 'setup_theme' hook.
*/
if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
require get_template_directory() . '/inc/featured-content.php';
}
这似乎是一个简单的覆盖问题?最好不要失去整个类的功能,而只是改变它......
【问题讨论】:
标签: wordpress wordpress-theming