web建站教程
     
  1. 首页
  2. 前端UI组件库
  3. AI项目和框架
  4. AIGC工具
  5. 百度echarts
  6. 地图大全
  7. 前端知识
  8. 更多
    vuejs
    js入门
    php入门
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    AI应用

wordpress栏目添加缩略图封面代码介绍

931 ℃

wordpress建站,如何在栏目添加缩略图封面功能,今天给大家分享一个如何通过代码来添加分类栏目缩略图字段功能,将如下代码添加到wordpress主functions.php中:

function salong_add_category_field(){
    echo '<div class="form-field">
            <label for="thumb">'.__('缩略图','salong').'</label>
            <input name="thumb" id="thumb" type="text" value="" size="40">
            <p>'.__('输入分类的缩略图链接。','salong').'</p>
          </div>';
}
add_action('category_add_form_fields','salong_add_category_field',10,2);
// 分类编辑字段  
function salong_edit_category_field($tag){
    echo '<tr class="form-field">
            <th scope="row"><label for="thumb">'.__('灰色地图','salong').'</label></th>
            <td>
                <input name="thumb" id="thumb" type="text" value="';  
                echo get_option('thumb-'.$tag->term_id).'" size="40"/><br>
                <span class="thumb">'.$tag->name.__('分类的缩略图链接。','salong').'</span>
            </td>
        </tr>';
}
add_action('category_edit_form_fields','salong_edit_category_field',10,2);
// 保存数据  
function salong_category_thumb($term_id){
    if(isset($_POST['thumb'])){
        //判断权限--可改  
        if(!current_user_can('manage_categories')){
            return $term_id;
        }
        $thumb_key = 'thumb-'.$term_id;
        $thumb_value = $_POST['thumb'];
        // 更新选项值  
        update_option( $thumb_key, $thumb_value );
    }
}
// 虽然要两个钩子,但是我们可以两个钩子使用同一个函数  
add_action('created_category','salong_category_thumb',10,1);
add_action('edited_category','salong_category_thumb',10,1);

添加好以上代码,如何调用呢,在需要显示分类缩略图的位置添加以下代码即可完成自动的调用功能:

echo get_option('thumb_color-'.$category_id)

ZipWP官网:一个AI驱动的零代码WordPress建站神器

小半WordPress AI助手:开源免费的AI插件,为WordPress网站注入智能内容创作能力

WordPress ai助手:为 WordPress 用户提供集成多种 AI 模型的功能

wordpress利用mysql让文章 ID重新排列

wordpress如何在搜索结果中排除指定分类的文章

标签: wordpress 缩略图

上面是“wordpress栏目添加缩略图封面代码介绍”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2094.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 首页 > wordpress
Trae:新一代免费的AI编程工具

呱呱工具箱

一款免费的在线小工具,无需下载,打开即可使用!呱呱工具箱

在线育儿补贴计算器

快来看看你到底可以领到多少补贴!生活小工具
上一篇:
下一篇:
x 打工人ai神器