douzhe9075 2014-03-28 05:57
浏览 25
已采纳

语法 - 将html属性添加到下拉类别

I am new to PHP and Wordpress. I have the following code in one of my plugin file. It is used to generate a drop down for categories. I want to add an html attribute to it. I want to add the html attribute "autofocus" to it so that when the page load this select box has focus by default.

<?php  

    wp_dropdown_categories( array( 

        'name'          => 'question-category',

        'id'            => 'question-category',

        'taxonomy'      => 'dwqa-question_category',

        'show_option_none' => __('Select a question category','dwqa'),

        'hide_empty'    => 0,

        'quicktags'     => array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ),            

    ) );

?>

I am having problem with the syntax in which this should be added.

  • 写回答

2条回答 默认 最新

  • doubinei1457 2014-03-28 06:07
    关注

    your best bet is going to be to set the echo attribute to false and then find and replace parts of the html that is returned.

    <?php  
    
        $questioncategory = wp_dropdown_categories( array( 
    
            'echo'     => false,
    
            'name'          => 'question-category',
    
            'id'            => 'question-category',
    
            'taxonomy'      => 'dwqa-question_category',
    
            'show_option_none' => __('Select a question category','dwqa'),
    
            'hide_empty'    => 0,
    
            'quicktags'     => array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ),            
    
        ) );
    
        $questioncategory = str_replace('<select', '<select autofocus', $questioncategory);
        echo $questioncategory;
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?