Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function related_posts() {
- global $post; //this is used by the loop down
- if (!$this->is_single) {
- return;
- }
- if (td_util::get_option('tds_similar_articles') == 'hide') {
- return;
- }
- if (td_util::get_option('tds_similar_articles_count') == '') {
- if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
- $tds_similar_articles_count = 3;
- } else {
- $tds_similar_articles_count = 2;
- }
- } else {
- $tds_similar_articles_count = td_util::get_option('tds_similar_articles_count');
- }
- $buffy = '';
- $buffy .= '<div class="art-img-text-down similar-articles">';
- $args = array();
- switch (td_util::get_option('tds_similar_articles_type')) {
- //by tag
- case 'by_tag':
- $tags = wp_get_post_tags($this->post->ID);
- if ($tags) {
- $taglist = array();
- for ($i = 0; $i <= 4; $i++) {
- if (!empty($tags[$i])) {
- $taglist[] = $tags[$i]->term_id;
- } else {
- break;
- }
- }
- $args = array(
- 'tag__in' => $taglist,
- 'post__not_in' => array($this->post->ID),
- 'showposts' => $tds_similar_articles_count,
- 'ignore_sticky_posts' => 1
- );
- }
- break;
- //by title
- case 'by_auth':
- $args = array(
- 'author' => $this->post->post_author,
- 'post__not_in' => array($this->post->ID),
- 'showposts' => $tds_similar_articles_count,
- 'ignore_sticky_posts' => 1
- );
- break;
- //by category
- default:
- $args = array(
- 'category__in' => wp_get_post_categories($this->post->ID),
- 'post__not_in' => array($this->post->ID),
- 'showposts' => $tds_similar_articles_count,
- 'ignore_sticky_posts' => 1
- );
- break;
- }
- if (!empty($args)) {
- //do the query
- $post_categories = wp_get_post_categories($this->post->ID);
- $cats = array();
- foreach($post_categories as $c){
- $cat = get_category( $c );
- $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
- }
- $my_query = new WP_Query($args);
- if ($my_query->have_posts()) {
- $buffy .= '<h4 class="block-title"><span>' . __td('SIMILAR ARTICLES') . ' - ' . $cat->name . '</span></h4>';
- $td_template_layout = new td_template_layout(''); //invalid sidebar position, it will default to 2 + 1
- if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
- $td_template_layout->set_columns(3);
- } else {
- $td_template_layout->set_columns(2);
- }
- while ($my_query->have_posts()) : $my_query->the_post();
- $buffy .= $td_template_layout->layout_open_element();
- $td_module_6 = new td_module_6($post);
- $buffy .= $td_module_6->render();
- $buffy .= $td_template_layout->layout_close_element();
- $td_template_layout->layout_next();
- endwhile;
- $buffy .= $td_template_layout->close_all_tags();
- }
- }
- $buffy .= '</div>';
- wp_reset_query();
- return $buffy;
- }
Advertisement
Add Comment
Please, Sign In to add comment