如何将最近发布的内容的缩略图自动添加到WordPress的owl-carousel中?

时间:2016-09-27 作者:Weber

This is the site that I am working with. 我需要将绿色图像制作成最近帖子的缩略图,以便能够让内容作者/作者(非开发人员)指定一个缩略图显示在最近帖子的旋转木马中。我在wordpress中通过一个我正在设计的主题来实现这一点。我已经实现了旋转木马,但我不知道如何让绿色图像显示最近的帖子“缩略图”。

这是代码

    <div class="jumbotron" >
        <div class="container-fluid">
            <div class="row" id="spacer"></div>
            <div class="row" id="btn-row">
                <div class="col-md-3"></div>
                <div class="col-md-6" class="splash-btn-col">
                    <a href="http://52.35.5.149/content/content/" class="splash-btn">Content</a>
                    <a href="http://www.fractured-gaming.com/forums/" class="splash-btn">Forums</a>
                </div>
                <div class="col-md-3"></div>
            </div>
            <div class="row">
                <div id="owl-demo" class="owl-carousel owl-theme">
                     <div class="item"><h1>1</h1></div>
                     <div class="item"><h1>2</h1></div>
                     <div class="item"><h1>3</h1></div>
                     <div class="item"><h1>4</h1></div>
                     <div class="item"><h1>5</h1></div>
                     <div class="item"><h1>6</h1></div>
                     <div class="item"><h1>7</h1></div>
                     <div class="item"><h1>8</h1></div>
                     <div class="item"><h1>9</h1></div>
                     <div class="item"><h1>10</h1></div>
                     <div class="item"><h1>11</h1></div>
                     <div class="item"><h1>12</h1></div>
                     <div class="item"><h1>13</h1></div>
                     <div class="item"><h1>14</h1></div>
                     <div class="item"><h1>15</h1></div>
                     <div class="item"><h1>16</h1></div>
                </div>

                <script>
                    $(document).ready(function() {

                  var owl = $("#owl-demo");

                  owl.owlCarousel({
                      items : 10, //10 items above 1000px browser width
                      itemsDesktop : [1000,5], //5 items between 1000px and 901px
                      itemsDesktopSmall : [900,3], // betweem 900px and 601px
                      itemsTablet: [600,2], //2 items between 600 and 0
                      itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
                  });

                  // Custom Navigation Events
                  $(".next").click(function(){
                    owl.trigger(\'owl.next\');
                  })
                  $(".prev").click(function(){
                    owl.trigger(\'owl.prev\');
                  })
                  $(".play").click(function(){
                    owl.trigger(\'owl.play\',1000); //owl.play event accept autoPlay speed as second parameter
                  })
                  $(".stop").click(function(){
                    owl.trigger(\'owl.stop\');
                  })

                });
                </script>
            </div>
        </div>  
    </div>
所以我在下面尝试了这个,它使屏幕变白了,当我用谷歌chrome检查时,由于某种原因,身体是空的。

    <div class="jumbotron" >
        <div class="container-fluid">
            <div class="row" id="spacer"></div>
            <div class="row" id="btn-row-fluid">
                <div class="col-xs-3"></div>
                <div class="col-xs-6" class="splash-btn-col">
                    <div class="col-xs-5">
                        <a href="http://52.35.5.149/content/content/" class="splash-btn" id="content-btn">Content</a>
                    </div>
                    <div class="col-xs-2"></div>
                    <div class="col-xs-5">
                        <a href="http://www.fractured-gaming.com/forums/" class="splash-btn">Forums</a>
                    </div>
                </div>
                <div class="col-xs-3"></div>
            </div>
            <div class="row">
                <div id="owl-demo" class="owl-carousel owl-theme">
                 <?php 
                    $args = array(
                        \'post_type\' => \'post\', //this tells WP what type of posts you want to get (post, page, etc..)
                        \'posts_per_page\' => 1, // this is the number of posts you want to get
                        \'order\' => \'DESC\' // this is the order you want it to use
                        \'orderby\' => date // you want to order by date if you want the latest ones
                    );

                    // Custom query.
                    $query = new WP_Query( $args );  // creating the query

                    // Check that we have query results.
                    if ( $query->have_posts() ) { 
                        // Start looping over the query results.
                        while ( $query->have_posts() ) {

                            //get the post
                            $query->the_post();
                            $id=get_the_ID(); //getting post id (not neccessary here)
                            $url=wp_get_attachment_image_src( get_post_thumbnail_id( $id ), \'full\' ); //getting the url of the post image
                            ?>     

                    <div class="item">
                        <a href="<?php the_permalink();?>"><img src="<?php echo $url;?>"></a>
                    </div>

                            <?php         
                        } 
                    } 
                    // Restore original post data.
                    wp_reset_postdata(); 
                    ?>
                </div> 

                <script>
                    $(document).ready(function() {

                  var owl = $("#owl-demo");

                  owl.owlCarousel({
                      items : 6, //10 items above 1000px browser width
                      itemsDesktop : [1000,5], //5 items between 1000px and 901px
                      itemsDesktopSmall : [900,3], // betweem 900px and 601px
                      itemsTablet: [600,2], //2 items between 600 and 0
                      itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
                  });

                  // Custom Navigation Events
                  $(".next").click(function(){
                    owl.trigger(\'owl.next\');
                  })
                  $(".prev").click(function(){
                    owl.trigger(\'owl.prev\');
                  })
                  $(".play").click(function(){
                    owl.trigger(\'owl.play\',1000); //owl.play event accept autoPlay speed as second parameter
                  })
                  $(".stop").click(function(){
                    owl.trigger(\'owl.stop\');
                  })

                });
                </script>
            </div>
        </div>  
    </div>
:

1 个回复
最合适的回答,由SO网友:Berto 整理而成

我看不到你的网站。但是,根据您添加的代码,您可以尝试以下操作:css:

.owl-controls .owl-pagination .owl-page span{
height: 50px;
width:50px;
background-size: cover;
background-position: center;}
JS公司:

$(\'.owl-controls .owl-pagination .owl-page\').each(function(index, value){
    $(this).children(\'span\').css(\'background-image\', "url(\'"+$(\'.owl-carousel .owl-wrapper .item\').eq(index).find(\'img\').attr(\'src\')+"\')");
});
以下是一个工作示例:http://codepen.io/BertoMejia/pen/LRLRBg

相关推荐

显示作者姓名PHP(自制插件)

我有一个需要帮助的问题,因为我自己找不到解决办法。我接管了一个网站,之前有人在那里创建了一个自制插件。。使用默认插件“Contact Form 7”,用户可以在页面上创建帖子。()https://gyazo.com/c8b20adecacd90fb9bfe72ad2138a980 )关于自行创建的插件“Contact Form 7 extender”,帖子是通过PHP代码在后台生成的(https://gyazo.com/115a6c7c9afafd2970b66fd421ca76a3)其工作原理如下:如果