Skip to content

Instantly share code, notes, and snippets.

@haicu
Created November 13, 2016 14:09
Show Gist options
  • Save haicu/f26f793859baa95f0835eec7efbda836 to your computer and use it in GitHub Desktop.
Save haicu/f26f793859baa95f0835eec7efbda836 to your computer and use it in GitHub Desktop.
TTB Sidebar showing 3 posts
<?php
/**
* The sidebar containing the main widget area.
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package haicu17
*/
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php // Query to show latest 3 posts
// arguments for query
$args = array(
'post_type' => 'post',
'posts_per_page' => 3
);
// new query for posts
$my_query = new WP_query ( $args );
if ( $my_query->have_posts() ) { ?>
<h2>Recent nieuws</h2>
<ul class="news-listing">
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;
rewind_posts(); ?>
</ul>
<?php } ?>
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment