【发布时间】:2013-10-22 07:18:29
【问题描述】:
我的目标是摆脱所有页面上的侧边栏,但我的网站安装了 Roots,因此 page.php 模板只有以下代码:
<?php get_template_part('templates/page', 'header'); ?>
<?php get_template_part('templates/content', 'page'); ?>
第一个问题,这是什么意思?这些模板“部分”在哪里?其次,如何去掉部分或全部页面的侧边栏?
编辑:在 templates/content-page.php 中添加代码:
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<nav class="pagination">', 'after' => '</nav>')); ?>
<?php endwhile; ?>
我有更多好东西。这是来自 lib/sidebar.php。看起来 Roots 有一些方法来决定单个元素,基于它们上的标志或其他东西,是否显示它们。有 PHP 知识的人可以解释一下这可能会做什么吗?
<?php
/**
* Determines whether or not to display the sidebar based on an array of conditional tags or page templates.
*
* If any of the is_* conditional tags or is_page_template(template_file) checks return true, the sidebar will NOT be displayed.
*
* @param array list of conditional tags (http://codex.wordpress.org/Conditional_Tags)
* @param array list of page templates. These will be checked via is_page_template()
*
* @return boolean True will display the sidebar, False will not
*
*/
class Roots_Sidebar {
private $conditionals;
private $templates;
public $display = true;
function __construct($conditionals = array(), $templates = array()) {
$this->conditionals = $conditionals;
$this->templates = $templates;
$conditionals = array_map(array($this, 'check_conditional_tag'), $this->conditionals);
$templates = array_map(array($this, 'check_page_template'), $this->templates);
if (in_array(true, $conditionals) || in_array(true, $templates)) {
$this->display = false;
}
}
private function check_conditional_tag($conditional_tag) {
if (is_array($conditional_tag)) {
return $conditional_tag[0]($conditional_tag[1]);
} else {
return $conditional_tag();
}
}
private function check_page_template($page_template) {
return is_page_template($page_template);
}
}
【问题讨论】:
-
在模板/页面的文件夹中查找,找到
header.php,虽然这不是你想要的,但在page.php(第二个template_part())里面会有一个get_sidebar()您需要删除的功能 =] -
很难理解你的英语。没有文件夹模板/页面。在 templates/ 中有一个 header.php,但它没有提到侧边栏。我不知道你最后一句话是什么意思。有一个 templates/content-page.php 文件,但没有提及侧边栏。我将编辑我的原始问题以添加其中的代码。
-
不一定在循环中,但更有可能在循环之外。 (否则,如果有 5 个帖子,将打印 5 个以上的侧边栏)。也找
dynamic_siderbar() -
templates/content-page.php 中的循环之外没有任何内容。我发布了它的全部内容。 dynamic_sidebar() 在哪里?
-
在根目录下查看 lib 文件夹,有 config.php。该函数右侧模板名称中有一个函数roots_display_sidebar,它不显示侧边栏,就像它已经有template-custom.php一样。自定义模板不显示侧边栏。