开发者

index content disappears in Wordpress

I'm making a plugin, and this function includes map at the end of the single post. Problem is, content disappears on index. Can you tell me how should I recode this function so it wouldnt affect content on index?

function svmpm_display_svm( $content ) { 
        global $post, $options;

        $options = get_option('svmpm_options');
        $metaname = $options['metaname'];
        $sheight = $options['hght'];
        $swidth = $options['wdth'];
        $svmpmaddress = get_post_meta($post->ID, $metaname, true);

        if(is_single()) {

            $acontent = '<div onunload="GUnload()"> 
                        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" type="text/javascript"></script>
                        <div id="map_canvas" style="width: ';
            $acontent .= $swidth;
            $acontent .= '; height: ';
            $acontent .= $sheight;
            $acontent .= '"></div> 

                        <script type="text/javascript"> 
                        var myAddress = ';
            $acontent .= '\'';
            $acontent .= $svmpmaddress;
            $acontent .= '\';';
            $acontent .= 'var userLocation = myAddress;

                        if (GBrowserIsCompatible()) {
                           var geocoder = new GClientGeocoder();
                           geocoder.getLocations(userLocation, function (locations) {         
                              if (locations.Placemark)
                              {
                                 var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
                                 var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
                                 var east  = locations.Placemark[0].ExtendedData.LatLonBox.east;
                                 var west  = locations.Placemark[0].ExtendedData.LatLonBox.west;

                                 var bounds = new GLatLngBounds(new GLatLng(south, west), 
                                                                new GLatLng(north, east));

                                 new G开发者_StackOverflow中文版StreetviewPanorama(document.getElementById("map_canvas"), 
                                                         { latlng: bounds.getCenter() });
                              }
                           });
                        }
                        </script> 
                        </div>';
        if ($options['pbelow'] == 1) { //Only below p
         return $content . $acontent;
        };


        } ;
};
add_filter('the_content', 'svmpm_display_svm');


Try putting

if (! is_single()) return $content;

at the top of your function. It doesn't look like you ever return the $content outside of your if (is_single()) block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜