|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / e+ i, ~5 L w$ A5 A/ n
4 f9 ?( r& u: |$ r) Y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持/ G2 I+ V0 w7 x8 `' ~$ D1 ~7 m, G
+ z; V2 x, @) X: P% [2 N1 J
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# S+ r2 p4 y5 r/ }
1 w3 L( e2 z2 `2 @6 @: A; j3 R
方便实用 简单 何乐而不用呢
+ h; f1 U; ]" a5 A8 x+ J' M- <?php+ a: }7 G. |" B# X |& a
- o/ G: a9 m4 b8 @! w1 i; z- define( 'ABSPATH', dirname(__FILE__) . '/' );
, a# i5 g# ?% M - require_once( ABSPATH . 'wp-config.php' );
* X0 j+ b4 X) |; I4 l - require_once( ABSPATH . 'wp-settings.php' );
& z) e' V+ M4 p! _5 o - require_once( ABSPATH . 'wp-includes/class-wp.php' );/ |" n2 t; r: `3 u0 h% a
- require_once( ABSPATH . 'wp-includes/functions.php' );
' m) d. |# R" D( a- C - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 q8 p3 q' x: B3 k# h8 g8 m - $title = $_POST["title"];9 y5 O' d. ~' j* N9 @+ C
- $content = $_POST["content"];2 H5 @* y5 S& c. i9 Z
- $tags = explode("_",$_POST["tags"]);- m$ l, Q' `, H" n: y& S* A
- $cate = $_POST["cate"];
^: `' q2 l' k9 _) T0 y - //print_r $tags;; [2 c4 T% @% K/ N
- //! h7 g( K+ x1 M# n0 R9 ?
- //
$ z7 n( U' Z: X6 X6 V - $wp = new WP();( d9 t6 ]: i- y" \+ T$ J
- $wp->main();
k3 P7 I- J4 b, I0 N% Y9 Q. o - //
# K: [2 z0 ~; s) j3 d: f+ h# C - $my_post = array();
. H6 Y j: p, }* ? - $my_post['post_title'] = $title;0 S6 ]) g$ d' [0 ?: H' V5 {
- $my_post['post_content'] = $content;
" W8 e- ~; r7 L5 _ - $my_post['post_status'] = 'publish';3 H5 I) S) H; m$ F4 d
- $my_post['post_author'] = 1;; G' X) U( @. t- [4 E- ]& ?. W6 B: v
- $my_post['post_category'] = array($cate);
* |. a' o. G1 c3 j- v$ ? - $my_post['tags_input'] = $tags;, H6 l* L8 E4 k9 E
- //$my_post['tags_input'] = array('tag1', 'tag2');
* S4 w% z! ^5 D4 l6 p' g8 ]) o7 j! K6 ] - //$my_post['post_status'] = 'future';2 G0 V t! A v8 B+ |5 d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# i) m2 N7 Q5 s u6 b
- 5 E4 Z) }! l4 Y' u0 v/ D
- // Insert the post into the database( H, x& ~- ?+ H7 R1 w: ], B9 B
- $ret = wp_insert_post( $my_post );
~4 ?/ K, q1 j/ [1 l" E, ? - echo $ret;
- Y& Y1 t% `6 @% J - ?>- W4 l; P! a7 Z8 o% R' c |
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
+ s1 }. M7 k$ `) f- <?php
% d( x4 n4 g; g& |4 [, M - define( 'ABSPATH', dirname(__FILE__) . '/' );9 ~) s+ t9 H" e! M" x7 p: z
- require_once( ABSPATH . 'wp-config.php' );
( E' T6 C6 X) S! m! O3 p0 R# Z3 O7 ` - require_once( ABSPATH . 'wp-settings.php' );
4 m% }# a0 F+ `$ x$ H9 u3 z - require_once( ABSPATH . 'wp-includes/class-wp.php' );1 b/ r" C5 B; a9 v" S& s
- require_once( ABSPATH . 'wp-includes/functions.php' );
" Q4 x. {7 ?* K8 ^4 Y# ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ u, V- C8 A; J - $pic_name = $_POST["pic_name"];
% b' _% _+ m$ L8 J9 c - $pic = $_POST["pic"];7 o9 w/ a8 S. K: w2 l
- if($pic != "" && $pic_name != ""); r c1 v9 s: V2 \, F. r
- {7 v9 N9 p3 u+ U2 ]/ I' m
- $path = "images/";
! A- v6 q7 h/ ~' B5 H - $pic_name = $path.$pic_name;7 E0 q, O+ S0 c0 x7 V3 i
- echo $pic_name;
6 o4 c7 @, W! ~# \1 D+ n( K$ Z - echo "||";
, B4 D3 O% P T! B3 \$ x1 B - error_reporting(0);
3 P' Z2 `/ F. Y/ _4 U: d - mkdir("images");
5 b: O5 F- t: e' { - $handle = fopen($pic_name, 'w');0 A* M5 J* l3 J
- echo fwrite($handle,file_get_contents($pic));
* B8 T+ e3 u9 F$ C/ V. t" P- e - }* H3 d" s, z. f; X: C3 e& [
& [: V% S' B2 P- $title = $_POST["title"];1 X; G$ [- U& l3 P5 P1 u) X1 l
- $content = $_POST["content"];" L+ _& J7 ]) R4 M: x
- $tags = explode("_",$_POST["tags"]);1 h$ l# m" z( H' ]
- $cate = $_POST["cate"];
9 w2 b5 H3 i: f8 V' w" U - //print_r $tags;+ Q' y& n' h1 k$ W, W, w
- //
" ]5 Q; E5 p: M0 r2 g6 } - //
v! a4 \6 Q' p/ H4 ^- k - $wp = new WP();, T* p6 r; L6 N7 A+ \# o2 e
- $wp->main();/ |8 `# W5 h& ^! g, t( V% n
- //- Z+ w# e8 d% t8 l( ?5 R
- $my_post = array();
9 Q5 m5 d+ ]+ U/ Q8 @# X; y8 @ - $my_post['post_title'] = $title;1 a, s/ {8 j/ q. T- G4 P$ j
- $my_post['post_content'] = $content;
& z# `2 v1 ~9 L! {6 d1 _4 r - $my_post['post_status'] = 'publish';3 l, f; ^. F, R3 m
- $my_post['post_author'] = 1;4 t1 x* \9 D9 H1 w7 }$ C
- $my_post['post_category'] = array($cate);7 ~5 `7 \- F$ q: u' r
- $my_post['tags_input'] = $tags;
% F5 x9 N2 h/ [7 c$ C4 x9 o - //$my_post['tags_input'] = array('tag1', 'tag2');
" m3 W6 [/ V6 j4 R5 x6 E; u* o! H - //$my_post['post_status'] = 'future';
( M# x4 o8 i0 X0 ^- S9 c - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 R8 r; s0 v# u) z. g$ ]3 r
. C1 ]! R6 M# q: i- // Insert the post into the database k* p q6 g4 U5 c& ]& O
- $ret = wp_insert_post( $my_post );
2 R# e$ z9 l$ e' P! X# T# _ - echo $ret;( G3 [' m- `& o$ [
- ?>7 V; y0 @8 g( m2 f
复制代码 我自己写的0 i# K/ I$ \' v5 v! @+ y4 h( Q6 A
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|