我创建了一个功能,用于将帖子保存为“精选”并在主页上显示它们。它与管理面板中的自定义复选框一起使用。我在论坛上的帮助下完成了该功能,但我想在此功能中添加为每个精选帖子设置特定订单号并按此顺序在首页显示它们的功能。(选择哪个是第一个,哪个是第二个,第三个等等……)
// FEATURED POST FUNCTION
add_action('add_meta_boxes', 'add_checkbox_featured');
function add_checkbox_featured() {
add_meta_box('is_featured', 'Featured', 'print_checkbox_featured', 'post', 'side');}
function print_checkbox_featured() {
global $post;
$checked = get_post_meta($post->ID, '_featured', true) ? 'checked="checked"' : '';
echo '<label for="checkbox_is_featured">Show at the front page <input id="checkbox_is_featured" name="is_featured" type="checkbox" value="1" '.$checked.'/</label>';
}
add_action('save_post', 'save_checkbox_featured');
function save_checkbox_featured($post_id){
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
if ($_POST['is_featured']){
add_post_meta($post_id, '_featured', '1');
}else{
delete_post_meta($post_id, '_featured');
}
}