|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 \; ]7 H# I2 ` z% V8 ~
1 h" C% N0 `2 F/ e2 T) p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持3 A% G1 B- d& E
& h$ t( g( c. n1 V3 N
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) m2 ], B4 J/ l! f7 G) o/ N% _
; z* V2 L! n: C方便实用 简单 何乐而不用呢- 9 V' W) t2 q/ ~
- <?php0 l; [1 F1 l0 ~
) u1 |2 [/ A j: l( m- define( 'ABSPATH', dirname(__FILE__) . '/' );; l: y( t; `! N5 y
- require_once( ABSPATH . 'wp-config.php' );5 V/ m9 P. p% C6 D5 R% h& J; i
- require_once( ABSPATH . 'wp-settings.php' );
, K' r0 }* H) C/ @- ]$ `* A3 u - require_once( ABSPATH . 'wp-includes/class-wp.php' );( j8 x! a' ^ `# R N
- require_once( ABSPATH . 'wp-includes/functions.php' );
. K- G R. D- u# y8 ^0 t; n - require_once( ABSPATH . 'wp-includes/plugin.php' );
" r- _1 a! J7 O* G( _, t8 ~$ q - $title = $_POST["title"];
( Q2 o4 a+ d) c, Z - $content = $_POST["content"];
1 L- Q# A: F7 Q) c( i% ]1 z - $tags = explode("_",$_POST["tags"]);
! c# B# s' K, v2 `+ u- L5 w - $cate = $_POST["cate"];
+ j6 ^3 m: P- Z* f/ W! {- X E - //print_r $tags;0 A% A9 W( l5 D% Q' |
- //0 @& z5 r7 C- w
- //. Q, ~+ ~* k- j$ s% K6 P7 q: v
- $wp = new WP();' D6 S! m S' s5 m! M
- $wp->main();0 Z1 x; j' t; p, t( U
- //2 o# a- C% Q. g: L
- $my_post = array();1 H) F. @$ M7 k3 f8 m
- $my_post['post_title'] = $title;* ?( A* m3 g# v* m7 t
- $my_post['post_content'] = $content;
. Z* g, U* F6 C9 {. z% i - $my_post['post_status'] = 'publish';
9 p% T, e7 i+ ? - $my_post['post_author'] = 1;0 ]. F+ a# O! W* x: }' u+ ~/ G
- $my_post['post_category'] = array($cate);
* e: T5 a1 j7 L - $my_post['tags_input'] = $tags;/ p. s3 h% V+ ~
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ l! [! P: O+ v* _ - //$my_post['post_status'] = 'future';2 Z1 r7 Q* e* ]3 L) }9 M. b& J
- ////$my_post['post_date'] = '2010-07-04 16:20:03';& y: C; M4 v9 Y
6 H& U0 R: n" |0 r2 c6 e- // Insert the post into the database
" m7 x; F2 F2 m; i - $ret = wp_insert_post( $my_post );
2 K% k! G' {$ q - echo $ret;0 B$ `) A) g! x% r
- ?>
4 ^% c9 s' h8 B: D9 L) U ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! p& }/ L$ a- @8 I- |& y; s- <?php
9 A0 W% Z; N0 Z6 G; _ - define( 'ABSPATH', dirname(__FILE__) . '/' );
! S5 z# x6 }$ U* I. G+ z - require_once( ABSPATH . 'wp-config.php' );
7 S ]8 S7 T) l1 X5 I - require_once( ABSPATH . 'wp-settings.php' );
+ K& w2 b) d' u8 w- u4 v9 P/ V* ` - require_once( ABSPATH . 'wp-includes/class-wp.php' );
# L; r; T+ u X/ K* t/ n8 l - require_once( ABSPATH . 'wp-includes/functions.php' );
# M+ @" w( q6 T3 A - require_once( ABSPATH . 'wp-includes/plugin.php' );, b. w: ^# a" _* l- ?" u3 `
- $pic_name = $_POST["pic_name"]; o/ s7 R8 ] \! m+ H& O: f
- $pic = $_POST["pic"];
6 b6 L5 q7 d4 m; H0 E1 r - if($pic != "" && $pic_name != "")
, J8 D4 t; I! U8 F - {
7 E4 H1 ~; J, I - $path = "images/";/ \* P0 E3 R0 n! {/ F0 X6 x3 t6 B5 E
- $pic_name = $path.$pic_name;
7 t! i# x( W' P - echo $pic_name;
0 n: [& `/ d: b7 p3 z - echo "||";8 K# k! N4 C k: ^! W
- error_reporting(0);% y r: E9 U6 A; Y
- mkdir("images");1 x# b; B0 ^( v- T( f1 G
- $handle = fopen($pic_name, 'w');
2 Q0 K7 q6 M3 F0 y - echo fwrite($handle,file_get_contents($pic));) m2 j1 h0 ]" x8 L3 o, g8 R, J0 ]
- }
4 `4 N8 @) l8 ? - ( J. r8 w6 \* F; O) f5 y5 ]: J. q4 h7 z
- $title = $_POST["title"];
6 t7 q: e' [0 ^8 ^9 s - $content = $_POST["content"];
' O, I6 i" A8 s* c r - $tags = explode("_",$_POST["tags"]);
+ |* z: |; v: u+ h$ s& u) S L2 U - $cate = $_POST["cate"];1 W2 {6 S& P& R
- //print_r $tags;
2 v. @. a' ]6 I% L% w - //4 i) Q7 Q7 a9 S% z S: _+ w! b7 N8 ~
- //
3 `6 p& r3 W2 f6 y6 i7 q+ ~ S - $wp = new WP();
1 V3 B1 T8 x5 v- {0 q9 F: c - $wp->main();1 m$ _; [7 O" d8 t: |9 z
- //3 X. o1 S: a% Y: f. u* s9 t$ l5 m, ]
- $my_post = array();8 n+ j- O9 f9 d3 H5 Y1 |
- $my_post['post_title'] = $title;8 C- J& e/ Z4 J: X( D* u1 b: d
- $my_post['post_content'] = $content;
& l& U2 e, K( r; n: h3 A9 S- F - $my_post['post_status'] = 'publish';' D- }4 w6 L" \2 W9 V+ g0 _
- $my_post['post_author'] = 1;
0 g2 S; T6 n3 m5 V; d; E) j - $my_post['post_category'] = array($cate);
3 O, R7 L6 A9 T1 D- j) } - $my_post['tags_input'] = $tags;+ H9 S: ^: y9 `" i" o
- //$my_post['tags_input'] = array('tag1', 'tag2');: g$ g3 o) Q! F1 U, O
- //$my_post['post_status'] = 'future';/ F7 o- c( p9 j6 F4 C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';) v$ |9 r) _: T6 x" V H
- - [6 l9 \8 w- R2 Y
- // Insert the post into the database1 X$ j0 J6 Y: ]0 i" J+ J' n, H
- $ret = wp_insert_post( $my_post );
- h; a8 i7 u3 `+ p - echo $ret;
' R8 E8 D5 F l - ?>- L) X0 ?7 S6 X( x+ Q. M
复制代码 我自己写的
' Q$ N4 Y6 r& b% c插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|