private function get_related_posts_content() { $related_posts = ep_more_like_this(get_the_ID(), null); $rp_content = ' <hr class="above-related-posts" /><div class="related-posts-head">'; $rp_content .= __('Related Posts', 'elasticpress'); $rp_content .= '</div>'; if ($related_posts['found_posts'] > 0) { $rp_content .= '<ul class="ep4wpe-related-posts">'; $post_limit = get_site_option(namespace\POST_COUNT_FIELD, namespace\MAX_RELATED_POSTS); for ($i = 0; $i < $post_limit; $i++) { $rp = $related_posts['posts'][$i]; $rp_date = mysql2date('F j, Y', $rp['post_date']); $rp_content .= <<<RELATEDPOST <li class="related-post-item"> <a href="{$rp['permalink']}" rel="bookmark" title="{$rp['post_title']}" class="related-post-link" >{$rp['post_title']}</a> <span class="related-post-date">{$rp_date}</span> </li> RELATEDPOST; } $rp_content .= '</ul>'; } else { $rp_content .= '<span class="no-related-posts">' . __('No related posts found.', 'elasticpress') . '</span>'; } return $rp_content; }
/** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { if (!is_single()) { return; } global $post; $post_id = $post->ID; $related_posts = ep_more_like_this($post_id, null); echo $args['before_widget']; echo $args['before_title'] . __('Related posts', 'elasticpress') . $args['after_title']; if ($related_posts['found_posts'] > 0) { echo '<ul class="ep4wpe-related-posts">'; $count = 0; foreach ($related_posts['posts'] as $post) { ?> <li> <a href="<?php echo $post['permalink']; ?> " rel="bookmark" title="<?php echo $post['post_title']; ?> "><?php echo $post['post_title']; ?> </a> <span class="post-date"><?php echo mysql2date('F j, Y', $post['post_date']); ?> </span> </li> <?php $count++; if ($count >= $instance[namespace\POST_COUNT_FIELD]) { break; } } echo '</ul>'; } else { echo '<span>' . __('No related posts found.', 'elasticpress') . '</span>'; } echo $args['after_widget']; }