2024年07月21日 建站教程
wordpress建站如何对文章及栏目进行排序,下面web建站小编给大家介绍一下代码!
1、在当前主题模板functions.php新增以下代码
function posts_order() { add_post_type_support( 'post', 'page-attributes' ); } add_action( 'admin_init', 'posts_order' );
2、文章排序
$order_posts = new WP_Query(array( 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC', ));
3、后台文章列表显示排序编号
function wz_posts_order_show_columns($name) { global $post; switch ($name) { case 'order': $views = $post->menu_order; echo $views; break; } } add_action('manage_posts_custom_column', 'wz_posts_order_show_columns'); function zm_posts_order_columns($defaults) { $defaults['order'] = '排序'; return $defaults; } add_filter('manage_posts_columns', 'zm_posts_order_columns');
4、批量清零排序编号:
global $wpdb; $wpdb->query("UPDATE wp_posts SET menu_order = 0 WHERE post_type = 'post'");
本文链接:http://so.lmcjl.com/news/8895/