|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. i4 C {1 ]% M8 Z
8 B, K4 m7 i, c% _直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. m0 A" ?7 R+ R+ y# R
& @$ F# `! q S我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) ?& y, Q- U! V& S: ^# B
% M9 v8 j+ X6 v4 U1 Q. x方便实用 简单 何乐而不用呢
& O* }! Q% q' s7 h T- <?php
" B) P! E v, z* Z - - L5 ^* ? L' j0 `
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 |4 B" b# ]7 W Q6 Q - require_once( ABSPATH . 'wp-config.php' );$ `* Q- o0 P1 i% a7 a6 q% W# I
- require_once( ABSPATH . 'wp-settings.php' );+ F4 W3 k/ m: a2 b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 T% k Y# B8 J4 k* l - require_once( ABSPATH . 'wp-includes/functions.php' );
1 y. e- I4 j! }' U, Q+ N/ X - require_once( ABSPATH . 'wp-includes/plugin.php' );7 X+ M& ^# |: W ~+ R& l
- $title = $_POST["title"];$ u. u$ A9 ?$ j' s& B Q
- $content = $_POST["content"];- L6 V" @* I- q8 W' [* D: L
- $tags = explode("_",$_POST["tags"]);/ [+ m) U4 [: l/ L3 M6 \
- $cate = $_POST["cate"];$ X; {- O' a/ R$ s
- //print_r $tags;+ @6 N A! u8 Q7 a' i
- //& W5 |( u2 N, h. v1 A
- //; _* v6 { c6 ?5 b9 n
- $wp = new WP();# `- N" Z0 d$ _
- $wp->main();$ X% q" k& v4 p. q
- //
~; `# c2 c3 _ - $my_post = array();
4 f! a' g5 }3 u8 X5 ]( s - $my_post['post_title'] = $title;) t p/ e: ]+ }0 m- ^0 ?
- $my_post['post_content'] = $content;
# j( `. p- M& o6 e) P0 i/ r4 ? - $my_post['post_status'] = 'publish';; l) }; `4 o3 w2 \; d1 R. N
- $my_post['post_author'] = 1;, E; \$ x1 G3 w$ `$ X K U
- $my_post['post_category'] = array($cate);- H! u: f9 t3 o8 }
- $my_post['tags_input'] = $tags;
) Z {$ e/ b! O& O$ T) @ - //$my_post['tags_input'] = array('tag1', 'tag2');
- f" H8 X. M7 T, K4 u - //$my_post['post_status'] = 'future';
5 G2 F" Q% c- ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';( `2 X3 l( M7 c1 L% h3 a( l
/ x: I$ m9 p4 d* Z- // Insert the post into the database
" q2 A: m, F% n, t% G - $ret = wp_insert_post( $my_post );% k8 ^' M* a- z! Z8 e; L& k
- echo $ret;
& ^5 N# q- C' C1 d - ?>) x& |( K+ f0 c# h0 N8 c( e
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- # p0 P6 t: M4 S$ g. \' @
- <?php" W. l' Z8 o+ V" Z$ B* P U; }% D2 f
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 `/ M1 ^2 R" \. |. D2 ]
- require_once( ABSPATH . 'wp-config.php' );
# ?6 |0 g: |. t* q - require_once( ABSPATH . 'wp-settings.php' );9 a# q+ [5 w4 E% f. O: ]- g
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ j! g! j; x0 H% ?# d! u; d$ U; t - require_once( ABSPATH . 'wp-includes/functions.php' );
9 |2 n ^" f0 n! m - require_once( ABSPATH . 'wp-includes/plugin.php' );& x0 \# I% M/ g; f5 r0 A% F) U
- $pic_name = $_POST["pic_name"];+ a7 d/ S5 O4 K
- $pic = $_POST["pic"];
% u% O0 F" H5 a6 M% E% ^/ k8 W - if($pic != "" && $pic_name != "")
- H; _* x% ]1 C( m/ ]/ @ - {
* D* E1 o# Y) B: @. D0 _' u - $path = "images/";
( O* V+ ~% p, r- u5 _8 O5 A - $pic_name = $path.$pic_name;( x8 `4 K* O/ |0 n5 z, E$ y! G
- echo $pic_name;& m2 Q" V) n* ~
- echo "||";
9 K# w' h; I, y2 R - error_reporting(0);
( h8 H6 b# B. m3 ^ - mkdir("images");1 ^8 X* f3 f- z
- $handle = fopen($pic_name, 'w');
& _; O* d7 L! [ - echo fwrite($handle,file_get_contents($pic));
7 I- {1 |, h! G$ T& U. f - }/ ^$ W% a$ a& Q- J7 U) V- y
- 9 H! t3 ]8 D2 A! G3 p) m q" |
- $title = $_POST["title"];
. b. o/ o7 O' b$ d6 K$ J* `7 y - $content = $_POST["content"];
: s. r; \# {9 J9 ?1 D% g- Z/ E5 \9 q - $tags = explode("_",$_POST["tags"]);
1 G# B6 ]7 _8 |5 t: n5 ?0 k$ o - $cate = $_POST["cate"];
2 }, v, D7 i6 Q+ I6 I& d/ i - //print_r $tags;+ H4 d, o; g; I# l( S' d
- //& i! [3 O: v2 w: k0 {
- /// f6 Q7 p' A' g* t
- $wp = new WP();
+ ]0 l; g# F' O1 u - $wp->main();
8 Z; n4 L7 u; R$ }9 x9 C: R - //
( ]4 o. q2 p7 w- y - $my_post = array();# M- E b8 W# W# M' O+ W# G
- $my_post['post_title'] = $title;4 s0 n" T4 Z, _% [
- $my_post['post_content'] = $content;
. K; r# w- G0 a$ |9 A - $my_post['post_status'] = 'publish';* X6 q6 t8 l1 F& m; G0 l5 m5 C) o9 Y
- $my_post['post_author'] = 1;( |! s1 K4 ~2 n" v: s
- $my_post['post_category'] = array($cate);
$ ^- K# i/ ?2 _) d - $my_post['tags_input'] = $tags;
4 F# ^* Y. ^3 v0 X2 M - //$my_post['tags_input'] = array('tag1', 'tag2');* q: r% {4 B! ]1 n' V* [$ B3 X
- //$my_post['post_status'] = 'future';
% u, N' q- H+ i Y2 ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ p- r9 T c8 C8 R. a- H
4 j/ Y1 z6 C2 M! w% R/ j% [/ V% p- h- // Insert the post into the database) }. A1 P# O& w0 @% Z' a
- $ret = wp_insert_post( $my_post );# f9 j3 @* e( r# T3 J$ w; \
- echo $ret;
6 p% p" r& L) ]- a/ W v - ?>* T; N4 d4 Q1 o+ @
复制代码 我自己写的
- A3 ]) u) J1 W- b插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|