우선, 나쁜 영어로 유감스럽게 생각합니다.Wordpress : 한 페이지에 여러 (사용자 정의) 루프를 만드는 방법은 무엇입니까?
내가 원하는 이제<?php $popular_restaurants = new WP_Query(array( 'post_type' => 'restaurant', 'posts_per_page' => 5, 'category_name' => 'restaurants', 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'DESC', 'date_query' => array( array( 'after' => '0', ), ), )); ?> <?php if ($popular_restaurants->have_posts()) : ?> <?php while ($popular_restaurants->have_posts()): $popular_restaurants->the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> (<?php comments_number('Nu stemmen!', '1', '%'); ?>)</li> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php else: ?> <p><?php _e('Sorry, er gaat even iets fout. We hebben niets kunnen vinden.'); ?></p> <?php endif; ?>
, 대신 대부분의 논평 게시물의 루프가 가장 높은 게시물을 투표를 보여줄 수 :
나는 특정 범주에 대한 대부분의 댓글을 달았 게시물을 보여 내 홈페이지에이 코드를 사용 . 어떻게 그렇게 할 수
/* Display likes/unlikes */
function aigoo_get_score() {
$comments = get_comments(array('post_id' => get_the_ID(),));
$likes = array();
$unlikes = array();
foreach($comments as $comment) {
if('unlike' == $comment->comment_content) $unlikes[] = $comment;
else $likes[] = $comment;
}
$likescore = count($likes);
$unlikescore = count($unlikes);
$score = count($likes) - count($unlikes);
$totalvotes = count($likes) + count($unlikes);
return compact('likes', 'unlikes', 'likescore', 'unlikescore', 'score', 'totalvotes');
}
대신의 게시물을 보여주는 :
$counts = aigoo_get_score();
extract($counts); //restores compacted variables
<span>+'.$score.'</span>
이 내 functions.php에 있습니다
일반적으로 나는 포스트 점수를 표시하려면이 코드를 사용 가장 많은 댓글을 달아 내 홈페이지에서 가장 높은 득표 수의 게시물을 표시합니까?
나는 그것이 가능 할지도 모른다. 잘만되면 누군가 나를 도와 줄 수 있습니다.
미리 감사드립니다.
나는 이제 막 빠져 나갔다. 바로 여기 루프의 일부 문제가있다. 'showposts'는 가치가 떨어지고'posts_per_page '여야한다. '고양이'는 민달팽이 나 이름을 제외하고는 카테고리 ID 만 갖고 있지 않습니다. 'order'는 'ASC'또는 'DESC'여야합니다. ['WP_Query'] (http://codex.wordpress.org/Class_Reference/WP_Query) –
당신이 제안한 변경을했습니다. 나는 cat을''cat '=> 1,''로 변경했다. 그게 맞습니까? 그리고''cat '=>'1 '이 아닌''그렇 겠지? 이제 첫 번째 루프와 기본 Wordpress 루프 만 작동하고 다른 두 개의 사용자 정의 루프는 작동하지 않습니다. 그들은 비어 있습니다. – edow
귀하의 제안에 따라 업데이트 된 질문을 참조하십시오. 이제 첫 번째 루프에서 category_name을 다른 카테고리 이름으로 변경하려고했습니다. 그런 다음 게시물을 찾을 수 없다는 오류가 발생합니다. 문제가 있다고 생각합니다. 나는 URI에서 카테고리 슬러그를 시도했기 때문에 category_name은 괜찮을 것이다. – edow