首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >叶-我需要显示更多的标记

叶-我需要显示更多的标记
EN

Stack Overflow用户
提问于 2021-04-30 04:51:19
回答 1查看 141关注 0票数 0

我在一个leaflet.js站点上运行WordPress地图,该站点正在从自定义邮政类型(Metabox.io)中提取位置。我有所有的工作,除了我只有10个标记在地图上。目前,欧洲防止酷刑委员会有24个地点。我在这里发现了关于一个地图上可以有多少标记的问题,而且我肯定不会接近我在堆栈溢出的答案中看到的限制。

,这是我在函数中使用的代码:

代码语言:javascript
复制
    add_action( 'wp_enqueue_scripts', function() {
    if ( is_page( 641 ) ) {
        wp_enqueue_style( 'leaflet', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet.css', [], '1.5.1' );
        wp_enqueue_script( 'leaflet', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet.js', [], '1.5.1', true );
        wp_enqueue_script( 'collab_list', get_theme_file_uri( 'collaborative.js' ), ['jquery', 'leaflet'], '1.0.14', true ); 
    }   
    });
    
         function bww_collaborative_maps() {
          

   $locations = [];
        $query = new WP_Query( [
            'post_type' => 'collaborative',
        ] );
        foreach ( $query->posts as $post ) {
            $location            = rwmb_get_value( 'location', '', $post->ID );
            $location['title']   = $post->post_title;
            $location['address'] = rwmb_get_value( 'collaborative_city_and_state', '', $post->ID );
            $location['icon']    = rwmb_get_value( 'collaborative_map_icon', '', $post->ID );
            $location['url']     = $post->post_name;
            $locations[]         = $location;
        }
        wp_localize_script( 'collab_list', 'Locations', $locations );
    }
add_shortcode('collaborative_map','bww_collaborative_maps');

,下面是我的.js文件中的代码:

代码语言:javascript
复制
( function( document, Locations, L ) {
    // Set map center = first restaurant location.
    var center = [39.043135, -98.148637];

    // Map options.
    var options = {
        center: center,
        zoom: 4
    };

    // Initialize the map.
    var map = L.map( document.querySelector( '#collab_map' ), options );

    // Set tile layer for Open Street Map.
    var tileLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        } );
    map.addLayer( tileLayer );

    // Show marker for each location.
    Locations.forEach( function( location ) {
        // Marker options.
        var options = {
            title: location.title,
            icon: L.icon( {
                iconUrl: location.icon,
                iconSize: [30, 50]
            } )
        };
        var center = L.latLng( location.latitude, location.longitude );
        var marker = L.marker( center, options ).addTo( map );

        // Show name of the restaurant when click on the icon.
        marker.bindPopup( '<span style="font-size:.9rem;"><b>' + location.title + '</b></span><br>' + '<br/><b><a style="font-size:.7rem;" href="' + location.url + '" target="_blank">More Information</a></b>' ).openPopup();
    } );

} )( document, Locations, L );

以下是活动页面:https://ecf.mywp.dev/collaborative-map-test/

我将非常感谢任何想法,如何使这张地图显示所有的标志,而不是仅仅10个。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-30 17:52:33

默认情况下,Wordpress显示查询的10个员额

在您的WP_Query args中,$query'posts_per_page'设置为-1以获取所有帖子:

代码语言:javascript
复制
$query = new WP_Query([
    'post_type' => 'collaborative',
    'posts_per_page' => -1
]);

参考资料:查询/#分页-参数

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67328353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档