WordPress教程

WordPress分类目录描述添加可视化编辑器

阿里云

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

  1. /**
  2.  * wordpress分类目录添加可视化编辑器
  3.  * 
  4.  */
  5. // 移除HTML过滤
  6. remove_filter( 'pre_term_description', 'wp_filter_kses' );
  7. remove_filter( 'term_description', 'wp_kses_data' );
  8. //为分类编辑界面添加可视化编辑器的“描述”框
  9. add_filter('edit_category_form_fields', 'cat_description');
  10. function cat_description($tag)
  11. {
  12. 	?>
  13. 	<table class="form-table">
  14. 		<tr class="form-field">
  15. 			<th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
  16. 			<td>
  17. 				<?php
  18. 				$settings = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true, 'textarea_rows' => '15', 'textarea_name' => 'description' );
  19. 				wp_editor(wp_kses_post($tag->description , ENT_QUOTES, 'UTF-8'), 'cat_description', $settings);
  20. 				?>
  21. 				<br />
  22. 				<span class="description"><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></span>
  23. 			</td>
  24. 		</tr>
  25. 	</table>
  26. 	<?php
  27. }
  28. //移除默认的“描述”框
  29. add_action('admin_head', 'remove_default_category_description');
  30. function remove_default_category_description()
  31. {
  32. 	global $current_screen;
  33. 	if ( $current_screen->id == 'edit-category' )
  34. 	{
  35. 		?>
  36. 		<script type="text/javascript">
  37. 			jQuery(function($) {
  38. 				$('textarea#description').closest('tr.form-field').remove();
  39. 			});
  40. 		</script>
  41. 		<?php
  42. 	}
  43. }
也想出现在这里?联系我们
创客主机

简化版

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

  1.     add_action("category_edit_form_fields", 'add_form_fields_example', 10, 2);
  2.     function add_form_fields_example($term, $taxonomy){
  3.         ?>
  4.         <tr valign="top">
  5.             <th scope="row"><?php _e('描述','salong'); ?></th>
  6.             <td>
  7.                 <?php wp_editor(html_entity_decode($term->description), 'description', array('media_buttons' => true,'quicktags'=>true)); ?>
  8.                 <script>
  9.                     jQuery(window).ready(function(){
  10.                         jQuery('label[for=description]').parent().parent().remove();
  11.                     });
  12.                 </script>
  13.             </td>
  14.         </tr>
  15.         <?php
  16.     }

获取分类描述

  1. <?php echo term_description( $term_id, 'category' ); ?>

WordPress 分类目录描述添加可视化编辑器

已有 212 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!