/** * widget - Standard function called to display widget contents * * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget */ function widget($args, $instance) { extract($args); if (is_single() || is_page()) { global $post; $post_type = $instance['post_type'] == 'all' ? null : $instance['post_type']; $related_posts = MRP_get_related_posts($post->ID, 0, 0, $post_type); if ($related_posts) { echo $before_widget; echo "<div id=\"related-posts-widget\">\n"; echo "<h3 class=\"widget-title\">" . $instance['title'] . "</h3>\n"; echo "<ul>\n"; foreach ($related_posts as $related_post_id => $related_post_title) { echo "<li><a href=\"" . get_permalink($related_post_id) . "\">" . $related_post_title . "</a></li>\n"; } echo "</ul></div>"; echo $after_widget; } else { if (!$instance['hide_if_empty']) { echo $before_widget; echo "<div id=\"related-posts-widget\">\n"; echo "<h3 class=\"widget-title\">" . $instance['title'] . "</h3>\n"; echo "<p>" . $instance['text_if_empty'] . "</p>\n"; echo "</div>\n"; echo $after_widget; } } } }
/** * widget - Standard function called to display widget contents * * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget */ function widget($args, $instance) { extract($args); if (is_single() || is_page()) { global $post; $post_type = $instance['post_type'] == 'all' ? null : $instance['post_type']; $related_posts = MRP_get_related_posts($post->ID, 0, 0, $post_type); if ($related_posts) { echo $before_widget; echo $before_title; echo $instance['title']; echo $after_title; echo "<ul>\n"; foreach ($related_posts as $related_post_id => $related_post_title) { echo "<li>"; if ($instance['show_thumbnail'] && has_post_thumbnail($related_post_id)) { echo "<a href=\"" . get_permalink($related_post_id) . "\">"; echo get_the_post_thumbnail($related_post_id, $instance['thumbnail_size']); echo "</a>"; } echo "<a href=\"" . get_permalink($related_post_id) . "\">" . $related_post_title . "</a>"; echo "</li>\n"; } echo "</ul>"; echo $after_widget; } else { if (!$instance['hide_if_empty']) { echo $before_widget; echo $before_title; echo $instance['title']; echo $after_title; echo "<p>" . $instance['text_if_empty'] . "</p>\n"; echo $after_widget; } } } }
<article class="entryPiece"> <header class="entryHeader"> <h1><?php the_title(); ?> </h1> <?php $healthCat = get_category_by_slug('health'); $cosmeCat = get_category_by_slug('cosme'); $troubleCat = get_category_by_slug('trouble'); $componentCat = get_category_by_slug('component'); global $post; $related_posts = MRP_get_related_posts($post->ID, 1, 0); if ($related_posts) { ?> <section class="recommendList"> <h1>関連のおすすめ記事</h1> <div class="inner"> <ul> <?php foreach ($related_posts as $item) { ?> <li><a href="<?php echo get_permalink($item->ID); ?> " style="height: 239px;"> <?php if (date("Y/m/d") == date("Y/m/d", strtotime($item->post_date))) { echo '<span class="entryMark">new</span>'; } ?>
/** * MRP_get_related_posts_html - Generate the related posts HTML for a post and return it as a string * * @param int $post_id - The id of the post * @param bool $hide_unpublished - When false drafts will be included * @param string $post_type - The post type of the related posts to return i.e. post, page, or any custom post types * When null all post types will be returned */ function MRP_get_related_posts_html($post_id, $hide_unpublished = true, $post_type = null) { # Get plugin settings $options = get_option("MRP_options"); # Get the supported post types (selected in plugin settings) $supported_post_types = MRP_get_supported_post_types(); if (!$supported_post_types) { return false; } $related_posts = array(); # If only related posts for specified post type are needed if (isset($post_type)) { $related_posts[$post_type] = MRP_get_related_posts($post_id, true, $hide_unpublished, $post_type); } else { # First get the entire set of related posts for all post types $all_related_posts = MRP_get_related_posts($post_id, true, $hide_unpublished, null); # If related posts should be displayed as one list if ($options['combine_post_types'] == 1) { $related_posts['MRP_all'] = $all_related_posts; } else { if ($all_related_posts) { foreach ($all_related_posts as $related_post) { $related_posts[$related_post->post_type][] = $related_post; } } } } # Start HTML output $output = "<div class=\"related-posts\">\n"; # Loop through different post types foreach ($related_posts as $post_type => $post_type_related_posts) { # This filters %posttype% from the title $title = MRP_get_title(__($options['title'], 'microkids-related-posts'), $post_type); if (count($post_type_related_posts)) { $output .= "<div id=\"related-posts-{$post_type}\" class=\"related-posts-type\">\n"; # Create the title with the selected HTML header $output .= "<" . $options['header_element'] . ">" . $title . "</" . $options['header_element'] . ">\n"; $output .= "<ul>\n"; # Add related posts foreach ($post_type_related_posts as $related_post) { $output .= "<li>"; if ($options['show_thumbnails'] && has_post_thumbnail($related_post->ID)) { $output .= "<a href=\"" . get_permalink($related_post->ID) . "\">"; $output .= get_the_post_thumbnail($related_post->ID, $options['thumbnail_size']); $output .= "</a>"; } $output .= "<a href=\"" . get_permalink($related_post->ID) . "\">" . $related_post->post_title . "</a>"; $output .= "</li>\n"; } $output .= "</ul></div>\n"; } else { if (!$options['hide_if_empty']) { $output .= "<div id=\"related-posts-{$post_type}\" class=\"related-posts-type\">\n"; $output .= "<" . $options['header_element'] . ">" . $title . "</" . $options['header_element'] . ">\n"; $output .= "<p>" . $options['text_if_empty'] . "</p>\n"; $output .= "</div>"; } else { # Show nothing return ""; } } } $output .= "</div>"; return $output; }
// Get similar posts // Get product's main category $main_category = get_post_main_category_slug($post); $parent_slug = $main_category; // Get product dimensions from meta fields / filters $dimension = get_product_dimension($post, $main_category); if ($dimension != '') { $articles = get_similar_posts($post, $main_category, $dimension); $title = 'Alte variante pt. ' . $dimension; $link = null; $id = 'variations'; include '_articles.php'; } // If there are no similar posts then get related posts if (empty($articles)) { $articles = MRP_get_related_posts($post_id, true); $title = 'Articole similare'; $link = null; $id = 'related'; include '_articles.php'; } // Get brands for this category include '_brands.php'; } ?> <?php if (is_page()) { ?> <nav id="sidebar">