kavo

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

 

 

posted on   下雨天唱情歌  阅读(3)  评论(0编辑  收藏  举报  

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示