日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

讓你的WordPress博客實(shí)現(xiàn)前臺(tái)快捷發(fā)布文章 | 螞蟻博客

 覡先生藏書館 2016-02-16

自從用上了微博,就覺得Wordpress的文章發(fā)布功能好麻煩,為什么不能在首頁(yè)發(fā)布文章呢?找來找去,找到了P2主題,可是個(gè)性化需要修改CSS,弄了一半因?yàn)楣ぷ魈o法進(jìn)行了。

Wordpress博客實(shí)現(xiàn)前臺(tái)快捷發(fā)布文章的界面

WordPress博客實(shí)現(xiàn)前臺(tái)快捷發(fā)布文章的界面

能不能有一種簡(jiǎn)單的方法,可以直接在wordpress首頁(yè)發(fā)布文章,免去繁瑣的后臺(tái)登陸呢。記得原來有一款quick-press插件可以在widget區(qū)域發(fā)布文章。于是參考了下,把有關(guān)代碼扣了出來,并實(shí)現(xiàn)前臺(tái)發(fā)文。添加代碼的方式很簡(jiǎn)單[適用于所有wordpress主題],如下(需要添加的代碼):

1、找到你所用主題的index.php文件,在代碼最前面加上:
if( ‘POST’ == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == ‘post’ ) {
if ( ! is_user_logged_in() )
auth_redirect();
if( !current_user_can( ‘publish_posts’ ) ) {
wp_redirect( get_bloginfo( ‘url’ ) . ‘/’ );
exit;
}
check_admin_referer( ‘new-post’ );
$user_id  = $current_user->user_id;
$post_content = $_POST['posttext'];
$tags   = $_POST['tags'];
$char_limit  = 40;
$post_title  = $_POST['title'];
$post_name  = $_POST['name'];
$post_id = wp_insert_post( array(
‘post_author’ => $user_id,
‘post_title’ => $post_title,
‘post_content’ => $post_content,
‘tags_input’ => $tags,
‘post_status’ => ‘publish’
) );
wp_redirect( get_bloginfo( ‘url’ ) . ‘/’ );
exit;
}

2、 還是在你的index.php文件里面,在顯示文章列表代碼之前加上以下代碼(比如我的文章列表是:
<?php
get_template_part( ‘loop’, ‘index’ );
?>
我就在這段代碼之前加的):
<?php
/* 首頁(yè)發(fā)文代碼
*/
if( current_user_can( ‘publish_posts’ ) ) {
require_once dirname( __FILE__ ) . ‘/post-form.php’;
}
?>

3、在你所用主題文件夾根目錄下新建post-form.php文件,其代碼如下:
<?php
$user   = get_userdata( $current_user->ID );
?>
<div id=”postbox” style=” padding: 15px; margin: 5px 0px; -moz-border-radius: 10px; -khtml-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px;” >
<form id=”new_post” name=”new_post” method=”post” action=”<?php bloginfo( ‘url’ ); ?>/”>
<input type=”hidden” name=”action” value=”post” />
<?php wp_nonce_field( ‘new-post’ ); ?>
<label for=”title”> &#x535A;&#x6587;&#x6807;&#x9898;:</label>
<br />
<input type=”text” name=”title” id=”title” style=”width:60%; height: 25px; border: 1px solid #99afbc; margin: 5px 0 10px 0;” />
<br />
<label for=”posttext”>&#x626F;&#x86CB;&#x7684;&#x5185;&#x5BB9;&#xFF1A;</label>
<br />
<textarea name=”posttext” id=”posttext” rows=”3″ style=”width:95%; height: 80px; border: 1px solid #99afbc; margin: 5px 0 10px 0;” ></textarea>
<br />
<label for=”tags”>&#x6807;&#x7B7E;:</label>
<br />
<input type=”text” name=”tags” id=”tags” style=”width:60%; height: 25px; border: 1px solid #99afbc; margin: 5px 0 10px 0;” />
<br />
<input id=”submit” type=”submit” value=”Post it” style=”background-color: #DDD; border: 1px solid #333; color: #333; font-weight: bold; padding: 5px 8px;” />
</form>
</div> <!– // postbox –>

做完以上修改后,保存,上傳并替換服務(wù)器上原有文件(最好先備份index.php文件)。刷新一下看看?是不是可以在首頁(yè)發(fā)布文章了?

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多