|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
+ F1 V, X& N9 v# h4 N
* a1 s& c4 G7 k5 |# N4 a' p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
0 g4 w! J* D9 Q- z: \! [: p" c& _: f" H6 m& b# Q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
# v# ~- J$ x* M9 H7 N2 z* @- Y/ ?$ }
方便实用 简单 何乐而不用呢- & W {" Y, }4 X, O$ D3 F( _- l. u
- <?php- {* `+ e% k2 ]% t3 H; ^
- 6 w6 ?+ s3 r+ c) m9 N3 r
- define( 'ABSPATH', dirname(__FILE__) . '/' );% y/ N" T% h7 b/ H3 U
- require_once( ABSPATH . 'wp-config.php' );
5 v8 j& C2 r7 S$ H( n: g - require_once( ABSPATH . 'wp-settings.php' );! G# F4 W. h' U+ I+ i. T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 ~, g" M6 |0 ^- T* G7 m2 x: ^ - require_once( ABSPATH . 'wp-includes/functions.php' );$ _0 X, J1 g& {0 r. A
- require_once( ABSPATH . 'wp-includes/plugin.php' );
/ ^- g5 j \0 F) ` - $title = $_POST["title"];5 F T. k1 }$ k4 Z% z
- $content = $_POST["content"];4 o& e' f9 k3 q# w/ X
- $tags = explode("_",$_POST["tags"]);
: o, v, ]& J4 l0 y7 Y - $cate = $_POST["cate"];% [1 u( ?4 r3 `( k, l
- //print_r $tags;
, a# S( ^' Y$ I# u# t: k( q - //& r$ u. i5 Y P: ]: X/ ^+ w
- //
% K+ C. @- d0 d# S. ~ - $wp = new WP();2 N( x& |9 W8 J( P. I# W- r
- $wp->main();* L4 M2 ~& F2 e
- //, T* E. H; R. u. R9 B; b
- $my_post = array();
' P( ]* ?! o. _ - $my_post['post_title'] = $title;
) }/ }2 |$ Z* B4 _8 B5 b+ p- u - $my_post['post_content'] = $content;$ q& c& U: m3 f* p) d. ^9 J0 k, M& Q
- $my_post['post_status'] = 'publish';
6 J+ n- y, K6 F, {7 r - $my_post['post_author'] = 1;
. _7 U' H0 u9 m9 g - $my_post['post_category'] = array($cate);& s$ @' ^) x, n: v
- $my_post['tags_input'] = $tags;7 w/ ?) Q9 _$ \
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 U2 @3 J, D1 K - //$my_post['post_status'] = 'future';
, U' V2 }) l5 h$ k5 V, n; Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';: a6 E$ U. a2 x7 ?2 G% g; b6 b6 h
- 2 v( P/ F7 a$ w4 ?
- // Insert the post into the database
7 t9 T$ }! D$ a0 o - $ret = wp_insert_post( $my_post );, |% {( h+ q6 s8 d3 P' ?6 i3 f
- echo $ret;" ^* a7 M: v/ |/ N7 M9 m; O
- ?>
$ b7 P- X+ M. t V1 s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; Z; X$ O* M' f* ^2 k+ C: _
- <?php( D: @+ s6 f: L! o$ N: j# v. f
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ H. h2 [5 }$ b1 b. ] - require_once( ABSPATH . 'wp-config.php' );
6 N9 u* F0 a- z8 Z2 @+ V& J - require_once( ABSPATH . 'wp-settings.php' );
, T: a, X6 \, J% L0 x+ _' o0 @ - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 k; I1 Z0 q3 i) O6 H: N
- require_once( ABSPATH . 'wp-includes/functions.php' );% \# j" a1 B* ^; i3 G) Q
- require_once( ABSPATH . 'wp-includes/plugin.php' );: K+ M+ t- I" c1 y) X, s/ o
- $pic_name = $_POST["pic_name"];/ F. L6 N# v9 e2 b4 N
- $pic = $_POST["pic"];( T$ K5 O% O4 Q4 t0 q4 b7 ?
- if($pic != "" && $pic_name != "")
{/ K6 c N7 T- n% w) b- K2 d - {# x' d1 }2 `. ]8 m9 B9 k
- $path = "images/";0 k0 t) v- Y3 G8 B
- $pic_name = $path.$pic_name;" b4 w5 z" b1 z' Y1 E
- echo $pic_name;
) I+ L( w4 T4 Y, W - echo "||";
" l& U9 m( \- w. |& }' B - error_reporting(0);
6 {9 @- Q" h# C& P - mkdir("images");
; Y; C6 {% l. @' n/ H, s: Y& }, w - $handle = fopen($pic_name, 'w');4 l! }/ x0 V$ x" C4 g4 l1 W6 l
- echo fwrite($handle,file_get_contents($pic));; X9 o- G$ W/ C8 N
- }- u+ z, x4 B9 I& z& E/ S
- - d$ @5 p3 y6 ]
- $title = $_POST["title"];
Z9 q4 x. G# Z* I+ @ - $content = $_POST["content"];
% e6 l1 Z: |4 L+ \( I - $tags = explode("_",$_POST["tags"]);
6 M% _" l, k/ }. L8 F. i& V4 _ - $cate = $_POST["cate"];% M) j0 v7 _! m& V& s! F, N) _6 S
- //print_r $tags;" G9 `/ o9 [2 l3 w4 m0 }; s, a
- //% h. ]+ v' S& B$ ]( G! j* m! k
- //
# @2 Y2 i) x& v3 l( |" ?* |% u - $wp = new WP();: W9 ^* Z, e9 Z0 `
- $wp->main();
4 n! M$ F( v# F B - //
+ L; M1 l3 m" z: }* E$ G1 w- M Y - $my_post = array();
$ z0 g: }1 O: K: ^ - $my_post['post_title'] = $title;
" e: d/ c* R' D3 x - $my_post['post_content'] = $content;" F& {; R4 s7 b# r
- $my_post['post_status'] = 'publish';
7 b" K& W5 Z: g3 i$ a - $my_post['post_author'] = 1;
& @' T. h2 e* q! u \ - $my_post['post_category'] = array($cate);
# h" y( ^, Z- z6 V. C - $my_post['tags_input'] = $tags;
" ]2 l8 C6 ~2 R4 ^- I, B( A - //$my_post['tags_input'] = array('tag1', 'tag2');
/ b9 }* g" m$ l0 ^! e3 p2 X2 `2 Z* W - //$my_post['post_status'] = 'future';
# M& y/ ?* Y, y% X) e - ////$my_post['post_date'] = '2010-07-04 16:20:03';5 h0 m& e' Z! t0 g* f" L% R
* d9 u5 f0 h3 F4 v4 o* ~, E- // Insert the post into the database
- B& l4 }; y1 d. H% p+ h. R2 M5 j - $ret = wp_insert_post( $my_post );! Q6 C% {4 c5 r- E
- echo $ret;
0 E3 W3 s- x* l& D0 q; C$ N( ` - ?>
/ _! l2 \/ B3 `
复制代码 我自己写的
0 q M" B3 ]& }* U; N插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|