<!--related post by title -->
<?php
// You might need to use wp_reset_query();
// here if you have another query before this one
global $post;
$current_post_type = get_post_type( $post );
// The query arguments
$args = array(
'posts_per_page' => 5,
'order' => 'DESC',
'orderby' => 'rand',
'post_type' => $current_post_type,
'post__not_in' => array( $post->ID )
);
// Create the related query
$rel_query = new WP_Query( $args );
// Check if there is any related posts
if( $rel_query->have_posts() ) :
?>
<h2 id="recent">Related recipes</h2>
<div id="related" class="group">
<ul class="group">
<?php
// The Loop
while ( $rel_query->have_posts() ) :
$rel_query->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
<article>
<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(); ?><br />
<h1 class="entry-title"><?php the_title() ?></h1>
<!--<div class="name-date"><?php the_time('F j, Y'); ?></div>-->
</article>
</a>
</li>
<?php
endwhile;
?>
</ul><!-- .group -->
</div><!-- #related -->
<?php
endif;
// Reset the query
wp_reset_query();
?>
<!--related post by titleEND -->
<!--related_post_END-->
Show related posts by Desc
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.