WordPress 文章类型的功能支持详解,添加(编辑器)实例

我们在给客户仿站的时候遇到一个问题,同分类下子分类要分别有页面级分类栏目,那怎样实现呢 WordPress 分类描述默认只是 textarea 文本框,如果要图文结合的介绍当前分类,就得编辑描述或添加图片,所以我们将改造下后台的分类描述表单。怎么在分类目录下做开发,做成一个独立页面内容的样式,那最简单的就是在分类目录编辑里添加编辑器。下面推荐给推荐给大家一段添加编辑器代码亲测可。

/**
 * wordpress分类目录添加可视化编辑器
 * 
 */
// 移除HTML过滤
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
//为分类编辑界面添加可视化编辑器的“描述”框
add_filter('edit_category_form_fields', 'cat_description');
function cat_description($tag)
{
    ?>
    <table class="form-table">
        <tr class="form-field">
            <th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
            <td>
                <?php
                $settings = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true, 'textarea_rows' => '15', 'textarea_name' => 'description' );
                wp_editor(wp_kses_post($tag->description , ENT_QUOTES, 'UTF-8'), 'cat_description', $settings);
                ?>
                <br />
                <span class="description"><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></span>
            </td>
        </tr>
    </table>
    <?php
}
// 移除默认的“描述”框
add_action('admin_head', 'remove_default_category_description');
function remove_default_category_description()
{
    global $current_screen;
    if ( $current_screen->id == 'edit-category' )
    {
        ?>
        <script type="text/javascript">
            jQuery(function($) {
                $('textarea#description').closest('tr.form-field').remove();
            });
        </script>
        <?php
    }
}

简化版

将如下代码添加到 functions.php 函数文件中,编辑器可设置 wp_editor 函数

 add_action("category_edit_form_fields", 'add_form_fields_example', 10, 2);
    function add_form_fields_example($term, $taxonomy){
        ?>
        <tr valign="top">
            <th scope="row"><?php _e('描述','salong'); ?></th>
            <td>
                <?php wp_editor(html_entity_decode($term->description), 'description', array('media_buttons' => true,'quicktags'=>true)); ?>
                <script>
                    jQuery(window).ready(function(){
                        jQuery('label[for=description]').parent().parent().remove();
                    });
                </script>
            </td>
        </tr>
        <?php
    }

获取分类描述

<?php echo term_description( $term_id, 'category' ); ?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值