简体   繁体   English

在内容和侧边栏之前放置幻灯片-WordPress

[英]Placing a slideshow before the content and sidebar - WordPress

I'm trying to add an image slider before the content of the page which spans the full width of the page (I'm using bootstrap, so a 12 column div will be used). 我正在尝试在覆盖页面整个宽度的页面内容之前添加图像滑块(我正在使用引导程序,因此将使用12列的div)。

Here is the current code for the index.php file: 这是index.php文件的当前代码:

get_header(); ?>

    <div class="col-sm-12">
        <?php 
            echo do_shortcode("[metaslider id=2010]"); 
        ?>
    </div>

    <?php if ( have_posts() ) : ?>
        // The Loop

    <?php else : ?>

        <?php get_template_part( 'no-results', 'index' ); ?>

    <?php endif; ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

As you can see, I've tried to add in the image slider just below where the header is called, but it hasn't quite worked. 如您所见,我尝试将图像滑块添加到调用标头的位置下方,但效果不佳。 The image slider is being created with a width the same as the posts, as if it is part of the content. 正在创建与滑块相同宽度的图像滑块,就好像它是内容的一部分一样。 So the sidebar is still taking up the entire right side of the page. 因此,侧边栏仍占据页面的整个右侧。

I would like the image slider to span the whole page, and THEN the posts and sidebar are shown. 我希望图像滑块覆盖整个页面,然后显示帖子和侧边栏。

Any idea how to do this? 任何想法如何做到这一点? I tried placing various things inside different divs and what not but can't seem to get the right layout 我尝试将各种东西放置在不同的div中,但没有,但是似乎无法获得正确的布局

Update: header.php 更新: header.php

<div class="main-content">
    <div class="container">
        <div class="row">
            <div id="content" class="main-content-inner col-sm-12 col-md-8" itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/Blog">

(The rest of the code isn't really necessary as it's just the navigation and banner etc) (其余的代码实际上并不是必需的,因为它只是导航和横幅等)

The image slider is then placed within this div above main-content-inner col-sm-12 col-md-8 . 然后将图像滑块放置在main-content-inner col-sm-12 col-md-8上方的该div中。 The main-content is where the posts are output to, so I would need the image slider to go before this div. main-content是帖子输出到的地方,因此我需要在此div之前使用图像滑块。 I could move this code into the index.php code, but I'm not sure if that is necessarily good practice. 我可以将此代码移到index.php代码中,但是我不确定这是否一定是好的做法。 It's the only way I can see being able to put the image slider before the content 这是我看到能够将图像滑块放在内容前的唯一方法

Answer: 回答:

Updated my header.php to this: 将我的header.php更新为:

<div class="main-content">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <?php if (is_front_page()) { 
                    echo do_shortcode("[metaslider id=2010]"); 
                }?>
            </div>
            <div id="content" class="main-content-inner col-sm-12 col-md-8" itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/Blog">

Do this: 做这个:

Above: 以上:

<div class="main-content">

Is where you want to call your slideshow. 是您要调用幻灯片的地方。

If you don't want it to show on every page, use some conditional tags to control which page it appears on. 如果您不希望它显示在每个页面上,请使用一些条件标签来控制它出现在哪个页面上。 See: http://codex.wordpress.org/Conditional_Tags 请参阅: http//codex.wordpress.org/Conditional_Tags

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM