以下拉列表显示WordPress所有文章类型

知更鸟 WordPress评论216阅读模式

以下拉列表的方式显示WordPress所有文章类型,包括自定义文章类型。

<?php
	$args = array(
		'public' => true,
	);
	$post_types = get_post_types( $args, 'objects' );
?>

<select class="widefat" name="post_type">
	<?php foreach ( $post_types as $post_type_obj ):
		$labels = get_post_type_labels( $post_type_obj );
	?>
	<option value="<?php echo esc_attr( $post_type_obj->name ); ?>"><?php echo esc_html( $labels->name ); ?></option>
	<?php endforeach; ?>
</select>

 文章源自知更鸟-https://zmingcx.com/display-the-html-dropdown-list-of-post-types.html

文章源自知更鸟-https://zmingcx.com/display-the-html-dropdown-list-of-post-types.html文章源自知更鸟-https://zmingcx.com/display-the-html-dropdown-list-of-post-types.html
weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定