0

On Likebtn-plugin homepage ([https://likebtn.com/en/wordpress-like-button-plugin#sort_posts_by_likes][1]) they give this code to input in a template file, e.g. index.php, archives.php, page.php, such that the posts are sorted based on the number of likes. I have input the code in the archives.php and the content is sorted correctly when I click on a category. But I also want to use the function in my pages so I tried to enter the code in my page-tmpl.php file but it does not seem to be working. Everything in the page just disappears. What am I doing wrong?

The page-tmpl.php file looks like this with the Likebtn-code incerted at the top:

<?php
$args  = array(
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'meta_query' => array(
        'relation' => 'OR',
         array(
            'key' => 'Likes',
            'compare' => 'NOT EXISTS',
            'type' => 'numeric'
         ),
         array(
            'key' => 'Likes',
            'compare' => 'EXISTS',
            'type' => 'numeric'
         )
     )
);
$args = array_merge( $args , $wp_query->query );
query_posts($args);?> 
>
<?php if ( hu_is_checked( 'singular-page-featured-image' ) ) { hu_get_template_part('parts/page-image'); } ?>

<div class="entry themeform">
  <?php the_content(); ?>
  <nav class="pagination group">
    <?php
      //Checks for and uses wp_pagenavi to display page navigation for multi-page posts.
      if ( function_exists('wp_pagenavi') )
        wp_pagenavi( array( 'type' => 'multipart' ) );
      else
        wp_link_pages(array('before'=>'<div class="post-pages">'.__('Pages:','hueman'),'after'=>'</div>'));
    ?>
  </nav><!--/.pagination-->
  <div class="clear"></div>
</div><!--/.entry-->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.