wp_ajax_get_tagcloud

函式
wp_ajax_get_tagcloud ( No parameters )

wp_ajax_get_tagcloud: 這個函式是一個WordPress的AJAX處理程式,用於返回標籤雲的HTML標記。它不需要引數,在AJAX響應中返回標籤雲的HTML標記。

用於獲取標籤雲的Ajax處理程式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_ajax_get_tagcloud() {
if ( ! isset( $_POST['tax'] ) ) {
wp_die( 0 );
}
$taxonomy = sanitize_key( $_POST['tax'] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
wp_die( 0 );
}
if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
wp_die( -1 );
}
$tags = get_terms(
array(
'taxonomy' => $taxonomy,
'number' => 45,
'orderby' => 'count',
'order' => 'DESC',
)
);
if ( empty( $tags ) ) {
wp_die( $taxonomy_object->labels->not_found );
}
if ( is_wp_error( $tags ) ) {
wp_die( $tags->get_error_message() );
}
foreach ( $tags as $key => $tag ) {
$tags[ $key ]->link = '#';
$tags[ $key ]->id = $tag->term_id;
}
// We need raw tag names here, so don't filter the output.
$return = wp_generate_tag_cloud(
$tags,
array(
'filter' => 0,
'format' => 'list',
)
);
if ( empty( $return ) ) {
wp_die( 0 );
}
echo $return;
wp_die();
}
function wp_ajax_get_tagcloud() { if ( ! isset( $_POST['tax'] ) ) { wp_die( 0 ); } $taxonomy = sanitize_key( $_POST['tax'] ); $taxonomy_object = get_taxonomy( $taxonomy ); if ( ! $taxonomy_object ) { wp_die( 0 ); } if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) { wp_die( -1 ); } $tags = get_terms( array( 'taxonomy' => $taxonomy, 'number' => 45, 'orderby' => 'count', 'order' => 'DESC', ) ); if ( empty( $tags ) ) { wp_die( $taxonomy_object->labels->not_found ); } if ( is_wp_error( $tags ) ) { wp_die( $tags->get_error_message() ); } foreach ( $tags as $key => $tag ) { $tags[ $key ]->link = '#'; $tags[ $key ]->id = $tag->term_id; } // We need raw tag names here, so don't filter the output. $return = wp_generate_tag_cloud( $tags, array( 'filter' => 0, 'format' => 'list', ) ); if ( empty( $return ) ) { wp_die( 0 ); } echo $return; wp_die(); }
function wp_ajax_get_tagcloud() {
	if ( ! isset( $_POST['tax'] ) ) {
		wp_die( 0 );
	}

	$taxonomy        = sanitize_key( $_POST['tax'] );
	$taxonomy_object = get_taxonomy( $taxonomy );

	if ( ! $taxonomy_object ) {
		wp_die( 0 );
	}

	if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
		wp_die( -1 );
	}

	$tags = get_terms(
		array(
			'taxonomy' => $taxonomy,
			'number'   => 45,
			'orderby'  => 'count',
			'order'    => 'DESC',
		)
	);

	if ( empty( $tags ) ) {
		wp_die( $taxonomy_object->labels->not_found );
	}

	if ( is_wp_error( $tags ) ) {
		wp_die( $tags->get_error_message() );
	}

	foreach ( $tags as $key => $tag ) {
		$tags[ $key ]->link = '#';
		$tags[ $key ]->id   = $tag->term_id;
	}

	// We need raw tag names here, so don't filter the output.
	$return = wp_generate_tag_cloud(
		$tags,
		array(
			'filter' => 0,
			'format' => 'list',
		)
	);

	if ( empty( $return ) ) {
		wp_die( 0 );
	}

	echo $return;
	wp_die();
}

常見問題

FAQs
檢視更多 >