I managed to make this shortcode work and it shows everything as I want. The only issue I am facing right now is that if I use posts_per_page => 1
, it keeps showing all the posts. What can I do to be able to show only the latest post of the category? I tried: posts_per_page => 1
without '', but nothing it's still not working.
Here's the code I am using:
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");
Thank you in advance!