Php 在wordpress中循环浏览粘性帖子?
我是Wordpress的新手,我正在尝试使用以下代码循环浏览粘性帖子:Php 在wordpress中循环浏览粘性帖子?,php,wordpress,Php,Wordpress,我是Wordpress的新手,我正在尝试使用以下代码循环浏览粘性帖子: <?php /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Query sticky posts */
<?php
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
/* Query sticky posts */
$stickies = query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
?>
<?php
foreach ($stickies as $sticky) {
the_title();
comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' );
}
?>
获取这两篇好文章,但我仍然有以下错误消息:警告:为foreach()提供的参数无效
完整代码:
<?php
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
$stickies = query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
?>
<?php
foreach ($stickies['WP_Post Object'] as $sticky) {
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumbnail', array('class' => "media-object img-rounded"));
}
the_title();
comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' );
}
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="media">
<a class="pull-left" href="<?php the_permalink() ?>">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumbnail', array('class' => "media-object img-rounded"));
}
?>
</a>
<div class="media-body">
<h3 class="media-heading"><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h3>
Par <?php the_author(); ?>, le <?php the_time('j F Y'); ?> - <?php comments_number( 'Pas de commentaires', '1 commentaire', '% commentaires' ); ?>
<?php the_excerpt(); ?>
</div>
</div> <!-- /media -->
<?php endwhile; ?>
<?php endif; ?>
PAR,LE
试试这个:
$stickies = query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1, 'ignore_sticky_posts' => true) );
编辑:
我认为你应该使用标准的wordpress帖子循环:
while (have_posts()) : the_post();
the_title();
endwhile;
编辑:
您可以使用倒带帖子()
开始新的循环:
// main loop
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
// rewind
<?php rewind_posts(); ?>
// new loop
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
//主循环
//倒带
//新回路
这两篇文章仍然使用此代码。问题似乎在foreach循环中(参见OP edit),问题是我已经有了一个“标准文章”的循环。我只想在非stiky文章列表之前的旋转木马中显示stiky文章…始终可以使用rewind_posts();或者使用WP_查询类创建自定义循环
// main loop
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
// rewind
<?php rewind_posts(); ?>
// new loop
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>