是否可以将蓝色发布按钮放在WordPress的后端,并将其放在我的index.php中的帖子附近的前端。我需要一种在不上仪表板的情况下发布未决文章的方法,只有管理员才能看到发布按钮?

<?php   
$args=array(
'post_type'         => 'post',
'post_status'       => 'pending',
'order'                 => 'ASC',
'caller_get_posts'  =>1,
'paged'         =>$paged,
            );

谢谢大家的帮助:D

有帮助吗?

解决方案

首先创建一个将打印出发布按钮的函数:

//function to print publish button
function show_publish_button(){
    Global $post;
    //only print fi admin
    if (current_user_can('manage_options')){
        echo '<form name="front_end_publish" method="POST" action="">
                <input type="hidden" name="pid" id="pid" value="'.$post->ID.'">
                <input type="hidden" name="FE_PUBLISH" id="FE_PUBLISH" value="FE_PUBLISH">
                <input type="submit" name="submit" id="submit" value="Publish">
            </form>';
    }
}

接下来创建一个函数以更改邮政状态:

//function to update post status
function change_post_status($post_id,$status){
    $current_post = get_post( $post_id, 'ARRAY_A' );
    $current_post['post_status'] = $status;
    wp_update_post($current_post);
}

然后确保捕获按钮的提交:

if (isset($_POST['FE_PUBLISH']) && $_POST['FE_PUBLISH'] == 'FE_PUBLISH'){
    if (isset($_POST['pid']) && !empty($_POST['pid'])){
        change_post_status((int)$_POST['pid'],'publish');
    }
}

现在,以上所有代码都可以在您的主题函数中进行。php文件,您要做的就是添加 show_publish_button(); 在您的每次帖子之后,在您待处理的帖子中。

许可以下: CC-BY-SA归因
scroll top