|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 - `: f8 Z+ s0 I O0 Z0 C
. m/ |. ]" R' _& I3 L
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持, ]' j, J! q5 {
8 r1 z" O/ ?* B4 Y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
5 S! L. w( a& Y, Y4 m1 t y2 M$ b0 z& l( v
方便实用 简单 何乐而不用呢- 1 t# B$ K& w% B- U
- <?php9 I) W6 k( Q' R, F, H
- ! V) N, B8 u% D1 o- u
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& c, L7 p( |5 ]$ F - require_once( ABSPATH . 'wp-config.php' );
6 w3 e/ s! W/ v* j - require_once( ABSPATH . 'wp-settings.php' );
% L& ?9 U/ }8 n+ L, m: q - require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 I8 P0 l* D- u. X7 Q5 T- E0 C' Z# C - require_once( ABSPATH . 'wp-includes/functions.php' );
/ R* c4 p6 J/ U: g - require_once( ABSPATH . 'wp-includes/plugin.php' );
! g+ M7 |# m4 N - $title = $_POST["title"];
8 N" R' e- M- x% m1 W1 G0 }2 I - $content = $_POST["content"];! C* c! u) ^4 O0 u s
- $tags = explode("_",$_POST["tags"]);
' L5 S. g0 z4 Q }7 }9 A5 `$ a - $cate = $_POST["cate"];. u' W1 ~* \3 E+ @; D' e A7 T
- //print_r $tags;
: i% ^5 n* o3 d, D, ?7 t) B' u" r+ P - //. E S! N& v; \% w" N4 W
- //. H6 x) P4 y8 x. [8 p( D4 [
- $wp = new WP();8 e/ v! X8 ~) d9 f
- $wp->main();
' S1 O: v0 b0 b" g Y% s - //
1 O7 T: Q. I/ ~: G3 P$ _1 J - $my_post = array();( W5 r: X( z [, z& b9 T
- $my_post['post_title'] = $title;
- L; n' w" w X1 [1 z - $my_post['post_content'] = $content;
1 Y+ v; j* F7 \0 _ - $my_post['post_status'] = 'publish';; g- _+ R0 o( R. ~2 l6 P
- $my_post['post_author'] = 1;
5 ]. E9 A+ ?) M a6 Z+ w - $my_post['post_category'] = array($cate);, s2 A' y1 ` \
- $my_post['tags_input'] = $tags;/ b" w1 y0 W2 c/ ]
- //$my_post['tags_input'] = array('tag1', 'tag2');
& q" L: d0 x2 l! _/ k( ]4 s7 _ - //$my_post['post_status'] = 'future';1 e9 M. |6 Y. c1 J+ t% u
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, J! H: Z5 F+ [
4 q5 Q/ Q0 C) T* Q" l- // Insert the post into the database' [# q( f# p" x; ^
- $ret = wp_insert_post( $my_post );+ t( L% _- D# d
- echo $ret;
2 W2 E( H- @& \7 \ ] - ?>5 i6 X6 g# ]5 A- F7 s; Z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( e( @. t- i, {* L: V* G! n
- <?php
$ y2 @- Z! \7 t' p( M: n - define( 'ABSPATH', dirname(__FILE__) . '/' );* C/ F+ o [- b P) O
- require_once( ABSPATH . 'wp-config.php' );
& J/ F4 `9 O p1 ^& j% A4 h - require_once( ABSPATH . 'wp-settings.php' );
, w: A, m& u0 c- ? - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: {& q1 d5 N9 {6 @& L - require_once( ABSPATH . 'wp-includes/functions.php' );/ c, @: S. \5 P* ]
- require_once( ABSPATH . 'wp-includes/plugin.php' );
+ l& W O/ L6 S7 n8 z8 O. g - $pic_name = $_POST["pic_name"];# F% d% d- w m7 I7 c* d& E
- $pic = $_POST["pic"];( w: W( w) t+ E- d
- if($pic != "" && $pic_name != "")% _- W; s% i8 E& C2 |; {5 x
- {
/ [; D- u8 E, b" O" p! J! v t - $path = "images/"; b5 s1 k% W( e+ T
- $pic_name = $path.$pic_name;
# V) `# }# s& X3 ^* o - echo $pic_name;) p$ k& c+ |+ P. y" E- F1 T
- echo "||";2 h. ]) Z" Y5 c' B5 R4 b2 R% Y7 p
- error_reporting(0); p1 ^" m2 N9 k9 ?* ^
- mkdir("images");
" o( a4 |1 j- I/ q' t/ d - $handle = fopen($pic_name, 'w');% L% q2 {! T5 O; d' T
- echo fwrite($handle,file_get_contents($pic));
8 w/ C$ i, r; J( }. `$ X - }4 W; M" f$ s8 z. ^& Q3 ~$ _, m
7 e4 p ~ S" x2 r5 B1 U3 g, y+ {- $title = $_POST["title"];2 v* J; |9 M* }% z6 h; \5 X) i
- $content = $_POST["content"];+ i4 c. q, J0 U+ [! X* J3 R
- $tags = explode("_",$_POST["tags"]);
5 t' a Y- u C - $cate = $_POST["cate"];
' i# E6 J% r a/ }$ W - //print_r $tags;
) o' T' o" `8 t8 v/ m - //; |( W% P3 _$ G8 U2 A& Z, g5 z
- //
4 l/ o: p; {! g# X - $wp = new WP();3 l/ f5 S6 J5 A
- $wp->main();
' u& w2 D" r2 C1 j, i) l, ~. c - //
' N, i0 D' Z8 q# f - $my_post = array();, x4 _& V6 q: r. d
- $my_post['post_title'] = $title;1 d# {0 w1 [5 B
- $my_post['post_content'] = $content;& j6 n( m* v1 ~/ X4 v
- $my_post['post_status'] = 'publish';
* H* }! L7 _5 D9 `; D: L; P - $my_post['post_author'] = 1;
* V" @- N3 b j# X$ Z - $my_post['post_category'] = array($cate);
- q5 k; h/ G6 o) f3 N( b w - $my_post['tags_input'] = $tags;
4 w K9 h2 C, a* \9 h5 O' f - //$my_post['tags_input'] = array('tag1', 'tag2');
0 e1 G A( Y$ l, M4 ?, ^, ^ - //$my_post['post_status'] = 'future';
! f' N7 O4 D. Y& c - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ V9 X. {; \( _) i% X4 o - . P) U/ W9 w' q ]+ [+ m
- // Insert the post into the database
R. | y8 u2 c$ g3 r) M+ @" H - $ret = wp_insert_post( $my_post );
9 ]: P3 t( G; p; W, C u9 g - echo $ret;
" w; t W. t# ?$ f) e - ?>4 s! Q7 u1 q2 L, k( B" \
复制代码 我自己写的
- v: n2 i8 i# Y# |) @插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|