PHP显示类别中的帖子
我试图为我们的Wordpress站点编写这个滑块,在每个框中显示该类别的第一、第二和第三个最新帖子(在本例中是体育)。无论我如何处理count变量,我都无法显示其他帖子,只有第一篇。这是我正在使用的循环和代码,页面是PHP显示类别中的帖子,php,wordpress,loops,tabs,Php,Wordpress,Loops,Tabs,我试图为我们的Wordpress站点编写这个滑块,在每个框中显示该类别的第一、第二和第三个最新帖子(在本例中是体育)。无论我如何处理count变量,我都无法显示其他帖子,只有第一篇。这是我正在使用的循环和代码,页面是 试试这个。注: 您只需要查询一次,但将帖子数量设置为3。然后,while循环将为您循环这些 $count++将计数从1增加到2到3 <?php $count = 1; $tabbedSportsQuery = new WP_Query(array(
试试这个。注:
- 您只需要查询一次,但将帖子数量设置为3。然后,
循环将为您循环这些while
将计数从1增加到2到3$count++
<?php $count = 1; $tabbedSportsQuery = new WP_Query(array( 'cat' => get_query_var('cat'), 'posts_per_page' => 3 )); while ($tabbedSportsQuery->have_posts()) : $tabbedSportsQuery->the_post(); ?> <div class="t<?php echo $count?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(665,500), array ('class' => 'alignnone')); ?></a> </div> <?php $count++; endwhile; ?> <!-- The tabs --> <ul class="tabs"> <li class="t1"><a class="t1 tab" ><h10><?php echo get_the_title($ID); ?></h10></a> </li> <li class="t2"><a class="t2 tab" ><h10><?php echo get_the_title($ID); ?></h10></a> </li> <li class="t3"><a class="t3 tab" ><h10><?php echo get_the_title($ID); ?></h10></a> </li> </ul>
希望下面的代码能帮助你。。在post中循环,然后为tab打印div,然后尝试将剩余的tab放入一个变量,并在循环结束时打印该变量<?php $count = 1; $tabbedSportsQuery = new WP_Query(array( 'cat' => get_query_var('cat'), 'posts_per_page' => 3 )); $out = ''; while ($tabbedSportsQuery->have_posts()) : $tabbedSportsQuery->the_post(); ?> <div class="t<?php echo $count?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(665,500), array ('class' => 'alignnone')); ?></a> </div> <?php if($count == 1) { $out .= '<ul class="tabs"><li class="t'.$count.'">'; } else { $out .= '<li class="t'.$count.'">'; } $out .= '<a class="t'.$count.' tab"><h10>'.get_the_title($ID).'</h10></a>'; if($count == 3) { $out .= '</li></ul>'; } else { $out .= '</li>'; } ?> <?php $count++; endwhile; print $out; ?>
是否自动将图像包装到锚标记中?不确定。。。你可能可以删除它。这可以用来拉起最近的3个,但它只是在标签外显示它们,我想用其中的哪一部分将特色图片1放入标签1,将特色图片2放入标签2,等等。<?php $count = 1; $tabbedSportsQuery = new WP_Query(array( 'cat' => get_query_var('cat'), 'posts_per_page' => 3 )); $out = ''; while ($tabbedSportsQuery->have_posts()) : $tabbedSportsQuery->the_post(); ?> <div class="t<?php echo $count?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(665,500), array ('class' => 'alignnone')); ?></a> </div> <?php if($count == 1) { $out .= '<ul class="tabs"><li class="t'.$count.'">'; } else { $out .= '<li class="t'.$count.'">'; } $out .= '<a class="t'.$count.' tab"><h10>'.get_the_title($ID).'</h10></a>'; if($count == 3) { $out .= '</li></ul>'; } else { $out .= '</li>'; } ?> <?php $count++; endwhile; print $out; ?>