我需要一些帮助才能在wordpress上显示已发布和计划发布的帖子。 我设法用我的sidebarleft.php用这段代码做到了:
$recentPosts = new WP_Query();
$recentPosts->query('post_status=any&showposts=3');
但我还需要在index.php和categories.php中显示它们(在帖子计数中)。 现在我的帖子显示如下: 的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>
有谁知道干净的方法吗?
答案 0 :(得分:0)
试试这个:
$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;
}
请记住传递正确的参数
答案 1 :(得分:0)
好的,谢谢,我设法显示了我想要的帖子,如果这有助于另一个失去的灵魂,那么它会分页:
code
$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>
/code
但对于categories.php,我可以显示正确的帖子数量(计划和发布)
code
“后”,
'taxonomy'=&gt; '类别',
'orderby'=&gt; “塞”,
'asc'=&gt; 'ASC'
));
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>';
}
?>
$ cat-&gt; count显示已发布帖子的数量。我可以在foreach中添加一个WP_Query,但如果可能的话,我想以另一种方式进行。