英文:
want to remove a <li> from list with a code in functions
问题
我有一个WordPress插件,支持非常差。这是一个用于班车服务的插件。为了预订班车,访客必须选择一个上车点和一个目的地点。
这两个点都在列表中进行配置,并且用于两个选择列表。有些用于上车,其他用于目的地。
在上车点,我想隐藏/删除一些项目,但是插件的任何配置都无法实现。
我希望有人能理解我的问题。首先,我提供一些构建表单的代码,然后是我尝试过但不起作用的方法...
首先是代码:
<div class="mage_input_select mage_bus_boarding_point">
<div class="route-input-wrap"><input id="bus_start_route" type="text" class="mage_form_control" name="bus_start_route" value="Fürth" placeholder="Please Select" autocomplete="off" required=""></div>
<div class="mage_input_select_list" style="display: block;">
<ul>
<li data-route="Bruck a/d Großglocknerstraße"><span class="fa fa-map-marker"></span>Bruck a/d Großglocknerstraße</li>
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li><li data-route="Fürth"><span class="fa fa-map-marker"></span>Fürth</li>
<li data-route="Kaprun"><span class="fa fa-map-marker"></span>Kaprun</li>
<li data-route="Salzburg Flughafen"><span class="fa fa-map-marker"></span>Salzburg Flughafen</li>
<li data-route="Taxenbach"><span class="fa fa-map-marker"></span>Taxenbach</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
<li data-route="Zell am See"><span class="fa fa-map-marker"></span>Zell am See</li>
</ul>
</div>
</div>
我想要隐藏的部分是...
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
我在functions.php文件中尝试的代码如下:
function remove_list_items_from_page_content($content) {
$content = preg_replace('/<li data-route="(Führt - Mittersill|test patrick)">.*?<\/li>/', '', $content);
return $content;
}
function modify_page_content() {
if (is_page(130)) {
$page_content = get_post_field('post_content', 130);
$new_page_content = remove_list_items_from_page_content($page_content);
$new_page_content = wp_kses_post($new_page_content);
wp_update_post(array('ID' => 130, 'post_content' => $new_page_content));
}
}
add_action('wp', 'modify_page_content');
但是它不起作用,有什么问题吗?
包含该表单的页面的ID是130,也是我的起始页面...
我不知道在这里是否允许提供我的开发页面的URL?
英文:
i have a wordpress plugin where the support is symply bad. this is a plugin for a shuttle service. to book a shuttle, the visitor have to pick a boarding point and a destination point.
both are configured in a list and are used for both select lists. some are used for boarding, other for the destination.
in boarding i want to hide/some items, and this is not possible by any configuration af the plugin.
i hope someone understand my issue. first i give some code how the form is build, then what i have try but it does not work...
first the code:
<div class="mage_input_select mage_bus_boarding_point">
<div class="route-input-wrap"><input id="bus_start_route" type="text" class="mage_form_control" name="bus_start_route" value="Fürth" placeholder="Please Select" autocomplete="off" required=""></div>
<div class="mage_input_select_list" style="display: block;">
<ul>
<li data-route="Bruck a/d Großglocknerstraße"><span class="fa fa-map-marker"></span>Bruck a/d Großglocknerstraße</li>
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li><li data-route="Fürth"><span class="fa fa-map-marker"></span>Fürth</li>
<li data-route="Kaprun"><span class="fa fa-map-marker"></span>Kaprun</li>
<li data-route="Salzburg Flughafen"><span class="fa fa-map-marker"></span>Salzburg Flughafen</li>
<li data-route="Taxenbach"><span class="fa fa-map-marker"></span>Taxenbach</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
<li data-route="Zell am See"><span class="fa fa-map-marker"></span>Zell am See</li>
</ul>
</div>
</div>
what i want to hide...
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
and what i did try for my functions.php file:
function remove_list_items_from_page_content($content) {
$content = preg_replace('/<li data-route="(Führt - Mittersill|test patrick)">.*?<\/li>/', '', $content);
return $content;
}
function modify_page_content() {
if (is_page(130)) {
$page_content = get_post_field('post_content', 130);
$new_page_content = remove_list_items_from_page_content($page_content);
$new_page_content = wp_kses_post($new_page_content);
wp_update_post(array('ID' => 130, 'post_content' => $new_page_content));
}
}
add_action('wp', 'modify_page_content');
But it is not working, what is wrong?
the page with the form have ID-130 and is my start-page...
I do not know if it is forbidden here to give the url of my develop page?
答案1
得分: 3
你可以使用CSS以以下方式来实现,使用选择器中的"data-route"属性:
li[data-route="Führt - Mittersill"],
li[data-route="test patrick"] {
display: none;
}
<div class="mage_input_select mage_bus_boarding_point">
<div class="route-input-wrap"><input id="bus_start_route" type="text" class="mage_form_control" name="bus_start_route" value="Fürth" placeholder="Please Select" autocomplete="off" required=""></div>
<div class="mage_input_select_list" style="display: block;">
<ul>
<li data-route="Bruck a/d Großglocknerstraße"><span class="fa fa-map-marker"></span>Bruck a/d Großglocknerstraße</li>
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li>
<li data-route="Fürth"><span class="fa fa-map-marker"></span>Fürth</li>
<li data-route="Kaprun"><span class="fa fa-map-marker"></span>Kaprun</li>
<li data-route="Salzburg Flughafen"><span class="fa fa-map-marker"></span>Salzburg Flughafen</li>
<li data-route="Taxenbach"><span class="fa fa-map-marker"></span>Taxenbach</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
<li data-route="Zell am See"><span class="fa fa-map-marker"></span>Zell am See</li>
</ul>
</div>
</div>
注意:以上代码是一个示例,用于演示如何使用CSS选择器和"data-route"属性来隐藏特定的列表项。你可以根据自己的需求进行修改和适应。
英文:
You can use CSS to do that in the following way, using the "data-route" attribute in a selector:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
li[data-route="Führt - Mittersill"],
li[data-route="test patrick"] {
display: none;
}
<!-- language: lang-html -->
<div class="mage_input_select mage_bus_boarding_point">
<div class="route-input-wrap"><input id="bus_start_route" type="text" class="mage_form_control" name="bus_start_route" value="Fürth" placeholder="Please Select" autocomplete="off" required=""></div>
<div class="mage_input_select_list" style="display: block;">
<ul>
<li data-route="Bruck a/d Großglocknerstraße"><span class="fa fa-map-marker"></span>Bruck a/d Großglocknerstraße</li>
<li data-route="Führt - Mittersill"><span class="fa fa-map-marker"></span>Führt - Mittersill</li><li data-route="Fürth"><span class="fa fa-map-marker"></span>Fürth</li>
<li data-route="Kaprun"><span class="fa fa-map-marker"></span>Kaprun</li>
<li data-route="Salzburg Flughafen"><span class="fa fa-map-marker"></span>Salzburg Flughafen</li>
<li data-route="Taxenbach"><span class="fa fa-map-marker"></span>Taxenbach</li>
<li data-route="test patrick"><span class="fa fa-map-marker"></span>test patrick</li>
<li data-route="Zell am See"><span class="fa fa-map-marker"></span>Zell am See</li>
</ul>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论