【问题标题】:Include a custom carousel to show it only on the home page包含自定义轮播以仅在主页上显示
【发布时间】:2018-03-22 18:42:54
【问题描述】:

我有一个自定义轮播,我只想显示主页。我已将轮播代码放置在一个名为 slider.php 的文件中,当我将其包含在 header.php 文件中时,我可以让滑块显示:

<?php require('../BlueQuote/wp-content/themes/greatmag/slider.php'); ?>

但是当我将它放在 index.phphome.php 中时,它没有显示在页面上(出于好奇,我尝试将它包含在 footer.php 并且它也确实显示在那里,但这不是我需要的)。我正在使用基于GreatMag 主题的子主题。 WordPress 4.9.4PHP 7 以及 Windows 7 上的 XAMPP,提前致谢!

【问题讨论】:

  • 在选项中,你有没有配置主页使用特定页面?
  • 是的,我已经设置好了,在本地主机上是localhost/BlueQuote
  • 我不是这个意思。可以将 WordPress 博客的主页设置为使用 blogroll 或特定页面模板。如果您使用后者,则模板可能不是home.phpindex.php
  • 哦,我明白了,是的,我已经在“设置”>“阅读”下进行了设置>您的主页显示:静态页面(在下面选择) 主页:主页和帖子页面是新闻页面。
  • 好的,无论主页页面使用哪个模板,您都需要在其中添加轮播。

标签: php wordpress


【解决方案1】:

我尝试调试这个主题,发现如下。

Header.php 将强制它显示在每个使用标题的页面上(因此这不起作用),并且 index.php 是一个通用模板文件,用于在没有更具体的匹配查询时显示页面(所以这也行不通)。

所以你只需要编辑 home.php 文件。在 php 函数之后和内容区域 div 之前添加此代码。这是部分的sn-p:

/.../

} else {
    $cols = 'col-md-8';
}
?>

<!-- This is where your code starts -->
<?php require('../BlueQuote/wp-content/themes/greatmag/slider.php'); ?>
<!--- This is where your code ends -->

    <div id="primary" class="content-area <?php echo $cols; ?>">
        <main id="main" class="site-main">

        <?php
        if ( have_posts() ) : ?>

            <div class="<?php greatmag_blog_layout(); ?>">
                <?php greatmag_grid_sizer(); ?>
/.../

这应该可以解决问题,因为您试图将代码添加到错误的部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    相关资源
    最近更新 更多