I'm trying to make a function to get 5 post of any category to display in main page of a wordpress site. But in main page, some posts are duplicate with others. Please help me fix it. Thank all!
Here my site: womenonline.us Here my function:
function special_index_hoz($cat){
$posts= array();
$posts=query_posts('showposts=5&cat='.$cat);
echo '<div id="box-top">';
$id=$posts[0]->ID;
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $id
);
$img_src = get_posts($args)[0]->guid;
echo '<img src="'.$img_src.'" width="80" height="100"/>';
echo '<h1><a href="'.get_permalink($id).'">'.wp_trim_words($posts[0]->post_title,10).'</a></h1>';
echo '<p>'.wp_trim_words($posts[0]->post_content,25).'<p>';
echo '</div>';
echo '<div id="box-bottom">
<ul>';
for ($i=1;$i<5;$i++)
{
$id=$posts[$i]->ID;
$args['post_parent']=$id;
$img_src = get_posts($args)[0]->guid;
echo '<a href="'.get_permalink($id).'">
<li><img src="'.$img_src.'" width="80" height="100" />';
echo '<p>'.wp_trim_words($posts[$i]->post_content,6).'</p></li>
</a>';
//echo '<div id="line-bottom"></div>';
}
echo '</ul>
</div>';
}
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum's parser.]