Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing my own theme on a website where I use the polldaddy polls & ratings plugin. I've set the ratings to show up on the homepage and that's working with e.g. the twentytwelve theme. However with my own theme, I do see the polldaddy div, but there's nothing in it:

<div class="pd-rating" id="pd_rating_holder_5424010_post_653"></div>

This is my index.php:

<?php
get_header(); // Loads the header.php template. 
if ( have_posts() ) : 
    while ( have_posts() ) : the_post(); ?>
        <div class="post_summary">
            <h2 class="post_title" id="post-<?php the_ID();?>"><a href="<?php the_permalink();?>" rel="bookmark" title="<?php the_title();?>"><?php the_title();?></a></h2>
            <?php the_excerpt(); ?>
        </div>
    <?php endwhile; 
else : 
    get_template_part( 'loop-error' ); // Loads the loop-error.php template. 
endif; 
get_footer(); // Loads the footer.php template. 
?>

The header.php and footer.php just make a basic box model.

Then, the relevant codes of the polldaddy plugin, ratings.php (there is a filter addition on the bottom):

<?php
function polldaddy_show_rating_comments( $content ) {
    if ( !is_feed() && !defined( 'DOING_AJAX' ) ) {
        global $comment;
        global $post;

        if ( isset( $comment->comment_ID ) && $comment->comment_ID > 0 ) {
            $unique_id  = '';
            $title      = '';
            $permalink  = '';
            $html       = '';
            $rating_pos = 0;

            if ( (int) get_option( 'pd-rating-comments' ) > 0 ) {
                $rating_id = (int) get_option( 'pd-rating-comments' );
                $unique_id = 'wp-comment-' . $comment->comment_ID;
                $rating_pos = (int) get_option( 'pd-rating-comments-pos' );
                $title = mb_substr( preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $comment->comment_content ), 0, 195 ) . '…';
                $permalink = get_permalink( $post->ID ) . '#comment-' . $comment->comment_ID;
                $html = polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, '_comm_' . $comment->comment_ID );

                if ( $rating_pos == 0 )
                    $content = $html . '<br/>' . $content;
                else
                    $content .= $html;
            }
        }
    }
    return $content;
}

function polldaddy_show_rating( $content ) {
    global $wp_current_filter;
    if ( !in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
        if ( !is_feed() && !is_attachment() ) {
            if ( is_single() || is_page() || is_home() || is_archive() || is_search() || is_category() ) {
                $html = polldaddy_get_rating_html( 'check-options' );

                if ( !empty( $html ) ) {
                    $rating_pos = 0;

                    if ( is_page() ) {
                        $rating_pos = (int) get_option( 'pd-rating-pages-pos' );
                    } elseif ( is_home() || is_archive() || is_search() || is_category() ) {
                        $rating_pos = (int) get_option( 'pd-rating-posts-index-pos' );
                    } else {
                        $rating_pos = (int) get_option( 'pd-rating-posts-pos' );
                    }

                    if ( $rating_pos == 0 )
                        $content = $html . '<br/>' . $content;
                    else
                        $content .= $html;
                }
            }
        }
    }
    return $content;
}

function polldaddy_get_rating_html( $condition = '' ) {
    global $post;
    $html = '';

    if ( $post->ID > 0 ) {
        $unique_id = '';
        $title = '';
        $permalink = '';
        $rating_id = 0;
        $item_id = '';
        $exclude_posts = explode( ',', get_option( 'pd-rating-exclude-post-ids' ) );
        $exclude_pages = explode( ',', get_option( 'pd-rating-exclude-page-ids' ) );

        if ( is_page() ) {
            if ( !in_array( $post->ID, $exclude_pages ) ) {
                $unique_id = 'wp-page-' . $post->ID;
                $item_id =  '_page_' . $post->ID;
                if ( $condition == 'check-options' ) {
                    if ( (int) get_option( 'pd-rating-pages' ) > 0 ) {
                        $rating_id = (int) get_option( 'pd-rating-pages-id' );
                    }
                } else {
                    $rating_id = (int) get_option( 'pd-rating-pages-id' );
                }
            }
        } elseif ( !in_array( $post->ID, $exclude_posts ) ) {
            $unique_id = 'wp-post-' . $post->ID;
            $item_id =  '_post_' . $post->ID;
            if ( is_home() || is_archive() || is_search() || is_category() ) {
                if ( $condition == 'check-options' ) {
                    if ( (int) get_option( 'pd-rating-posts-index' ) > 0 ) {
                        $rating_id = (int) get_option( 'pd-rating-posts-id' );
                    }
                } else {
                    $rating_id = (int) get_option( 'pd-rating-posts-id' );
                }
            } else {
                if ( $condition == 'check-options' ) {
                    if ( (int) get_option( 'pd-rating-posts' ) > 0 ) {
                        $rating_id = (int) get_option( 'pd-rating-posts-id' );
                    }
                } else {
                    $rating_id = (int) get_option( 'pd-rating-posts-id' );
                }
            }
        }

        if ( $rating_id > 0 ) {
            $rating_title_filter = get_option( 'pd-rating-title-filter' );

            if ( $rating_title_filter === false )
                $title = apply_filters( 'the_title', $post->post_title, $post->ID, '' );
            elseif ( strlen( $rating_title_filter ) > 0 )
                $title = apply_filters( $rating_title_filter, $post->post_title, $post->ID, '' );
            else
                $title = $post->post_title;

            $permalink = get_permalink( $post->ID );
            $html = polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, $item_id );
        }
    }
    return $html;
}

/**
 * Construct a Polldaddy target div for a given rating_id and optional item_id
 * Define a Polldaddy ratings variable for a given rating_id and optional item_id
 *
 * @param int     $rating_id
 * @param string  $unique_id
 * @param string  $title     Post title
 * @param string  $permalink Post permalink
 * @param string  $item_id
 * @return HTML snippet with a ratings container and a related JS block defining a new variable
 */
function polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, $item_id = '' ) {   
    $html = sprintf( '[polldaddy rating="%d" item_id="%s" unique_id="%s" title="%s" permalink="%s"]', absint( $rating_id ), polldaddy_sanitize_shortcode( $item_id ), polldaddy_sanitize_shortcode( $unique_id ), polldaddy_sanitize_shortcode( $title ), polldaddy_sanitize_shortcode( $permalink ) );
    return do_shortcode( $html );
}

function polldaddy_sanitize_shortcode( $text ) {
    $text = preg_replace( array( '/\[/', '/\]/' ), array( '&#91;', '&#93;' ), $text );
    return esc_attr( $text );
}

if ( (int) get_option( 'pd-rating-pages' ) > 0 || (int) get_option( 'pd-rating-posts-index' ) > 0 || (int) get_option( 'pd-rating-posts' ) > 0 ) {
    add_filter( 'the_content', 'polldaddy_show_rating', 5 );
    add_filter( 'the_excerpt', 'polldaddy_show_rating' );
}

add_filter( 'comment_text', 'polldaddy_show_rating_comments', 50 );
?>

How can I make the ratings show up right?

share|improve this question
    
How do you add the extra code? –  toscho Jan 27 '13 at 10:48
    
What extra code? The polldaddy div is just included by the plugin, I guess..? I didn't do anything about it. I think it's included in the_excerpt()? Or isn't that what you mean? –  Camil Staps Jan 27 '13 at 10:49
    
Yes, the exact hook and its callback function are the important bits here. –  toscho Jan 27 '13 at 10:52
    
Sorry, I can't follow you. Should I include another function to make the rating appear? If so, what function? –  Camil Staps Jan 27 '13 at 10:54
1  
Does your footer.php include a call to <?php wp_footer(); ?>? If not, see @CamilStaps answer below. –  Chip Bennett Jan 27 '13 at 13:52
show 2 more comments

2 Answers

up vote 1 down vote accepted

The wp_footer() function has to be called in footer.php, just before closing the page with </body>.

share|improve this answer
1  
I'm going to guess that this is the problem. We know the Plugin filter callback is working, because it is injecting the PollDaddy DIV. But PollDaddy's scripts are not firing - probably because they're not getting output. And if they're not getting output, it is probably because the Theme doesn't call wp_footer() in the footer. Note: add <?php wp_footer(); ?> immediately before the closing HTML </body> tag. –  Chip Bennett Jan 27 '13 at 13:48
    
I think that was the problem, yes. I edited my answer accordingly :-) –  Camil Staps Jan 27 '13 at 13:51
add comment

Sample of wp_footer()

<?php wp_footer(); ?>     

Also check wordpress codex

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.