douwen2158 2012-10-08 03:48
浏览 15

使用PHP Print显示jQuery函数是不好的做法吗?

Need to show a certain piece of jQuery in the header of a wordpress site for settings of a plugin. Is it bad practice to use this the php print method to accomplish it? I'm using the following code:

<?php is_page( 'front-page' ); print 
"<script>
jQuery(function() {

        jQuery('#bannerscollection_kenburns_majestic').bannerscollection_kenburns({
            skin: 'majestic',
            width: 2530,
            height: 1200,
            autoHideNavArrows:true,
            numberOfThumbsPerScreen:16,
            thumbsOnMarginTop:23,
            thumbsWrapperMarginTop: 0,
            initialZoom: 1,
            finalZoom: 1,       
        });     


    });
</script>"
?>

EDIT

I ended up using this, which works great.

<?php is_page( 'front-page' ); wp_enqueue_script( 'kbsettings' ); ?>
  • 写回答

3条回答 默认 最新

  • dongpei2835 2012-10-08 03:51
    关注

    YOu can try like this

    <?php if(is_page( 'front-page' )){ ?>
    <script>
    jQuery(function() {
    
            jQuery('#bannerscollection_kenburns_majestic').bannerscollection_kenburns({
                skin: 'majestic',
                width: 2530,
                height: 1200,
                autoHideNavArrows:true,
                numberOfThumbsPerScreen:16,
                thumbsOnMarginTop:23,
                thumbsWrapperMarginTop: 0,
                initialZoom: 1,
                finalZoom: 1,       
            });     
    
    
        });
    </script>
    
    
    
    <?php } ?>
    
    评论

报告相同问题?