|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! }; E2 J U* P: T ?' a! U4 f0 S2 H+ M& B+ e
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
2 `$ M% q( c+ k& P2 L. V7 A& N& I2 \7 A$ U3 ?- ]8 {
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( s& t+ O, e: L6 U* B- o2 L/ h
8 D5 s( C; f ]% Y3 ~' Z方便实用 简单 何乐而不用呢- ! m, T7 o3 h+ w- w5 y4 |5 ~
- <?php
R) I' O9 Y% t, W5 B5 W" T - 4 ?8 ~* f7 P# Z, Y
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 N/ G" R$ Y# t( {# S - require_once( ABSPATH . 'wp-config.php' );
# I9 F9 w$ i1 N1 B - require_once( ABSPATH . 'wp-settings.php' );
8 b1 S8 {& F+ z7 { - require_once( ABSPATH . 'wp-includes/class-wp.php' );6 `2 b# w9 ~) r
- require_once( ABSPATH . 'wp-includes/functions.php' );. E/ y0 ^) \4 d$ _
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% s) t9 q& X5 ^ - $title = $_POST["title"];
$ H7 R2 G$ m- @4 ? - $content = $_POST["content"];& W9 T G3 y' F& D
- $tags = explode("_",$_POST["tags"]);. l+ I/ _0 c6 a3 y
- $cate = $_POST["cate"];
9 H7 o- E& T4 _# g5 h6 J - //print_r $tags;
' B0 C5 x% ^3 \$ z6 ]- t9 E - //, t: V. z+ U9 L" O8 [1 K
- //: T/ S6 N+ ~! ~. B5 s6 P
- $wp = new WP(); T+ ]2 F' Y# q4 t. N% [
- $wp->main();
6 c" `: N+ ]4 ] w& j - //, e* I/ M: I( z( r- v1 h( a) ^2 g' f
- $my_post = array();9 y& r; G5 {/ _* F! n
- $my_post['post_title'] = $title;
+ S5 d) K4 b/ ^; L: V" x3 c - $my_post['post_content'] = $content;& w1 S+ O, [& e7 j
- $my_post['post_status'] = 'publish';
% Q1 ^0 {/ ^2 @! s* }/ ~. m. b - $my_post['post_author'] = 1;
9 q8 s+ M8 T; z/ ^8 I( Y: u - $my_post['post_category'] = array($cate);
( ]/ S5 E$ T, @4 q. L - $my_post['tags_input'] = $tags;* y2 N" p/ P3 s) \3 `5 Y
- //$my_post['tags_input'] = array('tag1', 'tag2');) }# k9 N* B7 H- o( {* H+ D0 ~
- //$my_post['post_status'] = 'future';
6 c0 B5 s" g- m. _( o - ////$my_post['post_date'] = '2010-07-04 16:20:03';$ s0 u t4 |- x3 ~$ |( N
- : Z0 W5 ]0 B8 q* ]
- // Insert the post into the database2 q+ s4 e" e+ [8 t7 ]! Q1 V
- $ret = wp_insert_post( $my_post );
8 o& m1 y% P) U8 F* y4 K. f - echo $ret;
8 c$ A. K! y I7 [ P5 {0 K* I - ?>8 m* P% P: T2 x4 s! \) Y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" ]6 |! ] [9 i) ?- <?php3 T- p* X4 N A- O9 Q
- define( 'ABSPATH', dirname(__FILE__) . '/' );# u! @# y* N# i
- require_once( ABSPATH . 'wp-config.php' );' q, M# {+ m7 X: m J* k) {# }
- require_once( ABSPATH . 'wp-settings.php' );1 |$ ?- }) J% ?2 M6 k6 P! W
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 c& i! H# e* S - require_once( ABSPATH . 'wp-includes/functions.php' );
) P1 ]8 y8 a; W& |; [5 d3 ? - require_once( ABSPATH . 'wp-includes/plugin.php' );: \7 b' @! O4 v9 v
- $pic_name = $_POST["pic_name"];
" s8 z/ l; k3 w8 o8 J - $pic = $_POST["pic"];5 R% C; N( ^1 h8 {5 L
- if($pic != "" && $pic_name != "")
5 _. A3 A% v! _ Q+ G - {. m3 S& ~( E/ I" m# D) x2 |. P! V
- $path = "images/";
7 ]4 h' ~, N s2 N - $pic_name = $path.$pic_name;
/ t- p4 p+ \- b6 _ - echo $pic_name;
8 {9 o. I3 I- u% A k7 V; w s - echo "||";: j* m, D: n; X
- error_reporting(0);& z, l; }( L) E! t
- mkdir("images");
+ o2 @4 u9 b6 m4 @+ r2 V0 Q - $handle = fopen($pic_name, 'w');
) `( A# m8 ]. N* B, g+ ^5 T8 g - echo fwrite($handle,file_get_contents($pic));. u4 E* l% R8 I* J
- }! D: L4 p; J, V
- # s& `& p# z( ^& j
- $title = $_POST["title"];
* s( h7 J) e1 G9 _ - $content = $_POST["content"];
$ U- b; V# t+ W5 J - $tags = explode("_",$_POST["tags"]);+ I4 T! h/ L2 B B i5 z' g
- $cate = $_POST["cate"];
2 r- f% V. b* E7 P" c- E6 \2 R - //print_r $tags;# B1 b& x# B) x' u9 n
- // H; `4 n1 q3 p4 j6 O$ j
- //# N9 p- _* y& g8 |5 z* B
- $wp = new WP();
! t# k1 ]8 J% X R2 | - $wp->main();3 h( x" `1 N7 h1 [7 |! S3 t; R2 t, _( |
- //- A7 Y! G$ V' N# M- P
- $my_post = array();* t- S5 ~( ~+ K- e; F! W
- $my_post['post_title'] = $title;
6 i% O9 h. ]$ ]6 i' ] - $my_post['post_content'] = $content;
1 F; ]$ R. |0 T* p' B* N+ P" t: r - $my_post['post_status'] = 'publish';, R1 t' A7 h7 h/ r7 ~; S
- $my_post['post_author'] = 1;
4 N6 K; F9 m; n& n - $my_post['post_category'] = array($cate);4 l4 N4 X f; L) d
- $my_post['tags_input'] = $tags;
3 }5 A3 N# t3 h, F9 v( y4 q - //$my_post['tags_input'] = array('tag1', 'tag2');3 G( `& \0 H% g/ g. x: }
- //$my_post['post_status'] = 'future';
; U4 D/ k+ z- m D. D4 z - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ E6 a6 [: K; r" d, V9 `
+ ^9 q3 N% Z0 P! y$ i- // Insert the post into the database$ o* `+ i$ L: z6 a6 X( D) _4 u a
- $ret = wp_insert_post( $my_post );
; H8 m/ Y2 t$ s+ U - echo $ret;
k1 G7 I, [1 h- @ - ?>
& k7 N! L6 C G/ H* ]; O& B- V7 |/ p
复制代码 我自己写的; l5 \, q3 h5 d
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|