|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & b" Y9 |; g6 ~& X
& G+ m, _1 T3 S8 r/ e) w# c
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持& {3 Y- j* n# }- Q2 z2 b
( ^2 L* Q7 l" ^2 T' \- B ^8 m
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
% V1 x# j( |4 F5 Q8 A& I' c% ^% I: c) D4 ^0 T* v5 t1 [6 ]1 ~
方便实用 简单 何乐而不用呢- / J6 C' X$ q- Y0 { Z
- <?php- k& M" ]: P4 W2 j! l1 T
. q1 B9 n& n3 B- v( m; t- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ S, V: [3 @. t% n' a! f) q% M0 G! b- d - require_once( ABSPATH . 'wp-config.php' );) w/ s: ~+ u. l
- require_once( ABSPATH . 'wp-settings.php' );
1 H5 p& ^; t$ m* N7 d) V# c - require_once( ABSPATH . 'wp-includes/class-wp.php' );1 j1 F3 I4 ]5 S0 k' ~# M( C2 L
- require_once( ABSPATH . 'wp-includes/functions.php' );
( q" A7 x+ @5 m1 m; ^ - require_once( ABSPATH . 'wp-includes/plugin.php' ); E9 t: z! U6 p6 s! Q w
- $title = $_POST["title"];
7 C& W2 y. [+ C. `! j* s% x9 c - $content = $_POST["content"];
- d3 N" b; A r- ]% y6 @% U" l, F - $tags = explode("_",$_POST["tags"]);
4 a5 l) C0 Y1 Y3 o/ B) k, E - $cate = $_POST["cate"];
$ Q; z. c$ z! h" @ - //print_r $tags;
% P8 |; x! }: S+ ~. ?! }! R2 w/ f4 ~ - //
. Q2 H$ {8 O7 Z+ H2 a' }: L0 q - //
X5 ^, E* S/ ^& \6 x3 A1 p - $wp = new WP();# b; @6 s0 x/ I7 b
- $wp->main();# `5 ~+ f; V4 q8 P. U& l |
- //
, m+ K" d- H9 u- @# c) H - $my_post = array();
% c9 ?3 \* n7 Z - $my_post['post_title'] = $title;
. e2 S' z1 E- v! s - $my_post['post_content'] = $content;/ {2 U3 K8 c9 b/ i
- $my_post['post_status'] = 'publish';
' s0 X/ [( e* N3 @8 P/ G' F0 o$ L+ H X - $my_post['post_author'] = 1;2 J# x( t( I: t
- $my_post['post_category'] = array($cate);3 A/ S* Z2 ~$ h
- $my_post['tags_input'] = $tags;
- _3 g2 _1 M3 p' n: t1 L - //$my_post['tags_input'] = array('tag1', 'tag2');8 u2 O" Q! ~3 c. M. x8 {0 J* `- z9 K
- //$my_post['post_status'] = 'future';+ ^) t* [' O) b6 `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' O+ _) q, ?5 {6 _' B - ' v5 h9 U+ t4 W9 j6 t, e) R. t3 y
- // Insert the post into the database
+ w& w4 G) _0 K% ~ - $ret = wp_insert_post( $my_post );
+ E" A/ B f$ @* X: l, i - echo $ret;
$ a- y: z. ~; S6 O4 v5 o! ? - ?>
$ ]& R& g3 q! }# G% _/ g' c
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 ~( H+ z4 Z9 d7 }# ~- <?php# U( n1 z6 D) x n. d$ @
- define( 'ABSPATH', dirname(__FILE__) . '/' );3 j( K- q) I7 ^1 z8 H+ B! N
- require_once( ABSPATH . 'wp-config.php' );
7 K7 ~6 m$ @+ q- ^4 U- I9 K- h - require_once( ABSPATH . 'wp-settings.php' );
9 s- C, l7 @% L& `& Y+ C - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 H: P0 O1 d$ i9 K
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 a! G" L4 C0 c6 e. f) U% u: s) s - require_once( ABSPATH . 'wp-includes/plugin.php' );) @7 F" J% d9 X
- $pic_name = $_POST["pic_name"];
2 K! J5 d! A, ?; }1 \ - $pic = $_POST["pic"];- M9 H5 n( k1 h, j5 F0 q1 Y) u
- if($pic != "" && $pic_name != "")" C: n7 _$ n/ D( q. H% a
- {
3 S7 }7 A$ x0 }; ~/ ~7 ?, b - $path = "images/";7 o3 U9 L( Z( H1 k B7 Q
- $pic_name = $path.$pic_name;0 l* _! Q# Y, j- Z' o) r
- echo $pic_name;
6 y1 J# p' o8 n - echo "||";
! ^. l/ Q4 {* W- C( c - error_reporting(0);" L9 r6 v+ m& N; V5 }3 \& v, H
- mkdir("images");3 J* w* V( O1 v& |: J7 I' d6 g
- $handle = fopen($pic_name, 'w');2 Y) a1 c$ _$ I, p0 E( B$ g" M
- echo fwrite($handle,file_get_contents($pic));
1 \: t! ]/ O B - }
/ b( }5 ^/ f! _9 X q/ Q' u) k4 } - 6 H% }1 {/ _" ]7 W7 _0 t) ?
- $title = $_POST["title"];- i3 P# k* y( X. {
- $content = $_POST["content"];
$ R+ D, i5 g" Y1 N: o% `3 A - $tags = explode("_",$_POST["tags"]);
; @1 T: M3 K, w/ t. n* p- U - $cate = $_POST["cate"];8 o7 y& k1 i; p7 {) P' n9 S( ~
- //print_r $tags;
1 `2 B- U* O0 H- K( q - //) K- n7 i1 X$ P
- //
+ P9 I$ G w6 A1 M - $wp = new WP();& X3 u5 S# C/ h# ?* _" a
- $wp->main();
0 e. m I- N! R* v - //
* c+ R3 T) n; N. K - $my_post = array();
) u0 |" S) q m - $my_post['post_title'] = $title;; e- w* i* W! X2 `# n3 ^1 _$ [
- $my_post['post_content'] = $content;
* ^4 h' N) P# k( Z0 O+ c9 K% e - $my_post['post_status'] = 'publish'; h# r8 v1 G" X/ N
- $my_post['post_author'] = 1;+ N* L; d" G6 T* N1 V$ y' K
- $my_post['post_category'] = array($cate);9 }3 Q# U! ~- l; ]+ X
- $my_post['tags_input'] = $tags;
' m) d! u$ t# I) N0 `9 l/ V! \1 D - //$my_post['tags_input'] = array('tag1', 'tag2');
: z* s5 l% C6 x2 ]! r - //$my_post['post_status'] = 'future';
) ]1 W9 y6 j' O0 m5 n9 { - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( R; _5 m" l: h% [6 q - ) C7 i' q( C: `" c
- // Insert the post into the database7 u) B9 ^4 N; _; |; N
- $ret = wp_insert_post( $my_post );
5 s( T% n$ @* p - echo $ret; E0 \ f* H5 y. z g( @4 A& e
- ?>
0 b) i7 G8 D3 a, V: m% A' q
复制代码 我自己写的, K& F9 z4 S* ~* m8 {
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|