|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & S) B3 R" `8 u, h' f
# H' h; d( K! Y/ }
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
7 f' ]" p( g# n2 D% C% V: L* E6 G7 `% v3 o5 N
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' t! `! S7 f, w! e, a4 v, _: z& I
) x' I; ?: i* h7 H4 j方便实用 简单 何乐而不用呢
1 g: b4 Z' [% U! l4 {- <?php$ ?3 O; d5 Q' z& L' f4 c
- 7 M7 P% v+ |2 P5 Z* I
- define( 'ABSPATH', dirname(__FILE__) . '/' );6 g' S, `: @2 E. ^; o1 O: P+ b6 n
- require_once( ABSPATH . 'wp-config.php' );
1 H3 ]$ Y1 r& q; j4 | - require_once( ABSPATH . 'wp-settings.php' );/ V# l. U8 ~! R0 q/ [
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
* [! H) _* V/ {& ]) {# Z - require_once( ABSPATH . 'wp-includes/functions.php' );
8 R6 ^: ~) W4 `! W - require_once( ABSPATH . 'wp-includes/plugin.php' );3 o& N# H. y- ^" O+ Q2 ]3 v* n
- $title = $_POST["title"];4 ~1 ^2 Q5 V. H3 f: K
- $content = $_POST["content"];
$ F& l' G& i+ x1 D( G0 f M - $tags = explode("_",$_POST["tags"]);3 @ s) q3 o: T8 p3 w8 s
- $cate = $_POST["cate"];+ P/ v( n* @3 k/ l
- //print_r $tags;5 Y5 H9 K: ~ S$ t A
- //" |1 ?' e) l+ H% H! R) n
- //( x7 x0 h% B7 f C
- $wp = new WP();8 ~2 s4 V8 x0 c& o Y* `) L
- $wp->main();& ]: G# _* T9 ?% D* q7 u: r
- //7 r3 x _* E! L) q2 j
- $my_post = array();. k! W/ i8 P; G, V* e* L
- $my_post['post_title'] = $title;
' F/ M% k2 I2 P% d" t% V/ { - $my_post['post_content'] = $content;
* [+ [5 E# B. x+ ^! P$ p& p" R. ]2 a - $my_post['post_status'] = 'publish';) t. |! j# e3 f+ U
- $my_post['post_author'] = 1;, G( v' d8 n$ b8 \$ u
- $my_post['post_category'] = array($cate);
& d% |2 G( I/ x7 B5 W3 Q - $my_post['tags_input'] = $tags;
; h `# c! s; [9 P - //$my_post['tags_input'] = array('tag1', 'tag2');3 M x; y3 c3 U0 S# }# a
- //$my_post['post_status'] = 'future';
/ C5 B( |; L" J# k - ////$my_post['post_date'] = '2010-07-04 16:20:03';, `- y) T+ K# H7 R: ?
# e; F4 I2 W3 L* D- f, J/ T6 x- // Insert the post into the database
7 J* b# b- _1 c4 z# q5 l& p* f - $ret = wp_insert_post( $my_post );
4 K8 @% N5 {% x: K6 t - echo $ret;1 X$ {6 o) D, ^: n, ^$ j
- ?>
# [, o9 A* u, }
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; N/ T1 ]( u( A# V/ {! ?
- <?php0 e' B' A) S6 Z: t
- define( 'ABSPATH', dirname(__FILE__) . '/' );& ]8 b- I- R6 G: r; V- ^
- require_once( ABSPATH . 'wp-config.php' );
( F3 O# Y. W% R, f: N' }& r" Y - require_once( ABSPATH . 'wp-settings.php' );; u: |6 _, V* g" p$ G9 {" Q& I
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
* R$ i, U, ^! l$ k1 ]2 s5 l7 _) D8 J - require_once( ABSPATH . 'wp-includes/functions.php' );
. t5 L3 Z% R& k; p4 c - require_once( ABSPATH . 'wp-includes/plugin.php' );9 b; \( U# C+ ]) T9 V0 d1 l9 x
- $pic_name = $_POST["pic_name"];
5 O" ` X5 R+ |" @" H" M; w. [ - $pic = $_POST["pic"];% l" y9 J1 y8 _+ C
- if($pic != "" && $pic_name != "")
4 l2 C, Y( \ c! ] - {( ~1 A* B% v+ \( s" J
- $path = "images/";
7 H9 c' Q) f: o. ~. L" z - $pic_name = $path.$pic_name;
_' u8 ]6 a; w - echo $pic_name;
1 h( S A" n2 A$ \ - echo "||";) I1 F! f5 p7 w6 W
- error_reporting(0); V* l- i2 H; F* n; f+ `, V! @9 x1 f
- mkdir("images");' K8 v/ W/ W ~) f0 |
- $handle = fopen($pic_name, 'w');7 {! \% z. I9 O
- echo fwrite($handle,file_get_contents($pic)); ~7 m4 n: g2 K) r5 d9 B
- }
9 q1 \4 m2 t8 ]" U" O& \$ q - , K5 b3 V0 ^3 e
- $title = $_POST["title"];
: n1 | q# W3 q& ?2 G4 T2 N - $content = $_POST["content"];
i! ?( y% O' n" } C% j5 V - $tags = explode("_",$_POST["tags"]);& Q I* N" O# v
- $cate = $_POST["cate"];
3 s; `1 R# m9 q# t0 n - //print_r $tags;
+ _7 |: K( A z: H" x - //9 j! z# n; k. S, _
- //: m, g/ T0 f$ D
- $wp = new WP();
+ ^- ]; C% D, _. c& @, X* g' D6 M - $wp->main();
1 o7 {) n- B+ d0 }# K - //; Y* Z9 [% B5 k) f: F0 p: l. _. d
- $my_post = array();
. T0 b' }# ]0 `9 a. l! @ - $my_post['post_title'] = $title;+ f' ?/ O4 `' {( _: ]. v5 d
- $my_post['post_content'] = $content;
- q! d9 D# {2 U' V0 i, M- R - $my_post['post_status'] = 'publish';
O" ]3 K9 L; I6 g; j+ c - $my_post['post_author'] = 1;
2 B! X% g) C0 N3 b* K1 V$ F* ]) x - $my_post['post_category'] = array($cate);
8 ]" }8 ]1 e C# | - $my_post['tags_input'] = $tags;# D2 s; h4 ]1 \2 P
- //$my_post['tags_input'] = array('tag1', 'tag2');
5 Q) k/ o5 i) b; d+ \3 a+ x - //$my_post['post_status'] = 'future';
% \( K- e7 V6 d* m/ p - ////$my_post['post_date'] = '2010-07-04 16:20:03';' p: }3 R. J% A/ P, Z
- # a9 k: J2 W8 J% p$ K4 O
- // Insert the post into the database
: W* K- m# _8 n, G0 L' L0 D/ x( T - $ret = wp_insert_post( $my_post );# H, ^* t7 d$ \* o
- echo $ret;' T( C" d I0 L: e) ]5 j
- ?>
5 n' `0 _6 v, Y2 y
复制代码 我自己写的
! m; p& G3 h l& S" P插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|