以下拉列表的方式显示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本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论