Ben ana sayfa içeriğine önce kodu görüntüleyen küçük bir kenar çubuğu var. Ben son mesaj ve yorumlar çekmek için bu (janky) işlevini yazdı. Harika çalışıyor, ancak, onun bütün sayfaları ile vidalama ve tüm bunların üzerine koyarak mesajları. Nasıl yani benim bütün sayfalar doğru içeriğini görüntülemek sorgu geri sarmak veya bir yenisini yapmak / sıfırlarım?
<?php rewind_posts(); ?> ve <?php wp_reset_query(); ?> Benim için hile yapıyor öyle
İşte benim sorgu:
$comments = get_comments('number=10');
$posts = get_posts('posts_per_page=10&category=6');
$most_recent = array();
foreach ($comments as $comment)
$most_recent[strtotime($comment->comment_date_gmt)] = $comment;
foreach ($posts as $post)
$most_recent[strtotime($post->post_date_gmt)] = $post;
unset($comments, $posts);
krsort($most_recent);
$most_recent = array_slice($most_recent, 0, 10);
foreach ($most_recent as $post_or_comment) {
$is_post = isset($post_or_comment->post_date_gmt);
$comment_id = $post_or_comment->comment_ID;
$post_id = $post_or_comment->ID;
$comment_post_id = $post_or_comment->comment_post_ID;
if ($is_post == 1)
{ ?> <li><a href="<?php echo get_permalink($post_id); ?>"><?php echo $post_or_comment->post_title; ?></a><span class="tag"><?php echo the_category($post_id); ?></span></li><?php }
else
{ ?><li> <a href="<?php echo get_permalink($comment_post_id); ?>"><?php echo get_the_title($comment_post_id); ?></a><span class="tag">Comment</span></li><?php }
// output comments and posts
}
output comments and posts }