Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions inc/widget-custom-post-type-recent-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,34 @@ public function widget( $args, $instance ) {
'ignore_sticky_posts' => true,
) ) );

$possible_templates = array(
'content-'.$this->alt_option_name.'-'.$posttype.'.php',
'content-'.$this->alt_option_name.'.php'
);
$template_found = false;

foreach( $possible_templates as $a_possible_template ){
if( locate_template( $a_possible_template ) ){
$template_found = locate_template( $a_possible_template );
}
}

if ( $r->have_posts() ) : ?>
<?php echo $args['before_widget']; ?>
<?php if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
} ?>
<ul>
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<?php if( ! $template_found ) : ?>
<li><a href="<?php the_permalink() ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
<?php if ( $show_date ) : ?>
<span class="post-date"><?php echo get_the_date(); ?></span>
<?php endif; ?>
</li>
<?php else : ?>
<?php include( $template_found ); ?>
<?php endif; ?>
<?php endwhile; ?>
</ul>
<?php echo $args['after_widget']; ?>
Expand Down