我将开始说我在PHP方面很糟糕。我可以修改一些简单的代码,但我不知道当我必须写自己的代码时,我在做什么。
目标:在我的wordpress index.php页面上显示来自一个特定类别的2个循环。第一个循环应该显示一个粘性的帖子,第二个应该显示所有其他的帖子。
我想显示的类别是“28”。
我已经找到了这个页面:Posts,但我不知道如何将它付诸行动。
我花了几个小时试着让它开始工作,但没有成功。
所以循环1应该是这样的:
循环2应该是这样的:
--猫是28显示所有的非粘性柱(所以不包括粘性)
如果有人能帮我,我会很高兴的。已经两天了,我还是不能把它放在一起,>.>
谢谢!
发布于 2014-03-06 13:53:51
找到最新的“粘性邮报”。
<?php
$sticky = get_option( ‘sticky_posts’ );
query_posts( array( ‘cat’ => 28, ‘post__in’ => $sticky, ‘orderby’ => ID, ‘showposts’ => 2 ) );
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>将粘性帖子排除在最近的帖子列表之外
<?php $sticky = get_option(‘sticky_posts’) ;
$post_to_exclude[] = $sticky[0];
$args=array(
‘cat’ => 28,
‘showposts’=>10,
‘post__not_in’=> $post_to_exclude,
);
query_posts($args); ?>
<h2><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a> </h2>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile;?>https://stackoverflow.com/questions/22223593
复制相似问题