php - Eliminate double posts in "other posts from this category" on single post page -
i using following code display posts same category on current post page:
<?php global $post; $categories = get_the_category(); $ceker=false; foreach ($categories $category[0]) { if ($ceker == false){ $ceker=true; ?> <h3 class="naslovostalih">other posts category:</h3> <ul class="clanciostalih"> <?php $args = array( 'numberposts' => 10, 'category' => $category[0] -> term_id, 'exclude' => $post->id ); } $posts = get_posts($args); foreach($posts $pz) { ?> <li> <?php $title = $pz->post_title; $link = get_permalink($pz->id); printf('<a class="linkpost" title="%s" href="%s">%s</a>', $title, $link, $title); echo get_the_post_thumbnail($pz->id, 'thumb-232'); echo '<div id="excerptcu">'; $pz = $pz->post_excerpt; if (strlen($pz) > 160) { $pz = substr($pz,0,strpos($pz,' ',160)); } ; $pz = $pz . ' ...'; echo apply_filters('the_excerpt',$pz); echo '</div>'; ?> <p class="more-link-wrapper2"><?php printf('<a class="read-more button" title="%s" href="%s">opširnije</a>', $title, $link, $title);?></p> </li> <?php } // end foreach ?> <?php } // end if ?> </ul>
it works perfect, problem other posts doubled have kind of output:
post1 (which in cat blizzard , in category europe)
content of post1
other posts category: (should take posts first category , blizzard)
post2
post3
post4
post2
post3
post4
so "other posts" doubled , cant figure out why.
any ideas?
foreach problem. first one. managed solve issue adding break command after closing foreach.
Comments
Post a Comment