Skip to content

Instantly share code, notes, and snippets.

@daveloodts
Created August 23, 2016 08:10
Show Gist options
  • Save daveloodts/d053eab1a9c9e169969cde8238278bc3 to your computer and use it in GitHub Desktop.
Save daveloodts/d053eab1a9c9e169969cde8238278bc3 to your computer and use it in GitHub Desktop.
shortcode latest posts
/* shortcode voor homeberichten */
add_shortcode( 'homeposts', 'list_homeposts' );
function list_homeposts( $atts ) {
ob_start();
wp_reset_postdata();
extract( shortcode_atts( array (
'type' => 'post',
'posts' => -1,
'category' => '',
), $atts ) );
$options = array(
'post_type' => $type,
'posts_per_page' => 4
);
$query = new WP_Query( $options );
if ( $query->have_posts() ) { ?>
<ul class="homeposts">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;
?>
</ul>
<a class="bttnrubriek eigbttn text-center" href="<?php echo site_url(); ?>/blog">Meer lezen</a>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment