Php 如何从wordpress到图像幻灯片动态获取图像?
我已经设计了一个网站,我正在转换到wordpress网站,因为我是wordpress的新手,我无法从wordpress动态获取图像,用于引导图像旋转木马 这是我使用Php 如何从wordpress到图像幻灯片动态获取图像?,php,html,css,wordpress,twitter-bootstrap,Php,Html,Css,Wordpress,Twitter Bootstrap,我已经设计了一个网站,我正在转换到wordpress网站,因为我是wordpress的新手,我无法从wordpress动态获取图像,用于引导图像旋转木马 这是我使用 但我需要帖子:这是这样的: <?php query_posts(array('category_name' => 'social', 'posts_per_page' => 5)); if(have_posts())
但我需要帖子:这是这样的:
<?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>
这是屏幕截图
为了更好地理解,我建议使用
wp\u Query
代替Query\u posts
现在,试试这个:
<?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>
对不起,我遇到了同样的问题。为什么?你试过那个密码吗?你能发布你的全部代码吗?我已经编辑了一个问题,请检查它,如果你能帮我的话会很棒。你能描述一下编辑代码的问题吗?没有显示图像??这部分代码显示错误,它说语法错误(我在问题中插入了图像),请检查它