我使用Wordpress,我正在循环我的文章和每篇文章我创建一个案例并添加一个类。案例名称和类名取自每个帖子附加的自定义字段。在php中循环帖子并添加一个类到多边形(小册子)
但是,如果我有两篇与某个国家相关的文章,例如澳大利亚,该循环会说“为这个班级找到一篇澳大利亚文章,设置一个案例并添加其课程”。但是,如果我有两篇与澳大利亚有关的文章,则已经为此创建了案例,因此我将无法添加第二个课程,因为它会跳过它。所以我认为我做错了,我不应该使用switch case
。
的想法是,以检查country custom field
和sovereignt property within the geoson
之间的匹配,这样我就可以得出该国的多边形,如果任何物品,关系到一个国家,但如果我有2页涉及到一个国家的文章,多边形只画了一次,但有上面的类问题。
geojson = L.geoJson(statesData, {
style: style,
style: function(feature) {
<?php
query_posts(array(
'post_type' => 'post',
'showposts' => -1
));
?>
switch (feature.properties.sovereignt) {
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
case '<?php the_field("country"); ?>': return {className: '_<?php the_field("year"); ?>'};
<?php endwhile; endif;?>
}
},
onEachFeature: onEachFeature
}).addTo(map);
开关案例我是从leaflet docs
P.S.请原谅我生锈的PHP,这是一段时间。 – IvanSanchez
post.country是什么?你的意思是我应该输出这个字段,比如the_field(“country”); ? –
以任何你需要的方式输出它。考虑我的PHP是伪代码。 – IvanSanchez