本文介绍了Wordpress-如何创建到数据过滤器元素的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的WordPress网站的页面使用页面过滤器"菜单,用户可以单击项目以过滤下面的帖子类型.有没有一种方法可以创建指向每个过滤器菜单项的链接,用户可以从此页面外部直接访问这些菜单项?请查看下面的html代码:
A page of my WordPress site use an On page filter menu which user can click on items to filter posts type below. Is there a way to create a link to every filter menu item which user can access directly to them from outside of this page? Please see the html code below:
<ul class="filter js-filter">
<li class="active">
<a href="#" data-filter="*">All</a>
</li>
<li class="">
<a href="#" data-filter=".building">Building </a>
</li>
<li class="">
<a href="#" data-filter=".villa">Villa </a>
</li>
<li class="">
<a href="#" data-filter=".interior">Interior </a>
</li>
<li class="">
<a href="#" data-filter=".exterior">Exterior </a>
</li>
</ul>
推荐答案
最简单的方法可能是使用jQuery的 trigger()
模拟基于URL片段(URL中的哈希)的相应元素的点击
The easiest way would probably be to use jQuery's trigger()
to simulate a click on the appropriate element based on a URL Fragment (hash in the URL)
链接:
<a href="https://example.com/filter-page#*">Filter All</a>
<a href="https://example.com/filter-page#.building">Filter Buildings</a>
过滤器页面上的JavaScript
JavaScript on your filter page:
jQuery(document).ready(function($){
var currentFilter = window.location.hash.substr(1);
$('.js-filter [data-filter="'+ currentFilter +'"]').trigger('click');
});
这篇关于Wordpress-如何创建到数据过滤器元素的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!