Wordpress:显示计划和发布的帖子
我需要一些帮助在wordpress上显示已发布和计划的帖子。 我在我的sidebarleft.php中使用以下代码实现了这一点:Wordpress:显示计划和发布的帖子,wordpress,post,Wordpress,Post,我需要一些帮助在wordpress上显示已发布和计划的帖子。 我在我的sidebarleft.php中使用以下代码实现了这一点: $recentPosts = new WP_Query(); $recentPosts->query('post_status=any&showposts=3'); 但是我还需要在index.php和categories.php中显示它们(在post计数中)。 现在我的帖子显示如下: index.php <?php if (have_posts(
$recentPosts = new WP_Query();
$recentPosts->query('post_status=any&showposts=3');
但是我还需要在index.php和categories.php中显示它们(在post计数中)。
现在我的帖子显示如下:
index.php
<?php if (have_posts()) : ?>
<?php theme_pagination(); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="listeItem">
<h3><?php the_title() ?></h3>
<span class="date"><?php echo the_time('j F Y') ?></span><br />
<span class="lieu"><?php $lieux = get_post_custom_values('lieux'); echo $lieux[0]; ?></span><br />
<a href="<?php the_permalink() ?>">Lire la suite ...</a>
</div>
<?php endwhile; ?>
<?php theme_pagination(); ?>
<?php endif; ?>
和categories.php:
<ul>
<?php wp_list_categories( array('hide_empty'=>'0', 'title_li'=>'', 'show_count'=>'1') ); ?>
</ul>
有人知道干净的方法吗?试试这个:
$recentPosts = new WP_Query(array(
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'desc',
'post_status' => 'any'
));
while ( $recentPosts->have_posts() ) : $recentPosts->the_post();
the_title();
endwhile;
$cats = get_categories(array(
'type' => 'post',
'taxonomy' => 'category',
'orderby' => 'slug',
'asc' => 'asc'
));
foreach ($cats as $cat) {
echo $cat->name;
}
请记住传递正确的参数,好的,谢谢,我按照我的要求显示了帖子,如果它有助于其他迷失的灵魂,这里会进行分页:
code
$cat->count显示已发布文章的数量。我可以在foreach中添加一个WP_查询,但如果可能的话,我想用另一种方式
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$category = get_the_category();
$category_id = $category->cat_ID;
$recentPosts = new WP_Query(array(
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'desc',
'post_status' => array('future', 'publish'),
'category_id'=>$category_id,
'showposts'=>5,
'paged'=>$paged
));
?>
<?php if (have_posts()) : ?>
<?php theme_pagination(); ?>
<?php while ( $recentPosts->have_posts() ) : $recentPosts->the_post();//while (have_posts()) : the_post(); ?>
<div class="listeItem">
<h3><?php the_title() ?></h3>
<span class="date"><?php echo the_time('j F Y') ?></span><br />
<span class="lieu"><?php $lieux = get_post_custom_values('lieux'); echo $lieux[0]; ?></span><br />
<a href="<?php the_permalink() ?>">Lire la suite ...</a>
</div>
<?php endwhile; ?>
<?php theme_pagination(); ?>
<?php endif; ?>
<a href="<?php echo get_permalink(CATEGORIES_ID) ?>"><< Retour</a>
</div>
</div>
foreach ($cats as $cat) {
echo '<li class="cat-item cat-item-'.$cat->ID.'"><a href="'.get_permalink($cat->ID).'" title="Voir tous les articles classés dans '.$cat->name.'">'.$cat->name.'</a> ('.$cat->count.')
</li>';
}
?>