|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 $ ?2 j! Q; |. J/ B# a
% q7 P* m' w# {+ ~- ` A' H直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
7 a3 ^: `. w% } a/ g0 o5 i2 B0 r0 u* r H& k7 E0 k% q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
4 D- c- X' I" M/ v8 e7 h" c0 K1 }0 V3 W! R2 X
方便实用 简单 何乐而不用呢
. {' S7 Y0 h, [. q- <?php, X9 i1 S- n0 E6 A9 ]
1 M3 \9 I5 ^" l& B/ u- q8 X- define( 'ABSPATH', dirname(__FILE__) . '/' );' S7 C) ^1 a; {0 r6 e5 k
- require_once( ABSPATH . 'wp-config.php' );5 g n" E+ [( y! ?1 R
- require_once( ABSPATH . 'wp-settings.php' );+ |8 A8 A y' }9 b. @* L! B3 S
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" g) z: _! k% n$ ]
- require_once( ABSPATH . 'wp-includes/functions.php' );
( _) u! z2 Y- @5 c* e) A4 U1 f5 q, l - require_once( ABSPATH . 'wp-includes/plugin.php' );
) A2 ~( N# S' e7 l- \3 a0 m - $title = $_POST["title"];$ Q; P: ~4 ]7 {& ?5 T" s
- $content = $_POST["content"];. w- Z e1 {2 k" i S! i" T
- $tags = explode("_",$_POST["tags"]);
3 o3 f# T0 u2 \5 d - $cate = $_POST["cate"];$ m w. M+ b7 N- ?2 z: A7 E& S3 [. B5 x
- //print_r $tags;
- A7 i' ^6 X$ u6 H - //
3 V* v# {1 `: W$ v9 _ - //* j) N3 C) G$ v
- $wp = new WP();3 H7 U1 j) g; T% i4 ~8 }
- $wp->main();
9 F; D% n# q! j0 X - //+ [! {1 w) Y) k& T: Q
- $my_post = array();) b( h9 U9 n& u! G" W, O) v
- $my_post['post_title'] = $title;5 A( r4 V9 f5 x1 ~- t4 J
- $my_post['post_content'] = $content;
& T7 J" k3 J( B4 ~4 l; O% y2 |: o - $my_post['post_status'] = 'publish';
$ b: k# o9 X* P" R8 Y - $my_post['post_author'] = 1;
% e8 v& ] y$ G8 `2 p7 j - $my_post['post_category'] = array($cate);
& K- m; T9 l; |! B5 ~ - $my_post['tags_input'] = $tags;0 v, i8 R* i: {0 d, t
- //$my_post['tags_input'] = array('tag1', 'tag2');( H" B: W+ s1 D4 d" G3 W8 }; @1 e
- //$my_post['post_status'] = 'future';- u' M% X8 c8 d5 B: `& j2 l
- ////$my_post['post_date'] = '2010-07-04 16:20:03'; N% I1 o4 ~3 u
- : Q3 E( f* I) H: ]+ I
- // Insert the post into the database
% O) B. Z A# H8 ]% i - $ret = wp_insert_post( $my_post );
& E9 K! n# H1 Y- F7 f - echo $ret;' X7 c+ I7 d: d. j5 p
- ?> M; U- a8 ]$ e: i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
* h' R- E3 X, i% J2 T% }5 d" y3 f- <?php
3 ]. A9 g2 q; R# f* S - define( 'ABSPATH', dirname(__FILE__) . '/' );
) y$ d8 c1 p0 n - require_once( ABSPATH . 'wp-config.php' );5 [9 i3 z( {4 w) `; Q
- require_once( ABSPATH . 'wp-settings.php' );" U5 k8 h! y+ h/ Z7 e. o
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 z0 C+ T V8 m; }, {! K
- require_once( ABSPATH . 'wp-includes/functions.php' );
- @! ?. Q5 t9 o4 f& ~: f* u - require_once( ABSPATH . 'wp-includes/plugin.php' );9 `/ r' l* J/ {3 ]/ K
- $pic_name = $_POST["pic_name"];
6 W) [) }. \2 j8 w" {& h - $pic = $_POST["pic"];6 k3 S: r+ A1 H
- if($pic != "" && $pic_name != "")( v+ ^3 u5 A! `1 _6 M
- {& n. D/ c g- d2 p# `+ z& T
- $path = "images/";
8 n2 V" H- |8 M - $pic_name = $path.$pic_name;
0 E( S: ^3 h3 C \! r - echo $pic_name;9 P) C3 w4 f2 Q. y
- echo "||";
s* }8 [6 c+ O2 \1 f - error_reporting(0);( w8 ~& J; w% D, s# K9 @
- mkdir("images");! h" p: r0 b% b. ~5 X
- $handle = fopen($pic_name, 'w');. X b5 O* D: E
- echo fwrite($handle,file_get_contents($pic));
% W8 a* i3 g+ K; @' W* g - }6 O3 y, I" P6 O1 y: n, H
- ' n5 X+ k- W* E( H/ b8 l
- $title = $_POST["title"];
- J: }5 H. @" W) I, b) d* e - $content = $_POST["content"];& R# r1 t5 U7 ]5 ]+ f% ?/ D
- $tags = explode("_",$_POST["tags"]);0 l% G9 H, X8 o! }; ~5 [
- $cate = $_POST["cate"];9 M" }9 W8 r. l5 I; w1 Z" r
- //print_r $tags; B7 M" O+ D3 p( D# [
- //( C/ }6 l1 o1 ]* F" H
- //# n! n0 Z) f. o& N2 O$ O) Q
- $wp = new WP();" u0 T2 x2 Z, n. p3 C
- $wp->main();
- l; t) s, q( g T! Q - //% N2 W9 M) p/ r. |+ ~% L
- $my_post = array();
( M4 z. N5 E2 I0 _. f+ m( q8 s - $my_post['post_title'] = $title;
% j$ a p- |) V4 k# ^) R - $my_post['post_content'] = $content;, X2 w7 W/ q0 I2 k
- $my_post['post_status'] = 'publish';7 I% ^9 o# C& n9 _
- $my_post['post_author'] = 1;' }* Q: ~* a+ u2 n! T9 x
- $my_post['post_category'] = array($cate);
$ w- f7 ]$ Q8 g" j2 g P# V - $my_post['tags_input'] = $tags;
) z2 b. U: k l: s4 F, D1 A/ @ - //$my_post['tags_input'] = array('tag1', 'tag2');
/ V3 g# r8 e/ {2 C& D - //$my_post['post_status'] = 'future';
$ C) `! A8 e y - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 G9 W2 d" p! g S% m3 n
- . F; o: _8 R$ T; M
- // Insert the post into the database6 T9 j! J) T3 ]( Z d G N5 B
- $ret = wp_insert_post( $my_post );
! }" j) _; Z0 D! M) } - echo $ret;
0 M! `6 x# ?4 P* H5 n% i - ?>
1 z- }0 L# B6 T
复制代码 我自己写的
- M. F6 k l' d4 ~插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|