0

我的目标是摆脱所有页面上的侧边栏,但我的网站安装了 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);
  }
}
4

3 回答 3

3

根主题主页上有此指南:

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'
  )
);

也可以指定隐藏侧边栏的某些模板。

于 2014-08-03T23:08:40.100 回答
0

在没有安装主题本身的情况下,它看起来有主题选项,可让您使用标准 WP 管理区域禁用侧边栏。这将是一个推荐的选项,因为它使您可以在以后重新激活侧边栏。但是,如果您想永久删除侧边栏,请尝试注释掉 ; 的第 21-25 行base.php。这应该删除对根侧​​边栏功能的调用。

于 2013-10-23T13:38:46.213 回答
0

据我所知,没有通过 WordPress 管理员从根目录中删除侧边栏的选项。在您的子主题中functions.php抛出以下代码段以完全删除侧边栏:

// functions.php
add_filter('roots_display_sidebar', 'roots_sidebar_on_special_page');
function roots_sidebar_on_special_page($sidebar) {
  return false;
}

您还可以根据页面数据有条件地禁用侧边栏,这里有一些附加信息

于 2014-05-06T16:33:00.363 回答