Wordpress后台标签自动全部显示

首先说明,花了一整天来研究这个东西,虽然各种失败,但是依然告诉自己要冷静,冷静!

下午找了两个同事帮忙,尝试用jquery自动加载点击事件,但怎样都不行。

说一下啊,wp-includes下的functions为后台自动加载函数

因为前侧到ajax,虽然拿到了标签数据,但是点击事件会全部失效。

各种折腾啊,下班又折腾了一个半小时,几乎是背水一战,搞定!

火狐浏览器F12查看了加载的js文件,又从对应js文件中得到js代码,找到了灵感。

直接放代码吧,修改在wp-admin/includes/meta-boxes.php

主要是增加了JS文件,PHP代码没有做任何修改!

<?php if ( $user_can_assign_terms ) : ?>
<p class="hide-if-no-js"><button type="button" class="button-link tagcloud-link" id="link-<?php echo $tax_name; ?>" aria-expanded="true"><?php echo $taxonomy->labels->all_items; ?></button></p>
<?php endif; ?>
<script type="text/javascript">
	jQuery(document).ready(function($) {
		var id = $('.tagcloud-link').attr( 'id' );
		var tax = id.substr( id.indexOf('-') + 1 );
		$.post( ajaxurl, { 'action': 'get-tagcloud', 'tax': 'video_tag' }, function( r, stat ) {
			if ( 0 === r || 'success' != stat ) {
					return;
				}

			r = $( '<p id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</p>' );
			$( 'a', r ).click( function() {
				tagBox.userAction = 'add';
				tagBox.flushTags( $( '#video_tag' ), this );
				return false;
			});

			$( '#' + id ).after( r );
		});
		// Update button state, remove previous click event and attach a new one to toggle the cloud.
		$('.tagcloud-link')
			.attr( 'aria-expanded', 'true' )
			.unbind()
			.click( function() {
				$( this )
					.attr( 'aria-expanded', 'false' === $('.tagcloud-link').attr( 'aria-expanded' ) ? 'true' : 'false' )
					.siblings( '.the-tagcloud' ).toggle();
			});
	});
</script>

最新使用方法,在 wp-admin\includes\meta-boxes.php 约 551 行在 endif 和 <?php 之间增加点击事件

<?php endif; ?>
		<script type="text/javascript">
	        jQuery(document).ready(function($) {
	            //模拟点击事件
	            setTimeout(function() {
	                $('#link-post_tag').click();
	            },2000)
	        });
    	</script>
	<?php

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值