|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
/ ^2 E& n6 Q/ k* r, a& _, K8 a! g) T8 z" K: S, L
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
: A- S# c! N) p# j
+ q& X8 m- y3 m. ^/ K我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 f6 x, l$ J" ^/ ]
( v/ s- l+ ?4 s! |# W$ z5 [- @
方便实用 简单 何乐而不用呢
# ^5 ^& G* F) O l i, n2 n7 R- <?php
# S0 c4 O3 u- o - % z/ f N* z+ P Q# r1 Y' x# g
- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 \: P) h+ }+ N: G; e. Q - require_once( ABSPATH . 'wp-config.php' );
; s k, R; F5 \ - require_once( ABSPATH . 'wp-settings.php' );. y2 [9 ? k# _7 f* Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 R# p8 m2 x' z; ?2 l3 ~1 A - require_once( ABSPATH . 'wp-includes/functions.php' );# ?' X( P2 e+ I0 J6 T
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ X" H: M# t# k% d* a8 c
- $title = $_POST["title"];
! }* K' U+ G- }5 q8 b7 q9 Q - $content = $_POST["content"];6 r; V9 g8 A+ j7 z) y& |0 U
- $tags = explode("_",$_POST["tags"]);
1 T' F7 a' b, i5 d5 R. L9 m0 A - $cate = $_POST["cate"];
2 O/ v; L, ?* |& `1 H3 ^9 r P - //print_r $tags;* e! b! E% R9 F4 u6 S
- //
$ l1 D) |2 E8 H" o& d, f) f: ~ - //, b% c0 f+ y# r, t" J
- $wp = new WP();7 H! g U& H1 j' _3 l: z& I5 J
- $wp->main();3 u0 I0 t- I& ]6 Y# g
- //
5 L. D% J. c& f' k) z: q8 b) \, X - $my_post = array();
- G5 \9 \9 c, I8 z2 e - $my_post['post_title'] = $title;
0 E& h& I: d4 I; p8 S - $my_post['post_content'] = $content;; P4 c! }0 o: M+ ~
- $my_post['post_status'] = 'publish';6 T) [/ T3 O! h$ `9 h7 r
- $my_post['post_author'] = 1;. z" H) @2 Z; _- r! n6 j
- $my_post['post_category'] = array($cate);# U3 T0 N0 J+ r f
- $my_post['tags_input'] = $tags;
# L) D/ k: m$ e3 {/ Z' B+ ~0 p5 { - //$my_post['tags_input'] = array('tag1', 'tag2');% ]/ @1 O* `9 s/ `$ B9 ~
- //$my_post['post_status'] = 'future';: \. K, Z* C" C z2 u; P4 h
- ////$my_post['post_date'] = '2010-07-04 16:20:03';/ W% s- |( q& k4 ? _8 }
- 5 M+ g3 |. V1 M+ `7 S& U- I. s: Z8 { _
- // Insert the post into the database2 m9 o3 R) F5 }3 V8 @
- $ret = wp_insert_post( $my_post );- F' `' k8 r. V/ N) ?% [* U& \+ V
- echo $ret;
' `/ w9 ?2 L+ W v/ T& d - ?>
% Y ?) [: l, l; S# ?
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( k5 z# u" o* k
- <?php
4 F+ M$ Y% d0 j6 h% X - define( 'ABSPATH', dirname(__FILE__) . '/' );
4 U! ]9 E" A7 M+ p - require_once( ABSPATH . 'wp-config.php' );
5 e5 c: X" \% h- f6 i - require_once( ABSPATH . 'wp-settings.php' );
3 k% o% o1 x, f$ E k - require_once( ABSPATH . 'wp-includes/class-wp.php' );8 W! e, ?9 U: Q
- require_once( ABSPATH . 'wp-includes/functions.php' );
% j4 S* N! ]4 Z$ d; J - require_once( ABSPATH . 'wp-includes/plugin.php' );& D! ]* O% [" h, `, w
- $pic_name = $_POST["pic_name"];' ?) V) B; K* d* ]3 P
- $pic = $_POST["pic"];) U: o4 E, z; b: C1 L1 x" n' I
- if($pic != "" && $pic_name != "")
( s% O# ^ F9 Z$ q; X% T - {
$ m" U6 N8 @' e - $path = "images/";5 W' k8 `- C% ], V- ~/ ~% `
- $pic_name = $path.$pic_name;2 z! X7 O: `) q( _' }
- echo $pic_name;
1 K* d6 o. m+ g. K4 l* @ - echo "||";. g' p$ }) M/ C- F( y
- error_reporting(0);! X& |' i( M/ c* }
- mkdir("images");8 Q1 X8 Q% t8 s! s# ]! Q
- $handle = fopen($pic_name, 'w');
7 c: i5 G: @! T( P* U* D - echo fwrite($handle,file_get_contents($pic));3 ?* i1 M3 M0 Z1 r3 T* `
- }
- B4 M; y: n2 L* h2 x0 h9 } - * G T' J5 Z; H! E6 g: Z
- $title = $_POST["title"];) t# j7 U5 P$ Q$ k# \. d
- $content = $_POST["content"];' E. a% |' Z- q7 h
- $tags = explode("_",$_POST["tags"]);
) X) v/ z6 ?3 j - $cate = $_POST["cate"];3 R2 b" k7 R( E' H; M6 V
- //print_r $tags;0 H. w P! v7 j
- //) b; }- N; O+ n. W" m2 M0 r5 g
- //' r6 E) y) w* ?7 @. U ?2 B
- $wp = new WP();
4 m$ s" e' ], T4 p. q% P* I - $wp->main();8 a& T$ Y2 {, R u+ s% }2 P1 X/ m
- //3 Z) z' n1 a Q3 t/ H5 _, K% P
- $my_post = array();# H7 B4 p2 B% w0 Y. ?9 X8 f
- $my_post['post_title'] = $title;, r% e# G1 u- P% I4 z$ X
- $my_post['post_content'] = $content;! i( G+ u: C% I0 p7 K! [* s" {! I
- $my_post['post_status'] = 'publish';& G* X# b7 _5 ~: @% F" L# q
- $my_post['post_author'] = 1;
6 F7 U0 o, s3 a - $my_post['post_category'] = array($cate);2 x6 b4 t) `3 t# J8 s9 R: n
- $my_post['tags_input'] = $tags;
( E# F5 q* ]8 s" I - //$my_post['tags_input'] = array('tag1', 'tag2');
7 k( }5 u: A: X' }9 f - //$my_post['post_status'] = 'future';
: W+ p4 _8 M- Y' ~" ^" d - ////$my_post['post_date'] = '2010-07-04 16:20:03';# H2 X1 j+ V: ]& A* a7 q3 Q, b
- 7 V% ~! f2 U( h* q4 A- }) j
- // Insert the post into the database
& [% H, @7 L9 v0 O - $ret = wp_insert_post( $my_post );
) c6 n5 K% ]2 r/ w7 w - echo $ret;
% c1 A& Y5 I% H4 }5 D3 S; Z - ?>
& H* l. k' i! b- c7 U
复制代码 我自己写的
& [: F/ U. t: S; k% H* D/ e插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|