File: /virtual/nagasaki/public_html/shop/wp-content/themes/riffles_ver1.1/related.php
<?php
/**
* @package Riffles
* @link http://www.u-hg.com/
* @author RiffleHatch
* @copyright Copyright (c)2014 RiffleHatch
*/
?>
<?php
global $post;
$cat_now = get_the_category($post->ID);
$nowid = get_the_ID();
$nowcat_id = array();
$item_cat = get_category_by_slug('item');
$item_cat_id = $item_cat->cat_ID;
foreach($cat_now as $cat):
$newid = get_category_by_slug("itemnew");
$newid = $newid->cat_ID;
$recoid = get_category_by_slug("itemreco");
$recoid = $recoid -> cat_ID;
$c_id = $cat -> cat_ID;
$cat_child = get_term_children($c_id, 'category');
if($cat_child != true && $newid != $cat -> cat_ID && $recoid != $cat -> cat_ID){
array_push( $nowcat_id, $cat -> cat_ID);
}
endforeach ;
$related_items = get_posts( array(
'post_type' => 'post',
'category_name' => '$item',
'category__in' => $nowcat_id,
'posts_per_page' => '4',
'exclude' => $nowid,
'orderby' => 'rand'
)); ?>
<?php if ( $related_items ) : ?>
<aside class="related-item row clear">
<h2 class="related">YOU MAY ALSO LIKE...</h2>
<ul class="block itemlist">
<?php foreach( $related_items as $post ): setup_postdata( $post ); ?>
<?php get_template_part('thumbnail-box'); ?>
<?php endforeach; wp_reset_postdata(); ?>
</ul>
</aside>
<?php endif; ?>