在Wordpress中如何在一个页面上有多个循环?
我正在使用我找到的一个很好的jquery幻灯片插件,并试图将其应用到我的Wordpress模板中。我尝试过下面的代码的各种格式,但我似乎不能得到它的方式我想要的 第一部分是文章的标题和内容使用特定类别读入滑块。我有以下三个部分:在Wordpress中如何在一个页面上有多个循环?,wordpress,Wordpress,我正在使用我找到的一个很好的jquery幻灯片插件,并试图将其应用到我的Wordpress模板中。我尝试过下面的代码的各种格式,但我似乎不能得到它的方式我想要的 第一部分是文章的标题和内容使用特定类别读入滑块。我有以下三个部分: <div class="details_wrapper"> <div class="details"> <div class="detail"> <?php query_posts('cat_ID=7&showposts
<div class="details_wrapper">
<div class="details">
<div class="detail">
<?php query_posts('cat_ID=7&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=8&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
<div class="detail">
<?php query_posts('cat_ID=9&showposts=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<h2 class="Lexia-Bold"><a href="<?php the_permalink() ?>">
<?php the_title() ?></a><?php the_excerpt(); ?></h2>
<?php endwhile; endif;
?>
</div><!-- /detail -->
</div><!-- /details -->
</div>
非常感谢您的帮助:)您是否尝试过使用
query_posts('cat_ID=9&posts_per_page=1');
或者我以前用过get_post来获得一定数量的帖子,比如
<?php
global $post;
$myposts = get_posts('posts_per_page=1&numberposts=-1&category=1');
foreach($myposts as $post) :
?>
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<?php setup_postdata($post);?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</div>
如果它只是你想要的一篇文章,你就不需要foreach或while循环了。你试过使用
query_posts('cat_ID=9&posts_per_page=1');
或者我以前用过get_post来获得一定数量的帖子,比如
<?php
global $post;
$myposts = get_posts('posts_per_page=1&numberposts=-1&category=1');
foreach($myposts as $post) :
?>
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<?php setup_postdata($post);?>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</div>
如果你只想要一篇文章,你就不需要foreach或while循环。我使用上面建议的方法来查询文章和该文章的特色图片,以完成这项工作:)谢谢Tianbo84!据我所知,
get_posts
和
行是关键。。。就像打开一个查询,然后在检索到数据后关闭它。我使用上面建议的方法来查询帖子和该帖子的特色图片,以完成这项工作:)谢谢Tianbo84!据我所知,get_posts
和
行是关键。。。就像打开一个查询,然后在检索到数据后关闭它。这很有效,谢谢!所以使用上面的方法从我选择的类别中引入一篇文章,这很好。不,那第二部分呢,它在文章的特色图片中提供了什么呢?我将编辑我的问题并发布上面的代码。我会使用同样的技术吗?获取“发布”缩略图(7,“大”)
将从该帖子中获取大格式的缩略图。我不确定如何通过查询循环获取图像,但对于get_post来说很容易。我想象你可以用图片url创建一个自定义帖子元,然后使用query\u posts('meta\u key=image\u url)获取它代码>使用此滑块的方式是
,但它一直从同一帖子中抓取图像。这对Tianbo84有效,谢谢!所以使用上面的方法从我选择的类别中引入一篇文章,这很好。不,那第二部分呢,它在文章的特色图片中提供了什么呢?我将编辑我的问题并发布上面的代码。我会使用同样的技术吗?获取“发布”缩略图(7,“大”)
将从该帖子中获取大格式的缩略图。我不确定如何通过查询循环获取图像,但对于get_post来说很容易。我想象你可以用图片url创建一个自定义帖子元,然后使用query\u posts('meta\u key=image\u url)获取它
使用此滑块的方式是
,但它会一直从同一帖子中抓取图像。