|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 s' A7 o9 F0 J, a2 H8 H. {) \! m6 Z ~' W/ E4 E0 Y# `
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持$ j" \2 n( D/ t0 T
6 B3 A2 y+ s' d+ ]0 y
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( H3 U2 K3 g, a( S; Y5 J/ ]- [. f2 s2 ^7 {% s# J7 {
方便实用 简单 何乐而不用呢
7 z! I) q6 f4 B/ y2 F4 p- <?php6 e% J2 V; Y4 g2 @% S3 v- @7 R! j
1 u; Z& B" K; J" Q. ^0 U- define( 'ABSPATH', dirname(__FILE__) . '/' );+ M7 L$ q% `" H2 l8 o
- require_once( ABSPATH . 'wp-config.php' );1 t b6 H1 Y2 R: l: C( b
- require_once( ABSPATH . 'wp-settings.php' );- w& R; @& A$ {0 j; h
- require_once( ABSPATH . 'wp-includes/class-wp.php' );; Z9 r3 K( @/ K3 Z6 Y4 P ~$ H
- require_once( ABSPATH . 'wp-includes/functions.php' );/ c0 h$ S( l3 r# ^, Y
- require_once( ABSPATH . 'wp-includes/plugin.php' );
& f8 p8 V2 T! ]$ w - $title = $_POST["title"];; H) Q4 j4 F5 W
- $content = $_POST["content"];
% H. i7 L! l! a* y# }; T- J+ ]3 F - $tags = explode("_",$_POST["tags"]);' S7 D1 ^# c3 F1 b+ f" M1 n+ k
- $cate = $_POST["cate"];
+ Z# g8 R2 z7 A6 W. ]! ] - //print_r $tags;! ~+ T+ S8 J. g) D0 M3 z. x
- //% k$ a# ~! a" t/ v, ~- U; M
- //
% O6 M, E7 M/ q9 o0 @! m - $wp = new WP();
8 \+ X8 Z/ B* L- }8 S- `; [ - $wp->main();
2 {+ D/ r' l) ?: Z. |1 n - //8 @1 B" R8 P% M4 P
- $my_post = array();$ ~4 [* A- o: M
- $my_post['post_title'] = $title;6 S( _8 Z+ ]' f6 C" M
- $my_post['post_content'] = $content;8 n7 ]# T. h9 G6 ]3 {
- $my_post['post_status'] = 'publish';. H0 x" P; D; x! ^ s
- $my_post['post_author'] = 1;
8 n0 b6 t& ]2 Z3 ~4 r( D: @" @( g H - $my_post['post_category'] = array($cate);
1 c0 ?* Q# w* A( q2 m* P0 l. t& x - $my_post['tags_input'] = $tags;
" C/ m1 q. ~. K; u - //$my_post['tags_input'] = array('tag1', 'tag2');, w- v! d% b! ]: x
- //$my_post['post_status'] = 'future';
1 S( p3 c0 J1 K! N/ k+ C( K - ////$my_post['post_date'] = '2010-07-04 16:20:03';; f& Y6 M9 @" } k6 J
- 1 n' b6 p R& [, c; W/ I% v, e
- // Insert the post into the database& j. G; H4 E- h6 s5 s, `$ `7 o! J
- $ret = wp_insert_post( $my_post );( X. X; ?+ o6 e6 u( o
- echo $ret;
6 r, Q1 ]0 `9 T - ?>: P2 s7 e5 T/ U* y. f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
1 S9 G! q% g1 d! [' g6 p- <?php% D$ L8 h* M+ Z2 f0 H2 Q
- define( 'ABSPATH', dirname(__FILE__) . '/' );6 p- @" t$ ~4 q2 |% M# E
- require_once( ABSPATH . 'wp-config.php' );
7 N) E4 Y0 B; f - require_once( ABSPATH . 'wp-settings.php' );
# Q& v" Q/ j/ M) A. A# \4 W3 R - require_once( ABSPATH . 'wp-includes/class-wp.php' );( L2 K; t# A! L' a) I3 `
- require_once( ABSPATH . 'wp-includes/functions.php' );
& w) u/ r6 o/ v6 C, J I i6 M - require_once( ABSPATH . 'wp-includes/plugin.php' );% e% ]# \0 }# R2 j- i( Z: O$ k- ] Z
- $pic_name = $_POST["pic_name"];
' @2 {6 X) D; z - $pic = $_POST["pic"];+ r/ o6 W' e8 u, ]- E
- if($pic != "" && $pic_name != ""). U4 c/ W% ^; V/ [
- {* f8 N& L* Q' y5 P g( p/ b6 m
- $path = "images/";
3 B8 q+ d* \$ @1 `+ d( R% ? - $pic_name = $path.$pic_name;7 Q9 O- x* s7 h) G
- echo $pic_name;+ x9 `. |* Z: Q. f- \
- echo "||";
( {6 Q; t s. Z4 a& [% v - error_reporting(0);5 B3 D* h0 T6 ~1 G9 ~1 N
- mkdir("images");2 j0 m3 B5 d* O
- $handle = fopen($pic_name, 'w');
& [( I9 ~$ [; r! y, | - echo fwrite($handle,file_get_contents($pic));9 ]% ~/ |0 x' l% K
- }: B# ?+ c; Z: S9 G8 q
' A9 Y8 [5 s, S4 I+ {' `8 @- $title = $_POST["title"];
# c1 J. e" _+ a. U& F5 s - $content = $_POST["content"];) a+ X2 h: y3 P! {% H" w3 l
- $tags = explode("_",$_POST["tags"]);
- c- I/ W' `- x1 X" G. | - $cate = $_POST["cate"];
$ j+ B$ o" A1 k) C1 k - //print_r $tags;/ n* t; I. C5 `, k8 u- H
- //
( o3 R- @9 {, \6 V q R$ | - //
/ [6 X% a5 M2 q& ?8 H- \ - $wp = new WP();
6 d9 g( _& u/ U/ n( T3 k; ] - $wp->main();% G3 [' w7 E9 \6 e
- //4 U8 r) o; g4 @* J1 c
- $my_post = array();
( a, J$ Q# W- T8 i! ]- u - $my_post['post_title'] = $title;0 E7 G" v; t; C
- $my_post['post_content'] = $content;( k2 m& k2 K: U- U/ G5 }/ V' W
- $my_post['post_status'] = 'publish';
+ a1 D( ?, ]8 d5 A - $my_post['post_author'] = 1;
3 l. C$ y9 o" `$ J2 } ^' U- M. v - $my_post['post_category'] = array($cate);
0 g" A" v4 `) H0 d- v) R( A2 b - $my_post['tags_input'] = $tags;, E/ G9 i4 o& c& t; A" h0 o
- //$my_post['tags_input'] = array('tag1', 'tag2');, t: K, d, \' d" {
- //$my_post['post_status'] = 'future';
2 J8 b) J, g. K1 D/ J- E- x - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 T+ t+ c; }/ c. b' g/ o. m4 p
e" @0 }" Y3 v% _& l4 T9 J+ w- // Insert the post into the database, b+ G: U: \% e5 i( ]
- $ret = wp_insert_post( $my_post );8 ^0 J4 i/ T. G) K# o1 O5 C. t& b) b" E) X
- echo $ret;
. a8 `$ Y" p" `. U; i2 I! A: \ - ?>
. o" i1 u4 \7 n/ ?' m+ d" X
复制代码 我自己写的
% [5 A; I! c; `9 N插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|