我设法使这个短代码工作,它显示了我想要的一切。我现在面临的唯一问题是如果我使用posts_per_page => 1
, 它不断显示所有帖子。如何才能只显示该类别的最新帖子?我试过:posts_per_page => 1
没有“”,但什么都没有,它仍然不工作。
以下是我使用的代码:
function Arte($atts, $content = null) {
extract(
shortcode_atts(
array(
"pagination" => \'false\',
"query" => \'\',
"category" => \'arte\',
"posts_per_page" => \'1\',
),
$atts
)
);
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
if ( $pagination == \'true\' ) {
$query .= \'&paged=\'.$paged;
}
if (!empty($category)) {
$query .= \'&category_name=\'.$category;
}
if (!empty($query)) {
$query .= $query;
}
$wp_query->query($query);
ob_start();
?>
<ul class="loop">
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<div class="cont-overlay"><?php the_post_thumbnail(
\'ilRaccoglitore_single\', array(
\'class\' => \'img-thumb-sidebar\',
\'alt\' => get_the_title(), )); ?>
<div class="overlay"></div>
</div>
<h5 class="title-sidebar"><?php echo the_title(); ?></h5>
</a></li>
<li class="excerpt-sidebar"><?php the_excerpt(); ?></li>
<?php endwhile; ?>
</ul>
<?php if ($pagination == \'true\') { ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link(\'« Previous\') ?></div>
<div class="alignright"><?php next_posts_link(\'More »\') ?></div>
</div>
<?php } ?>
<?php
$wp_query = null; $wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("arte", "Arte");
提前感谢您!