gpt4 book ai didi

php - 如何动态获取图像从wordpress到图像幻灯片?

转载 作者:行者123 更新时间:2023-11-28 03:15:43 24 4
gpt4 key购买 nike

我设计了一个网站,我正在将其转换为 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>

这是截图

This is the error i am getting

最佳答案

我建议使用 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>

关于php - 如何动态获取图像从wordpress到图像幻灯片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27999254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com