Hallo allen,
Ik heb o.a. deze query op mijn homepage om de top 5 posts weer te geven met de meeste reacties:
Ik heb de volgende functie die de score per post weergeeft:Code:<ul class="most-voted"> <h3>Top activiteiten</h3> <?php $popular_activiteit = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 5, 'category_name' => 'activiteit', 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'DESC', 'date_query' => array( array( 'after' => '0', ), ), ) ); ?> <?php if ( $popular_activiteit->have_posts() ) : ?> <?php while ( $popular_activiteit->have_posts() ): $popular_activiteit->the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> (<?php comments_number( '0', '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; ?> </ul>
En dit hoort daarbij (staat in functions.php):Code:$counts = aigoo_get_score(); extract( $counts ); //restores compacted variables <span>+'.$score.'</span>
Hoe kan ik in de query op de homepage de top 5 posts met de beste score weergeven i.p.v. de posts met de meeste reacties?Code:<?php /* 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'); } ?>
Is dit mogelijk en zo ja, hoe kan ik dit doen?
- WP_Query orderby custom function mogelijk?
-
17-06-2014, 22:33 #1
- Berichten
- 576
- Lid sinds
- 18 Jaar
WP_Query orderby custom function mogelijk?
-
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic