|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 y- ^8 `9 \. w. O" A# `: ~8 Y" f6 }- I" }# Q2 c$ O7 `
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 _$ Z4 s5 {0 e. R. s' f
1 r- J- n7 [5 p i/ G! e& Z3 u) f我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
* B4 j0 [0 p$ _- z3 T1 }
/ \: }$ ?1 @" d0 \0 F9 U* ^方便实用 简单 何乐而不用呢
$ v8 j! Q3 X. V" L5 I- <?php6 ]+ i2 W2 y7 v% D( G
- / O9 l7 k2 Q: z& k
- define( 'ABSPATH', dirname(__FILE__) . '/' );( k! j) @# U0 }* ~4 B
- require_once( ABSPATH . 'wp-config.php' );
- G6 P8 A1 X) A, P; F n8 K; z - require_once( ABSPATH . 'wp-settings.php' );' Y5 E7 @$ f# H4 ^ j! E; ?
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) S' E6 i, t- q5 X9 J- b - require_once( ABSPATH . 'wp-includes/functions.php' );
+ @! f1 x. D+ P4 n A - require_once( ABSPATH . 'wp-includes/plugin.php' );
, Z; O2 C, ^4 c S+ F7 m; y - $title = $_POST["title"];
% ^8 W- r* {) O7 `* V/ H& |. ^ - $content = $_POST["content"];. I2 U& Z- u/ D; y) W' J; A+ ]
- $tags = explode("_",$_POST["tags"]);
0 h) m; Y' B% E2 l" i. z' j - $cate = $_POST["cate"];" o1 u& H. r8 D2 f" l( y
- //print_r $tags;4 @- z9 v' u9 v9 j0 E$ g
- //2 l2 F2 g7 d' z# s. ?2 c" |% n& ~0 f
- /// k! b3 y* Y/ n' z! I8 q
- $wp = new WP();
1 M) o4 @8 @! N' K" l8 r; L- }5 k; z* a - $wp->main();
* ?* l) ^+ C3 ^+ c4 U - //6 ~% K( w4 A7 s) h* o& E
- $my_post = array();
+ P3 B$ ^) H: t4 e5 |+ D - $my_post['post_title'] = $title;" p- s1 g3 Q* a h1 @
- $my_post['post_content'] = $content;
( V* w! X) f' m3 u; h( o4 W - $my_post['post_status'] = 'publish';
5 F, l( R. c9 W - $my_post['post_author'] = 1;! c. D0 P1 T/ [1 T9 g
- $my_post['post_category'] = array($cate); j1 _/ N+ E0 P* W! r
- $my_post['tags_input'] = $tags;
' {# Q. y8 l* S6 [* X. L - //$my_post['tags_input'] = array('tag1', 'tag2');
( [- C8 p. n+ _/ O - //$my_post['post_status'] = 'future';, ~: O: x5 S* P. @7 @. e) H+ A) w
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ L" g2 {- b) @ O
' E8 _# U2 b3 C; c8 U. I: i1 }" c- // Insert the post into the database$ p' j! l9 R/ x9 T$ F/ n* R5 o$ }8 a
- $ret = wp_insert_post( $my_post );' E* x4 A* J; A6 G) h- Y8 Y2 j
- echo $ret;
& e5 @; { q. y2 Y0 i# m) b. e - ?>
& b& R- d1 w" l1 T Z# r
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- : } I' U5 @( [: T( D$ u
- <?php3 l; J! W2 P1 B4 ~4 Y) H( O/ a: P
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 @3 T/ B# a+ j+ D- {# b
- require_once( ABSPATH . 'wp-config.php' );
$ F+ t5 E5 z3 Q3 Y* w) { - require_once( ABSPATH . 'wp-settings.php' );% u [; r4 G9 L; v, u$ ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ N9 x9 Y Y1 L" t9 b, n2 s& n' y - require_once( ABSPATH . 'wp-includes/functions.php' );
# g/ s( {. j! a1 {; S - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 J+ q( ?: T$ b. ? - $pic_name = $_POST["pic_name"];
8 r7 R# a4 l; `' j: n" \. y P - $pic = $_POST["pic"];
, R- e# W3 s0 H5 n* n - if($pic != "" && $pic_name != "")
) A9 z4 g' n4 G - {, _3 o- R5 U c+ K( @) m
- $path = "images/";+ j1 s$ A9 A! ]/ S4 l6 Z
- $pic_name = $path.$pic_name;
/ H' F/ o. r, b - echo $pic_name;9 R$ N8 G6 i. L5 |
- echo "||";8 Y; \# E4 O5 O# P# n4 H
- error_reporting(0);$ q P- y2 p( d* k
- mkdir("images");& _9 R- ~4 Y( s# M2 x R2 Z
- $handle = fopen($pic_name, 'w');
& E8 u/ {4 n& c% N6 { - echo fwrite($handle,file_get_contents($pic));
5 A& w/ s! d1 d: t- `3 W# P+ ~ - }
- H: `! x4 v) H8 s$ J! f - : l5 T1 F( ?4 ^! J
- $title = $_POST["title"];$ i/ F' Z' P0 @1 w
- $content = $_POST["content"];* ~- ~* `" @' i5 S0 K
- $tags = explode("_",$_POST["tags"]);; Y2 o& E1 {8 c9 V$ j4 A
- $cate = $_POST["cate"];: }& _% v. C' f
- //print_r $tags;5 R6 q' C7 ]2 ?3 B# ?
- //& m! t( m/ [. y+ e0 W% X8 B
- //& i2 l( k K' Q- }" y* g2 `( s
- $wp = new WP();4 C' N. w6 c" c1 a5 b" A: l
- $wp->main();
+ e, I( R9 y- J1 h+ u% `$ W2 B2 j" I - //9 T! ^! I7 ?5 I- y5 J0 ^
- $my_post = array();
+ t4 p$ h9 b/ y - $my_post['post_title'] = $title;
* \ R3 \7 N1 g% r! E s6 P! y6 D0 z - $my_post['post_content'] = $content;
4 j. v) Y& l: g% e# M2 u - $my_post['post_status'] = 'publish';
( L/ X, v# K/ ]: E: K - $my_post['post_author'] = 1;
G# G2 f! I) W - $my_post['post_category'] = array($cate);8 W; I( x9 [+ u" e. @ M. j A
- $my_post['tags_input'] = $tags;
! I# V5 q8 l( W2 P; v0 W) [ - //$my_post['tags_input'] = array('tag1', 'tag2');# z9 D" z/ M' w6 o# R
- //$my_post['post_status'] = 'future';
, u& C& h8 z9 o, k. Z5 E h- j - ////$my_post['post_date'] = '2010-07-04 16:20:03';. Y) p6 I+ h7 X( p9 @& V% D
% O% Q- Y8 c7 _3 z% S# N- // Insert the post into the database4 V0 G& `0 C( w/ x, D
- $ret = wp_insert_post( $my_post );. A# j! E) T) m! R4 S
- echo $ret;
3 R* _5 R$ c2 f - ?>
5 F4 M- j' {* x9 J8 b2 m7 {8 ]
复制代码 我自己写的
5 N1 ?) n! x! ~- k+ J; J插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|