|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' H* z% }, a) D
! O y( }7 \$ \) W2 `6 i5 T: D直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 p1 ~7 o' e/ }( f
! Y" a: S7 _ d9 o我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) f* s" P0 y5 D" [$ M
h L- I! H6 f9 X方便实用 简单 何乐而不用呢
3 v; I* X8 o2 o, K- <?php
1 q B+ Z9 K3 w+ v; T
6 d% a1 _. v( v9 ] `- define( 'ABSPATH', dirname(__FILE__) . '/' );
8 A& X* }+ h8 q" ^" A7 }0 L - require_once( ABSPATH . 'wp-config.php' );0 Y L; F) w, b+ e; o; t% _
- require_once( ABSPATH . 'wp-settings.php' );
+ q8 E( X4 v+ @; ?! Z3 q: r* P, e' ^! { - require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 V( r/ E! p: _/ z% ?% V - require_once( ABSPATH . 'wp-includes/functions.php' );
+ G, j7 c5 e& X- ]4 B& g - require_once( ABSPATH . 'wp-includes/plugin.php' );
* L: j; r1 f% j - $title = $_POST["title"];
. s2 Q: o* X7 u$ x, d' _& ` - $content = $_POST["content"];
" K: y" W, B) \ - $tags = explode("_",$_POST["tags"]);, J, c5 ]0 i4 B/ B
- $cate = $_POST["cate"];9 U. L7 r; x3 z: e) I
- //print_r $tags;
7 K. k9 F+ F) [0 f - //8 _8 ?$ r5 e- u
- //
8 q4 A! m7 l- H- H: m* m" y* M - $wp = new WP();
3 R) O q( v1 k ^9 { - $wp->main();" {+ b- S6 M9 S( g2 M: `9 k7 j: |
- //$ F+ I4 E0 F! ?
- $my_post = array();
; `1 } v9 A+ L2 x9 m# a - $my_post['post_title'] = $title; S# ^, k. `$ U5 M
- $my_post['post_content'] = $content;3 N* j# Q0 N6 l% }" p- t5 X
- $my_post['post_status'] = 'publish';
9 `5 x+ f$ F8 X, f u9 K! j - $my_post['post_author'] = 1;$ T! g$ H2 _: G+ B/ J
- $my_post['post_category'] = array($cate);6 J. v6 b: W* _' }. M! [) U
- $my_post['tags_input'] = $tags;8 _: i: z: T) x# k
- //$my_post['tags_input'] = array('tag1', 'tag2');; q: p' W% Y& Z
- //$my_post['post_status'] = 'future';
' ^# X4 E: `! E4 V - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( T# i/ f8 F2 o: q5 Y0 {3 {2 j; Q
* z5 M, F% }- w- X- // Insert the post into the database
1 X) Q) y) c. n' E - $ret = wp_insert_post( $my_post );( R: Z0 f8 l$ G
- echo $ret;
6 T& D4 q8 M' b) ~. [1 b - ?>
3 L- E Q( E) h: U. S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 z) P+ w) x* b- <?php& X. n8 b1 @2 @$ Z& t9 a
- define( 'ABSPATH', dirname(__FILE__) . '/' );
" y$ I, n' N# m/ r, {( N! ` - require_once( ABSPATH . 'wp-config.php' );
* T8 }6 X3 q7 i# \% _% r% |& G4 l - require_once( ABSPATH . 'wp-settings.php' );$ d @% R7 n1 c. c: N6 W& _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );! y T6 \+ P$ m j+ _: b5 X
- require_once( ABSPATH . 'wp-includes/functions.php' );' Z( J" I1 {8 s1 r7 \
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 n$ {; J2 Z' f9 E7 f
- $pic_name = $_POST["pic_name"];
Q8 T9 r; _# U! P4 e( P" a. U7 b+ X - $pic = $_POST["pic"];
8 p7 X9 @$ \ O' G$ U4 D" g+ u - if($pic != "" && $pic_name != "") ]; @5 p3 }: a# ]
- {0 P) B9 X6 ?4 F& c" H1 w+ ?4 `% g* L
- $path = "images/";6 y3 X! L1 u& N- k) }& H0 h" T" g2 {: O
- $pic_name = $path.$pic_name;
. Q4 O2 X7 b X7 K - echo $pic_name;
( n0 b7 t/ a! ^ - echo "||";
. y+ a! ?) ]; E6 X0 t' `7 S4 c - error_reporting(0);
2 I4 n' F, V: \1 z, i7 W8 k0 Y - mkdir("images");' n$ [5 |& j/ ~
- $handle = fopen($pic_name, 'w');
7 b" \3 P# j( y+ q! m - echo fwrite($handle,file_get_contents($pic));
7 z; W! O8 ^; m* v1 M - }
k* Z; j L# x' ?
8 L3 l. z4 z6 a/ K- $title = $_POST["title"];
9 S7 z- Z$ ~3 S. e - $content = $_POST["content"];4 ?1 ]: t1 y# V0 Z1 q% q
- $tags = explode("_",$_POST["tags"]);$ p) D g, K) \/ D3 n2 y/ s- b) j
- $cate = $_POST["cate"];& c) a6 Z$ Z& I q* i
- //print_r $tags;
; e( K$ j4 _* ^( ?# Q: M: ?* ? - //
* m$ o% m- |! p" p - // S7 l% o9 A* `
- $wp = new WP();# j) J, ~8 D+ y0 Y
- $wp->main();# T# v' L* Z# `- ]7 B, k& A
- //
8 O6 N, t2 r; C; K - $my_post = array();" V) J- E( D/ S$ e
- $my_post['post_title'] = $title;, m& \; @3 h. [! k
- $my_post['post_content'] = $content;
# ^. U# x8 Q$ G, a6 x( Z - $my_post['post_status'] = 'publish';$ S" ~5 Y% u2 F Z2 [# F' R2 l B
- $my_post['post_author'] = 1;: h% [, _6 i; G% s, B: Y
- $my_post['post_category'] = array($cate);
8 z, E8 d6 k5 l. v" g( D- X - $my_post['tags_input'] = $tags;) C. x& a, n* G% x, C, l+ v6 q
- //$my_post['tags_input'] = array('tag1', 'tag2');
" P: Q# y* S5 q* H5 L- i - //$my_post['post_status'] = 'future';& q2 x( R3 p. e R8 i" a
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
% a/ O1 s& k. T1 a1 q- h0 f0 {
. |. Y8 d8 E& `1 Y- L7 Z! g n- // Insert the post into the database
) r1 z; H, n+ q7 k* y& S - $ret = wp_insert_post( $my_post );
5 i" B" a7 f% b( w" v; b* M- q - echo $ret;' i: p& v$ m/ J# } ^5 x
- ?>
$ ~( E+ `5 `" Y- O
复制代码 我自己写的: r; M- Z0 c: ^% U2 h
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|