我设计了一个网站,我正在转换为wordpress网站,因为我是wordpress的新手我无法从wordpress动态获取图像用于bootstrap图像轮播
这是我使用<?php bloginfo(template_url); ?>
但我需要帖子:这就是这样的:
<?php
query_posts(array('category_name' => 'social', 'posts_per_page' => 5));
if(have_posts()) : while(have_posts()) : the_post()
?>
<li><?php the_post_thumbnail('social'); ?></li>
<?php endwhile; endif; wp_reset_query(); ?>
这是我的图片幻灯片代码
<div class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 topmargin">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<?php
$qArgs = array(
'category_name' => 'mainslide',
'posts_per_page' => '5'
);
$newQuery = new WP_Query($qArgs); ?>
<div class="carousel-inner" role="listbox">
<?php if($newQuery->have_posts()) : ?>
<?php while($newQuery->have_posts()) : $newQuery->the_post(); ?>
<div class="item">
<?php echo get_the_post_thumbnail( $post->ID, 'full'); ?>
</div>
<?php endwhile;?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
这是屏幕截图
答案 0 :(得分:0)
我建议使用wp_Query
代替query_posts
,以便更好地理解read this
现在,试试这个:
<?php
$qArgs = array(
'category_name' => 'social',
'posts_per_page' => '5'
);
$newQuery = new WP_Query($qArgs); ?>
<div class="carousel-inner" role="listbox">
<?php if($newQuery->have_posts()) : ?>
<?php while($newQuery->have_posts()) : $newQuery->the_post(); ?>
<div class="item">
<?php echo get_the_post_thumbnail( $post->ID, 'full'); ?>
</div>
<?php endwhile;?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>