|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
0 \# T) d' N9 z7 o! H' H
* c- m1 x+ n- a9 `0 w直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ z/ D2 i" N7 z* F e3 [$ w0 ]& V
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: a7 `# i8 Q3 E8 T- w
7 [% u, V" ?. ?' L" s9 Y) W$ I方便实用 简单 何乐而不用呢
* k! C- x2 V5 U6 Z( g- <?php4 g8 U) b- o: h z$ Z
- ; j; R9 {9 ~4 n/ d: V& S
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ R+ y) s6 g$ v% H' q! H7 w& ?% w2 [9 B - require_once( ABSPATH . 'wp-config.php' );
# l* @/ J0 F3 z - require_once( ABSPATH . 'wp-settings.php' );
8 x7 _& m9 ?( V3 H/ _0 d - require_once( ABSPATH . 'wp-includes/class-wp.php' );* v6 y* y B" B
- require_once( ABSPATH . 'wp-includes/functions.php' );
5 h% t; g, P+ j. n - require_once( ABSPATH . 'wp-includes/plugin.php' );5 ?& w; X# c5 ?2 [1 I
- $title = $_POST["title"];& |# [! o6 S5 Z4 l
- $content = $_POST["content"];3 X6 P0 F/ Y1 L+ U/ \8 T
- $tags = explode("_",$_POST["tags"]);$ Q5 H+ h7 M" n8 N; }& x
- $cate = $_POST["cate"];
* A5 O6 @% h' F' }9 _2 q6 U( y - //print_r $tags;
, T) @2 \5 _; k. ^ - //- F) M0 v- s% ~* N
- //( b% R4 b0 l& J3 ]+ j
- $wp = new WP();
) L' w# ?2 w) C1 M( V8 z - $wp->main();
& l2 ]& A5 k; k2 X! T - //9 S) }' y2 G; I( e" p0 f. ]
- $my_post = array();
3 q$ {% z6 u7 E; Y& W4 o" N - $my_post['post_title'] = $title;
, t) [! }- q7 ^% v - $my_post['post_content'] = $content;4 T0 X5 F8 ~6 s4 p
- $my_post['post_status'] = 'publish';
# t" s9 D1 R! ]6 B, D- L - $my_post['post_author'] = 1;
# l/ Q; P9 Q X0 b3 G. v - $my_post['post_category'] = array($cate);
$ ~* m) y% b9 L/ g; l* e - $my_post['tags_input'] = $tags;
0 h4 N* J& M3 x% h4 E - //$my_post['tags_input'] = array('tag1', 'tag2');
$ f0 M# o7 r9 C* p) F - //$my_post['post_status'] = 'future';
; g6 Z D2 k6 I0 Z( m" U# Q& p - ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 Z7 |! h" Q1 b- ~ - T. d6 J) f6 u; A' F
- // Insert the post into the database
A! ^) j, ~" N3 b+ \& h - $ret = wp_insert_post( $my_post );
6 D; k! w# P" Y - echo $ret;% E$ B; O7 R3 [$ I4 ^, \* v# r
- ?>( |' B' r2 ~8 {3 O( k. p# J
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
; \6 P) T% U! D; n$ \& P- <?php F( w( l- d2 ^: |( V/ K v
- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 z! y- z7 F D3 t! B$ d - require_once( ABSPATH . 'wp-config.php' );0 \: H6 K' L. J4 `" g: o% V
- require_once( ABSPATH . 'wp-settings.php' );# } z; d) V8 E
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 c- D* x1 p% P U$ I" Q& h
- require_once( ABSPATH . 'wp-includes/functions.php' );
4 k( ~* v2 L! L5 B2 j - require_once( ABSPATH . 'wp-includes/plugin.php' );) a# ~. a8 _4 ?1 o
- $pic_name = $_POST["pic_name"];
" O. \. j2 j$ x9 \) s+ m& I - $pic = $_POST["pic"];% \% Y) {1 F0 P, w H, s7 W
- if($pic != "" && $pic_name != "")7 ^, S- o q5 i$ o5 g7 y3 l; ~! y% S
- {
: e9 [7 N6 t, c: y: Y2 i ] - $path = "images/";
7 \5 u. v+ _1 ?. o0 ^. _ - $pic_name = $path.$pic_name;% ^; ]) d% J: Z8 v G2 V0 ~ n
- echo $pic_name;
: Q8 ~% e0 D0 R# ^6 s2 j2 R - echo "||";, Q: f/ n7 N$ C9 D8 M/ G
- error_reporting(0);
+ r% K- ]( u1 Q' b- [3 u - mkdir("images");
' E& S6 H+ X0 ?/ \ - $handle = fopen($pic_name, 'w');# K% r6 u$ l+ j) V2 Q8 M
- echo fwrite($handle,file_get_contents($pic));4 P, Y7 t' `; L( p; N; E$ y* |
- }
1 G- ?* \# _4 \+ d - . u2 j* Q* Z4 _
- $title = $_POST["title"];
* b$ b) ~5 D1 ^7 q( [ - $content = $_POST["content"];
s3 w X+ g5 G( R/ N7 }% H' z - $tags = explode("_",$_POST["tags"]);! Y% e6 O; A w, S; d# ]; C
- $cate = $_POST["cate"];
6 c! @5 G9 ]; G4 B - //print_r $tags;
. Y2 D z( I$ m$ G5 T# X - //
1 D: w8 W4 |5 F6 `; R - //
. v" ?3 u% S- w3 C" Z - $wp = new WP();- R8 U2 v- d; w0 R4 H
- $wp->main();7 r3 Y2 G1 c0 a! u0 X5 z, d. G8 c
- //+ S* K8 |0 L+ k. E, N( ^9 k' C5 d) D
- $my_post = array();/ g e4 E9 N7 ]9 ?: c7 }
- $my_post['post_title'] = $title;
. M5 ~9 l# A- D( }! L+ a - $my_post['post_content'] = $content;& r, j9 `" b. e8 B3 n
- $my_post['post_status'] = 'publish';) ]% n9 }: p' i& B4 K7 \$ n' a
- $my_post['post_author'] = 1;
% a' q. f. F$ l& g- _7 E - $my_post['post_category'] = array($cate);9 @9 D4 e0 U. U F h
- $my_post['tags_input'] = $tags;% D8 O; r: r3 R# N) t
- //$my_post['tags_input'] = array('tag1', 'tag2');
6 f, _ G6 x2 O& n' `# @ - //$my_post['post_status'] = 'future';
" T. k1 V2 `- D0 V: |2 T - ////$my_post['post_date'] = '2010-07-04 16:20:03';* v. P) o' Z+ w4 n# P
- a2 ^% M2 P9 I2 [
- // Insert the post into the database0 Y) C3 e2 F- |4 {
- $ret = wp_insert_post( $my_post );
, r4 E: f8 H) L# } - echo $ret;: C8 e! g% |& x0 h
- ?>" ~) d2 {* J6 u& o b2 A8 J
复制代码 我自己写的
# r1 {( I9 @* S* a" }4 p插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|