如何在php中分配属性?

发布于 2024-12-07 03:14:29 字数 641 浏览 3 评论 0原文

我已经给 元素一个 data-filter 属性,如下所示:

<ul> 
    <li>
        <a href="#" data-filter="*" class="all current"><?php _e('All', 'framework'); ?></a>
        <span>/</span>
    </li> 

    <?php  
    wp_list_categories(array( 
            'title_li' => '',  
            'taxonomy' =>  
            'skill-type',  
            'walker' => new Portfolio_Walker(), 
            'show_option_none' => '' 
        ) 
    );
    ?> 
</ul>

How can I pass this data-filter property to PHP ?

I have given an <a> element a data-filter property, as shown:

<ul> 
    <li>
        <a href="#" data-filter="*" class="all current"><?php _e('All', 'framework'); ?></a>
        <span>/</span>
    </li> 

    <?php  
    wp_list_categories(array( 
            'title_li' => '',  
            'taxonomy' =>  
            'skill-type',  
            'walker' => new Portfolio_Walker(), 
            'show_option_none' => '' 
        ) 
    );
    ?> 
</ul>

How can I pass this data-filter property to PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风苍溪 2024-12-14 03:14:29

如何将此数据过滤器属性传递给 PHP?

你不能。不可能使用纯 HTML 和 PHP 将某个(虚构的)HTML 属性传输到 PHP。一个不错的选择是使用表单,您可以在其中选择单选按钮并提交表单。

编辑

另一种选择是简单地通过请求的查询字符串传递过滤器:

<li>
    <a href="?data-filter=*" class="all current"><?php _e('All', 'framework'); ?></a>
    <span>/</span>
</li> 

// in PHP:
$data_filter = $_GET['data-filter'];
echo $data_filter;

How can I pass this data-filter property to PHP?

You can't. It's not possible using pure HTML and PHP to transfer a certain (made-up) HTML attribute to PHP. A decent alternative is to use a form instead, where you could select a radio button and submit the form.

EDIT:

Another alternative is to simply pass the filter through the request's query string:

<li>
    <a href="?data-filter=*" class="all current"><?php _e('All', 'framework'); ?></a>
    <span>/</span>
</li> 

// in PHP:
$data_filter = $_GET['data-filter'];
echo $data_filter;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文