|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 c2 M* H* G0 G9 ^! ?2 E) e, s& ^7 I: T' i9 l" t! q( t7 a
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
5 |: J6 Z5 m6 R3 N7 u2 Q. a4 n) b' d; p
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了! K( C2 d3 A8 Y$ a: D
0 ]7 R) T, _9 S0 T( J9 _2 S; h
方便实用 简单 何乐而不用呢- ) e. n6 N( J7 X- K. o5 C8 w7 ?: P
- <?php* B$ C4 L9 P( |0 K9 N
- V$ \0 H4 B( n- define( 'ABSPATH', dirname(__FILE__) . '/' );
: [. H( `. x/ N R% p - require_once( ABSPATH . 'wp-config.php' );; v$ F6 e: x: `
- require_once( ABSPATH . 'wp-settings.php' );
% U1 k: Z# C8 k* J3 {5 o/ { - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, r& N4 o" ?8 e# y. ^7 s, D - require_once( ABSPATH . 'wp-includes/functions.php' );5 w1 k; Z8 T* y ^. i1 S2 B
- require_once( ABSPATH . 'wp-includes/plugin.php' );; P0 l2 N: ~5 l5 S6 o2 c2 ?! `
- $title = $_POST["title"];
' W% m. g6 m" z/ j1 }! w$ ~9 f - $content = $_POST["content"];$ O5 S, T7 ~: O# j
- $tags = explode("_",$_POST["tags"]);
- ?& z8 ` C. y, [! D/ A" b! p - $cate = $_POST["cate"];2 C4 q) b; X) t; D# f
- //print_r $tags;
. M& i1 l. S. T" w) X% U0 y* Q - //
9 O6 m- j2 |( L: f - //. r( j+ o4 N6 I3 U( f7 D
- $wp = new WP();
) c, E t& ?7 v - $wp->main();
+ o2 t+ q; {8 L) R7 T - //& S. i& D; Y! w# Q, i9 X* i5 `
- $my_post = array();
- l- I2 i5 e! C3 ~: k: s; e - $my_post['post_title'] = $title;
O% [/ u$ n3 R& v; a - $my_post['post_content'] = $content;" u/ U$ E1 I4 P% |% D0 ^1 g8 K- `
- $my_post['post_status'] = 'publish';
# R0 m! L4 M3 Y' P2 q - $my_post['post_author'] = 1;
4 D* H, [. \) W5 U - $my_post['post_category'] = array($cate);
& E# O7 _6 ~+ E$ _+ e6 R! m* [' O - $my_post['tags_input'] = $tags;
$ T8 ?8 o. x6 X - //$my_post['tags_input'] = array('tag1', 'tag2');
" Z8 _% {% y# Z( ]% s5 ~. C6 C$ n - //$my_post['post_status'] = 'future';% l; D5 v& c% X' {$ I$ L; l& R7 D
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 `9 l, h' b% k) H! |* }
% i i: ?- F1 r6 y% _. `) j- // Insert the post into the database
9 y! w( i; X+ @/ `/ s: k* ?7 i - $ret = wp_insert_post( $my_post );. \) r( ?) F$ f! @, }
- echo $ret;) v/ ]+ H0 Z7 `& e" \
- ?>) {" L- J% w) Q4 E5 G# S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
& x1 l- B4 V- f- h8 J! R- <?php6 X9 y% v' j3 }4 _
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 r, X3 L. a% B1 z0 {4 ^/ w - require_once( ABSPATH . 'wp-config.php' );
9 L% F$ r4 ~4 M, Z - require_once( ABSPATH . 'wp-settings.php' );% i8 ]' c9 A& E* L1 N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
* ~1 R0 P& ^ H8 [: S5 `6 t - require_once( ABSPATH . 'wp-includes/functions.php' );
; l) L8 I2 _: T# r& c; r - require_once( ABSPATH . 'wp-includes/plugin.php' );4 W, y- q4 p/ R: L* M
- $pic_name = $_POST["pic_name"];& ]1 Q9 i) q2 O( }# |
- $pic = $_POST["pic"];
2 X: a9 ~4 j0 v* }$ o* ] - if($pic != "" && $pic_name != "")6 b6 }. A+ D1 [1 B9 c/ w- |/ l
- {. E" Z7 q% j: X8 j& V: n
- $path = "images/";
7 l4 x ~! H \& F) j5 x' q - $pic_name = $path.$pic_name;9 @9 N# L" o7 H9 p
- echo $pic_name;1 H; B. c4 {, s2 P$ l8 {
- echo "||";: @5 F/ S$ _ Q6 [9 d- A
- error_reporting(0);: w& h3 _* U# ?
- mkdir("images");
' I6 @4 a& f; I: N* C - $handle = fopen($pic_name, 'w');
% Q& h1 b: ^/ j# @ - echo fwrite($handle,file_get_contents($pic));
4 k. q/ F6 C+ F0 \% [$ ~' \7 O* B - }
' ?6 j- ]1 L3 X% }: U
4 I0 r3 `( {, t- {7 ^: b/ p- $title = $_POST["title"];
8 u4 v7 {8 a3 {2 w2 d4 B5 m$ c - $content = $_POST["content"];
9 a \1 ]+ s1 q ?4 ^5 O4 I - $tags = explode("_",$_POST["tags"]);3 m2 x2 X$ z8 b; e
- $cate = $_POST["cate"];
: a% ?) [& }9 U# u0 G! [5 H - //print_r $tags;5 V, A+ j8 U8 T* N7 b, ^
- //! S; Q# d. E \2 s8 {! K
- //6 C5 g3 q0 f: M
- $wp = new WP();$ w L) j8 j3 q& U7 ^ \4 _& J
- $wp->main();) g/ g" u( {) _% X8 ~- C4 {
- //' ^! n3 V$ R$ s; _: t
- $my_post = array();( ]9 O; v4 Q4 E
- $my_post['post_title'] = $title;$ A8 O4 m) }# M: u, J+ T
- $my_post['post_content'] = $content;! H) ~& [$ J) R& K6 q4 M
- $my_post['post_status'] = 'publish';
; U& A. W+ P3 k" k. e6 m1 ?2 @$ ]: ~ - $my_post['post_author'] = 1;% B. z9 p o* V! T# Z' U& _! j
- $my_post['post_category'] = array($cate);
0 X- t. U. j u" @7 R2 \5 _8 C% E - $my_post['tags_input'] = $tags;, H& n q. m( g: t
- //$my_post['tags_input'] = array('tag1', 'tag2');/ ^+ l1 d# M/ E9 t8 A# i
- //$my_post['post_status'] = 'future';
! X0 X2 R& d7 }7 d. E% `" h: O. e - ////$my_post['post_date'] = '2010-07-04 16:20:03';9 E/ ?' g7 r7 j! t
- ' q2 K+ u$ Z3 z m1 |+ n9 c
- // Insert the post into the database6 Y/ `1 j/ X3 y; C% j4 Z E; i0 ]( f6 Y G
- $ret = wp_insert_post( $my_post );
: j% @# T1 @; N I. E0 I* n2 [ - echo $ret;$ s. |+ E" M# I- G9 q. w) i
- ?>: d$ o2 o0 D9 j6 p+ W
复制代码 我自己写的' B( F+ S$ `: |6 q# I
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|