|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " y1 p% c/ m" c2 \0 C
/ ^8 t1 v9 S8 i7 m
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
/ ~$ {+ }; p" _7 c7 ?+ @6 l4 H- y' o* | x8 l+ ?! I
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 w1 I$ s1 f1 [$ s, g: U
$ q. C. z* N) F! ~ P, W0 s% f8 S1 A
方便实用 简单 何乐而不用呢- 8 s: G7 y! @ w! `
- <?php1 ^# E+ g; _/ G% r
- . r% X( Z( ?( N2 g& U& R
- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 J: Z5 Z6 M' L+ \* M" \ - require_once( ABSPATH . 'wp-config.php' );$ A( `# o3 D# X! E% n
- require_once( ABSPATH . 'wp-settings.php' );: J2 k, J! A( i* Q! r
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
' v1 X, V4 {$ a8 @% R - require_once( ABSPATH . 'wp-includes/functions.php' );
0 R/ a, f q2 b% n6 |. M$ D - require_once( ABSPATH . 'wp-includes/plugin.php' );9 n1 x! J5 }3 d2 D5 `* B; |2 ^5 f
- $title = $_POST["title"];
6 D5 P, n9 N+ p) L" N4 d3 h2 o - $content = $_POST["content"];
$ }! c* H+ ]. R. p( `; C - $tags = explode("_",$_POST["tags"]);$ g0 l' |# m P: |1 j- `
- $cate = $_POST["cate"];3 q J" p! g: j5 ?
- //print_r $tags;4 N7 g% d Q$ e
- //+ B* U) [1 E1 V$ L
- //* a( ~- J6 \5 g( g5 i7 v6 W2 [
- $wp = new WP();3 f2 t4 O) W! o; r$ P B( }
- $wp->main();
- D& b9 \* g3 G# M0 H* B - //. J. \9 n3 b2 I3 M, p B5 e
- $my_post = array();
- C* Q. g/ t4 R) G, p% \ - $my_post['post_title'] = $title;$ j& b! K2 b: M7 _
- $my_post['post_content'] = $content;
4 B- [& R! ~1 I# F7 J) Z2 J( _; y5 W - $my_post['post_status'] = 'publish';
# i1 J5 q) r3 m Z - $my_post['post_author'] = 1;
X- x2 _( r! K# i - $my_post['post_category'] = array($cate);( L8 _7 P: `9 U
- $my_post['tags_input'] = $tags;
9 H: P# c5 ^* p$ i9 z - //$my_post['tags_input'] = array('tag1', 'tag2'); F+ ^3 W2 i* y1 O
- //$my_post['post_status'] = 'future';$ T( C& P- O7 P
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# f4 p& `# N6 ^1 w I
- X7 f/ n- O& N- // Insert the post into the database
) V/ x" p7 N; m% x! G0 w1 V - $ret = wp_insert_post( $my_post );
) e8 z+ x5 ]5 i - echo $ret;
; G& o0 Z" M- y S' p - ?>
: W/ U* V$ [3 G2 S/ w2 \
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
E# S2 [. }' h2 k- <?php
" j0 A% w: d+ F+ |" d- j, ?8 A - define( 'ABSPATH', dirname(__FILE__) . '/' );( ?& p' c G8 t, O8 |) v" \
- require_once( ABSPATH . 'wp-config.php' );
5 s: z* x' }: ` m - require_once( ABSPATH . 'wp-settings.php' );
; T' T" ~3 B& V - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. i0 Y2 p+ z9 o% C - require_once( ABSPATH . 'wp-includes/functions.php' );
) }& `. u2 P2 s j* }* M - require_once( ABSPATH . 'wp-includes/plugin.php' );* B% i1 D( G' q# U' [! b
- $pic_name = $_POST["pic_name"];
( d) A, i' I+ Y; \ - $pic = $_POST["pic"];" |- c% D* P8 x1 N
- if($pic != "" && $pic_name != ""). A8 ?$ n+ g9 ^
- {
3 y& i4 W z- i - $path = "images/";( @+ u" a; r0 k ~. A
- $pic_name = $path.$pic_name;
& _5 C3 e( D' T+ f5 `3 b - echo $pic_name;
7 X5 O& P$ Q$ v. q0 j - echo "||";
r$ f- U1 X' R4 {% { - error_reporting(0);
& A: k( b! L3 D" V' r+ j3 I - mkdir("images");
; u6 p" j% b# z0 o! N - $handle = fopen($pic_name, 'w');6 E& E- N# J1 @6 R2 S
- echo fwrite($handle,file_get_contents($pic));
6 g/ v* a5 M* y5 H; z - }
$ ]" ?. S* D# v U
, T7 G5 b, r* l' X) z' Y$ R- $title = $_POST["title"];
: B& ~; i! ~7 k2 o- u - $content = $_POST["content"];
+ r& ^6 `: t3 b. H* Z" ^4 H/ u0 P0 ~ - $tags = explode("_",$_POST["tags"]); e+ l8 {( W/ q* P4 R+ D" o& _
- $cate = $_POST["cate"];
2 h4 R0 M; a" Q" Q9 X- U8 c - //print_r $tags;
( s0 R- F! j9 C0 [3 F! r - // Z. g1 u* V# T' o3 b& ]# r
- //& {/ H7 s# V0 {2 ^
- $wp = new WP();) k3 v: x, M7 u+ R! m
- $wp->main();% C5 j, l- R$ W) o' }
- //9 [7 O9 A# A- E4 U* ^' U8 T
- $my_post = array();/ P# a, J) ^8 ?+ K
- $my_post['post_title'] = $title;* H# A, R8 W9 ]
- $my_post['post_content'] = $content;
- d! _ ^1 x! ^. E5 S' g - $my_post['post_status'] = 'publish';, x0 y# [% ]$ Y" \# v
- $my_post['post_author'] = 1;/ T+ }8 b5 C4 u1 }" K
- $my_post['post_category'] = array($cate);
0 s# @1 p4 U; U( \ - $my_post['tags_input'] = $tags;6 b6 b) m& H7 H4 [, X
- //$my_post['tags_input'] = array('tag1', 'tag2');2 h" s& E+ Y5 D) C" _. F& y
- //$my_post['post_status'] = 'future';
$ C2 I! b6 U9 B t - ////$my_post['post_date'] = '2010-07-04 16:20:03';& Z: L/ R- z$ [0 P8 M' R' O( o7 w
2 R" ~8 ]: h4 X* Z- // Insert the post into the database
+ g3 e) v5 `* v+ k6 G# \- ` - $ret = wp_insert_post( $my_post );" H+ @# F2 I4 ?6 M
- echo $ret;/ k* y. E7 [8 {# h. q" j) M! H
- ?>$ N2 ]: X( Z" i/ e( D9 Q7 K+ c
复制代码 我自己写的
1 |0 W+ g& ]/ [' s插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|