|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
3 ^3 F( v& q H. e
& D$ n1 l: ?- g8 Y; b! {直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持1 b2 k0 H# l. d8 n/ t3 Z
9 z& [( y/ O$ \- z" y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
8 Q3 _2 U7 Y4 f$ N! t4 u3 c1 l# [7 c& y
方便实用 简单 何乐而不用呢
" |7 {3 l, D6 D* d( c, p6 M6 P- <?php4 l. c4 A5 T+ w8 Q
5 t# \0 P& b) M- define( 'ABSPATH', dirname(__FILE__) . '/' );0 Y7 s- v. t, f' D {
- require_once( ABSPATH . 'wp-config.php' );
9 N! n- r( U4 k# k - require_once( ABSPATH . 'wp-settings.php' );
5 P& l2 b `. I/ d. @2 w - require_once( ABSPATH . 'wp-includes/class-wp.php' );3 i& x0 A! E( O0 V1 [
- require_once( ABSPATH . 'wp-includes/functions.php' );
p# W* G1 j+ A ~3 X- c - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 l( |* @3 y) E, I - $title = $_POST["title"];
* n! ?: H6 C3 f! ]; X+ i6 D - $content = $_POST["content"];
; T: G+ C. `; ? - $tags = explode("_",$_POST["tags"]);) j9 o, K' g5 h7 J
- $cate = $_POST["cate"];4 h6 H/ z9 L( a9 r7 v
- //print_r $tags;7 a2 A6 @/ T% b$ T! E
- //* R* z" B5 r$ e7 t; f& k1 e
- //& @+ W$ E" k; b0 l: O# L) d
- $wp = new WP();) s9 m" p) [& `$ Z: b- b" y0 q+ g h
- $wp->main();. O* y2 L$ Z& l) L7 P
- //
3 u, G' N9 l, h6 H4 Z5 d) L - $my_post = array();
7 w% b& S2 ~( S e - $my_post['post_title'] = $title;0 S% o* Q% O. S, p8 ?' ~, k S
- $my_post['post_content'] = $content;5 x" w* M- q5 d. D; ?7 a* v
- $my_post['post_status'] = 'publish';8 G3 {$ P7 w l! `
- $my_post['post_author'] = 1;0 p; c, h8 m6 `, s& l, ?
- $my_post['post_category'] = array($cate);
! A' @% m1 \$ F/ n+ H: V ] - $my_post['tags_input'] = $tags;2 W. B( [( M/ Y- E7 M/ k
- //$my_post['tags_input'] = array('tag1', 'tag2');
# Y- V2 B8 j) `8 K - //$my_post['post_status'] = 'future';( w" ? J( v$ m' }* p5 R2 S
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' }5 }$ B" A. x& a/ J' G' E - : T+ F9 l3 T* c! G$ I
- // Insert the post into the database8 X. Q! f1 o5 E5 V: A+ C3 m
- $ret = wp_insert_post( $my_post );( f1 y8 ^9 ^ \! O
- echo $ret;
4 W/ J1 q& |1 D* o+ A - ?>+ b! f3 `$ o: Y6 r3 X1 f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 a7 }) q, z5 P) w( J* m: {8 a
- <?php+ K9 x. l9 k/ l1 |
- define( 'ABSPATH', dirname(__FILE__) . '/' );8 q+ o7 ^) J& l t
- require_once( ABSPATH . 'wp-config.php' );' K" j2 V2 }! e6 T
- require_once( ABSPATH . 'wp-settings.php' );
- K S# o7 v; ] - require_once( ABSPATH . 'wp-includes/class-wp.php' );
1 ~4 Q" g! k- p0 g - require_once( ABSPATH . 'wp-includes/functions.php' );3 O* t/ h3 N" a6 m# ~
- require_once( ABSPATH . 'wp-includes/plugin.php' );
1 U8 k) U" Q, w' v - $pic_name = $_POST["pic_name"];* n% H2 a& T% d7 q# ?
- $pic = $_POST["pic"];1 O7 V8 f, P, k: X( d. c
- if($pic != "" && $pic_name != "")
3 N! M0 c' v# S1 B0 M - {
" L& e% j3 R/ k9 R6 `) V! U$ w - $path = "images/";$ ^: a: Z2 L [" v- T! o
- $pic_name = $path.$pic_name;9 a7 P- j5 `/ h/ i) B5 W2 a
- echo $pic_name;. C7 c+ ]. Y a2 f% e5 E
- echo "||";- n% G$ o8 B- g0 ?" v2 R/ B
- error_reporting(0);
" p* q' X0 |6 ^. [+ P* F# o - mkdir("images");
! A1 s, |4 X- F! j' A - $handle = fopen($pic_name, 'w');6 p5 Q$ a" z" p3 `
- echo fwrite($handle,file_get_contents($pic)); F* p/ _0 P8 H6 r
- }
) h: e9 F) U2 P
% q% s' M6 Z$ p4 R9 y- $title = $_POST["title"];2 h _# \, L- J* \* E7 _3 s, i
- $content = $_POST["content"];
. j) E8 x7 Y0 h. K7 B7 a: d - $tags = explode("_",$_POST["tags"]);3 c; Z3 N( R! }6 y) T( p% A
- $cate = $_POST["cate"];, V. K& q; d; z
- //print_r $tags;
- Q' C6 B2 D" L3 w' z2 \; i - //
1 d9 b2 _3 u! y, f - //
; U) }/ E: S6 B - $wp = new WP();4 j6 ^* Q5 _* v
- $wp->main();1 O" O( N K3 F6 Y: O
- //4 `2 ~3 \* z) X" s# x
- $my_post = array();) t( C$ ^1 }) b- k) Y* A( |. ]1 P
- $my_post['post_title'] = $title;9 h: N8 V; x% A/ S7 j/ h
- $my_post['post_content'] = $content;
4 c) d7 _/ ?. x" B" D - $my_post['post_status'] = 'publish';2 }: U& K! ]9 {& j, Z( S9 k3 d
- $my_post['post_author'] = 1;$ r) L- s1 \2 ^! {& q4 v3 q
- $my_post['post_category'] = array($cate);( |) y4 G2 f0 W: [5 K1 t# q r
- $my_post['tags_input'] = $tags;% E% P* s$ h1 G" i% w! y
- //$my_post['tags_input'] = array('tag1', 'tag2');6 c, e9 X# n/ ?/ @1 w' {' C
- //$my_post['post_status'] = 'future';
, L0 o9 U2 l0 z# | g/ f - ////$my_post['post_date'] = '2010-07-04 16:20:03';! }7 a3 C/ N+ I
) o4 d) z! x; ^" W* ~ L- // Insert the post into the database
* w: H% n" J$ P+ x9 m - $ret = wp_insert_post( $my_post );
8 h1 v' k' ?; `7 @0 ], x - echo $ret;
3 f' s/ s7 A0 g; i1 j - ?>4 y$ C1 c6 _/ O- q# e, a
复制代码 我自己写的. H. M0 H" P# p' g
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|