Title: Where to insert php functions?
Last modified: August 21, 2016

---

# Where to insert php functions?

 *  Resolved [BongSong](https://wordpress.org/support/users/bongsong/)
 * (@bongsong)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/)
 * On the Faq section it has information about Displaying Most Rated Post and other
   display options.
 * Apologies if this is a stupid question but it doesn’t specifically state where
   exactly should these php functions codes go?
 * Inside the post when you’re editing it or inside the function.php file.
 * I currently put [ratings] in my posts to display the voting options and results.
 * I want to display the top three most rated underneath for purposes of tempting
   them to click on those posts to peek at them. (That is if it provides a link 
   to those top three posts as well)
 * It would look something like:
 * Here’s what others are voting on!
 * [top three posts shortcode here]
 * I realize there is a widget but I don’t want to go this route.
 * Thanks for any help in advance.
 * James
 * [https://wordpress.org/plugins/wp-postratings/](https://wordpress.org/plugins/wp-postratings/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850520)
 * The PHP functions goes within the loop [https://codex.wordpress.org/The_Loop](https://codex.wordpress.org/The_Loop)
   because it really differs from theme to theme, I cannt be explict. You have to
   consult your theme author.
 * If you want to put the most rated post you have to put it in the single post 
   template and use the PHP function and I already answered it in your [http://wordpress.org/support/topic/most-rated-shortcode?replies=2](http://wordpress.org/support/topic/most-rated-shortcode?replies=2).
   There is no shortcode for it.
 *  Thread Starter [BongSong](https://wordpress.org/support/users/bongsong/)
 * (@bongsong)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850521)
 * Lester,
 * First of all thanks for your assistance. And sorry for the duplicate posts earlier.
   Had an issue with my browser.
 * I am frankly confused. I am looking for the php code:
 * <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 * in the single.php file. It doesn’t exist in index.php either as instructed on
   the faq.
 * I am using wp 3.1.2 and using the twentyten theme.
 * I understand that once I find this:
 * <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 * I need to paste the php code as instructed on the faq for inserting most rated
   posts.
 * I understand that I could do this within a widget but this is not an option I
   want to use.
 * I’m hoping to insert it directly after the [ratings] shortcode in the post.
 * More guidance please?
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850526)
 * For TwentyTen, it is in loop-single.php [https://themes.trac.wordpress.org/browser/twentyten/1.6/loop-single.php](https://themes.trac.wordpress.org/browser/twentyten/1.6/loop-single.php)
 *  Thread Starter [BongSong](https://wordpress.org/support/users/bongsong/)
 * (@bongsong)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850537)
 * Lester,
 * Thanks, that works.
 * I have updated my single-loop.php by placing the php function for highest rated
   posts.
 * However this line:
 * Default: get_most_rated(‘post’, 0, 3)
 * is being echoed out into the post. I can’t understand why and I assume I need
   that part of the code so it knows about the 0 and 3 value on displaying the posts.
 * I copied exactly as it was in your faq page.
 * What am I doing wrong? Paste the code I need to use please?
 * Thanks.
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850543)
 * Try this as stated in the FAQ “Use” block
 *     ```
       <?php if (function_exists('get_most_rated')): ?>
           <ul>
               <?php get_most_rated('post', 0, 3); ?>
           </ul>
       <?php endif; ?>
       ```
   
 *  Thread Starter [BongSong](https://wordpress.org/support/users/bongsong/)
 * (@bongsong)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850570)
 * Lester,
 * Thanks. This works.
 * One final question if I could…
 * How could I add a title to that block of code you provided so it gives the top
   three highest scored posts a title?
 * Something like “Check out these other posts and vote!”
    Then underneath are the
   three posts
 * Thanks for your patience and help. 🙂
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850577)
 * Just add `<?php echo 'Check out these other posts and vote!'; ?>` before that
   block of code?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Where to insert php functions?’ is closed to new replies.

 * ![](https://ps.w.org/wp-postratings/assets/icon.svg?rev=978014)
 * [WP-PostRatings](https://wordpress.org/plugins/wp-postratings/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-postratings/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-postratings/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-postratings/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-postratings/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-postratings/reviews/)

## Tags

 * [vote](https://wordpress.org/support/topic-tag/vote/)

 * 7 replies
 * 2 participants
 * Last reply from: [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/where-to-insert-php-functions/#post-4850577)
 * Status: resolved