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

以下拉列表的方式显示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>
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容