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.

Below is a code I use to display post views. It is integrated with an options panel which allows users to choose whether to display it.

I would like to integrate the div class .postviews directly into the code. I would like to do this because it incorporates a blue background and if the views are not displayed, that blue background still gets displayed.

<div class="postviews">
<?php $options = get_option('to_post_views');
if( $options == 'Yes' ) { echo getPostViews( get_the_ID() );
} ?>
</div>

If you view this page, views are currently being displayed where it says "58 views."

share|improve this question
    
Even though answered, given the nature of the actual topic of the question, I'd still say this ought to be closed as off-topic. –  Johannes Pille Apr 2 '13 at 21:02
    
I disagree, I think it should be closed because it's not really a question, and its not obvious what is needed to answer it. –  Tom J Nowell Apr 2 '13 at 21:33
    
This is basically just a PHP question. –  vancoder Apr 2 '13 at 21:36
    
Yeah, to hell with PHP! –  AndrettiMilas Apr 3 '13 at 14:04
add comment

closed as off topic by Johannes Pille, s_ha_dum, Tom J Nowell, brasofilo, Wyck Apr 3 '13 at 4:09

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Apart from the fact, that the conditional is based on a WordPress option, this is pure PHP, but anyhoo:

<?php
    $show_views = get_option( 'to_post_views' );

    if ( 'Yes' === $show_views ) {
        echo '<div class="postviews">' .
            getPostViews( get_the_ID() ) .
            '</div>';
    }
?>
share|improve this answer
add comment

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