当前位置: 首页 » 网站建设 » wordpress教程 » 正文

给wordpress分类添加字段

发布时间:2025-01-16 以下文章来源于网友投稿,内容仅供参考!

wordpress分类字段功能对于综合类网站来讲,是一个非常灵活的调用功能。可以根据网站不同的需求来调用不同的字段选项;下面给大家介绍一款非常实力的函数代码;是用来调用电话及联络方式的,各位可以根据自己的需求对代码进行调整和修改;测速网用来修改成了wordpress主题分类的标签id调用;亲测可用的;

1. 在wordpress主题模板目录下的主函数文本代码 function.PHP 里添加包含 页面 category_field.php

包括代码如下:

area data-settings="dblclick" readonly >// 分类添加字段 require_once( dirname(__FILE__).'/category_field.php' ); area>12// 分类添加字段require_once( dirname(__FILE__).'/category_field.php' );

2. 新建 category_field.php 页面
代码如下:

area data-settings="dblclick" readonly ><?php // 分类添加字段 function ems_add_category_field(){ echo '<div > <label for="cat-tel">Tel</label> <input name="cat-tel" id="cat-tel" type="text" value="" size="40"> <p>The telephone.</p></div>'; echo '<div > <label for="cat-url">URL</label> <input name="cat-url" id="cat-url" type="text" value="" size="40"> <p>The URL.</p></div>';} add_action('category_add_form_fields','ems_add_category_field',10,2);// 分类编辑字段 function ems_edit_category_field($tag){ echo '<tr > <th scope="row"><label for="cat-tel">Tel</label></th> <td> <input name="cat-tel" id="cat-tel" type="text" value="'; echo get_option('cat-tel-'.$tag->term_id).'" size="40"/><br> <span >'.$tag->name.' on the phone.</span> </td> </tr>';echo '<tr > <th scope="row"><label for="cat-url">URL</label></th> <td> <input name="cat-url" id="cat-url" type="text" value="'; echo get_option('cat-url-'.$tag->term_id).'" size="40"/><br> <span >'.$tag->name.' on the URL.</span> </td> </tr>'; } add_action('category_edit_form_fields','ems_edit_category_field',10,2);// 保存数据 function ems_taxonomy_metadate($term_id){ if(isset($_POST['cat-tel']) && isset($_POST['cat-url'])){ //判断权限--可改 if(!current_user_can('manage_categories')){ return $term_id; } // 电话 $tel_key = 'cat-tel-'.$term_id; // key 选项名为 cat-tel-1 类型 $tel_value = $_POST['cat-tel']; // value// url $url_key = 'cat-url-'.$term_id; $url_value = $_POST['cat-url']; // 更新选项值 update_option( $tel_key, $tel_value ); update_option( $url_key, $url_value ); } }// 虽然要两个钩子,但是我们可以两个钩子使用同一个函数 add_action('created_category','ems_taxonomy_metadate',10,1); add_action('edited_category','ems_taxonomy_metadate',10,1); ?> area>161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<?php // 分类添加字段function ems_add_category_field(){echo '<div ><label for="cat-tel">Tel</label><input name="cat-tel" id="cat-tel" type="text" value="" size="40"><p>The telephone.</p></div>';echo '<div ><label for="cat-url">URL</label><input name="cat-url" id="cat-url" type="text" value="" size="40"><p>The URL.</p></div>';}add_action('category_add_form_fields','ems_add_category_field',10,2);// 分类编辑字段function ems_edit_category_field($tag){echo '<tr ><th scope="row"><label for="cat-tel">Tel</label></th><td><input name="cat-tel" id="cat-tel" type="text" value="';echo get_option('cat-tel-'.$tag->term_id).'" size="40"/><br><span >'.$tag->name.' on the phone.</span></td></tr>';echo '<tr ><th scope="row"><label for="cat-url">URL</label></th><td><input name="cat-url" id="cat-url" type="text" value="';echo get_option('cat-url-'.$tag->term_id).'" size="40"/><br><span >'.$tag->name.' on the URL.</span></td></tr>'; }add_action('category_edit_form_fields','ems_edit_category_field',10,2);// 保存数据function ems_taxonomy_metadate($term_id){if(isset($_POST['cat-tel']) && isset($_POST['cat-url'])){//判断权限--可改if(!current_user_can('manage_categories')){return $term_id;}// 电话$tel_key = 'cat-tel-'.$term_id; // key 选项名为 cat-tel-1 类型$tel_value = $_POST['cat-tel']; // value// url$url_key = 'cat-url-'.$term_id;$url_value = $_POST['cat-url']; // 更新选项值update_option( $tel_key, $tel_value ); update_option( $url_key, $url_value );}}// 虽然要两个钩子,但是我们可以两个钩子使用同一个函数add_action('created_category','ems_taxonomy_metadate',10,1);add_action('edited_category','ems_taxonomy_metadate',10,1);?>

前台字段调用方法

area data-settings="dblclick" readonly ><?php // 取出当前分类 id: $categories[0]->term_id $categories = get_the_category(); $term_id = $categories[0]->term_id; $cat_name = $categories[0]->name; ?> <div ><div ><?php echo get_option('cat-tel-'.$term_id);?></div><div ><a href="<?php echo get_option('cat-url-'.$term_id);?> " target="_blank"><?php echo $cat_name;?></a></div> </div> area>12345678910<?php // 取出当前分类 id: $categories[0]->term_id$categories = get_the_category();$term_id = $categories[0]->term_id;$cat_name = $categories[0]->name;?><div ><div ><?php echo get_option('cat-tel-'.$term_id);?></div><div ><a href="<?php echo get_option('cat-url-'.$term_id);?> " target="_blank"><?php echo $cat_name;?></a></div></div>
  • • 开启wds是什么意思?无线路由器wds是怎么开启?

    开启wds是什么意思?WDS是英文Wireless Distribution System的简称,中文名称是:无线分布式系统。WDS功能就是一种帮助无线基站与

  • • 系统boot是什么意思?电脑出现boot manager怎么办?

    系统boot是什么意思1、开机后我们连续按启动热键,进入bios界面,我们就可以看到boot了。2、boot有启动的意思,在电脑中就是指电

  • • win10系统msconfig无法正常启动怎么办?win10系统msconfig怎么设置最

    msconfig打不开解决办法:1.先打开电脑开始菜单,在操作窗口输入regedit,打开注册表编辑器。然后将HKEY_LOCAL_MACHINE\SOFTWARE

  • • 金士顿u盘怎么写保护?金士顿U盘恢复出厂设置怎么操作?

    金士顿u盘怎么写保护?方法一:如果你的U盘如我简介中说的那样,有一个自带的物理写保护的小 开关 ,就观察一下是不是已经将开关

  • • 苹果AirPods Pro 2发布 搭载H2芯片降噪能力翻倍

    9月8日凌晨,苹果正式发布第二代主动降噪耳机AirPods Pro 2,搭载H2芯片,降噪能力翻倍,而且续航也飚至30小时。得益于全新的H2

  • biubiu加速器
    九游优盟游戏推广平台
    九游推广联盟
    digdig游戏入口
    4999小游戏大全
    九游游戏网
    站长素材
    植物大战僵尸杂交免费版
    站长之家
    测速网在线测网速
    354211邮编查询,354211邮政编码查询
    354209邮编查询,354209邮政编码查询
    353132邮编查询,353132邮政编码查询
    354215邮编查询,354215邮政编码查询
    353121邮编查询,353121邮政编码查询
    354213邮编查询,354213邮政编码查询
    353125邮编查询,353125邮政编码查询
    354201邮编查询,354201邮政编码查询
    353101邮编查询,353101邮政编码查询
    354200邮编查询,354200邮政编码查询