我的目标是摆脱所有页面上的边栏,但我的网站安装了 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);
}
}
最佳答案
根主题主页上有这方面的指南:
http://roots.io/the-roots-sidebar/
上面提到的是 Ali Exhalter,但基本上您需要找到 lib/config.php 文件并将适当的函数名称添加到数组列表中。在这种情况下,如果您希望从所有页面中删除,is_page 将起作用。
config.php 将如下所示:
function roots_display_sidebar() {
$sidebar_config = new Roots_Sidebar(
array(
'is_404',
'is_front_page',
'is_page'
),
/**
* Page template checks (via is_page_template())
* Any of these page templates that return true won't show the sidebar
*/
array(
'template-custom.php'
)
);
也可以指定隐藏侧边栏的某些模板。
关于php - WordPress Roots 主题摆脱所有页面的侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19511473/