|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
( c! h$ S5 l" c- L3 p1 o( g6 ]0 L/ z" s! p
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% F a5 w' Y( N, D
" {4 f& n* ^! x: j* w5 c我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; F+ Z% q* [- J- ~4 p
/ o) L8 q x# t8 C: B: E方便实用 简单 何乐而不用呢
h6 @6 G1 |) A" I1 ?- <?php/ P1 ~5 m9 t* J2 {- Y- n; V$ f
% J4 W; q- q; n: J# F- define( 'ABSPATH', dirname(__FILE__) . '/' );
- M' m* z3 r% `7 ]1 o - require_once( ABSPATH . 'wp-config.php' );5 n" S: x; i7 o2 y" G
- require_once( ABSPATH . 'wp-settings.php' );8 V0 w1 f4 O" O4 C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ ^7 H" j4 k( _. _6 d - require_once( ABSPATH . 'wp-includes/functions.php' );
6 `8 G/ ]/ Y% ]1 p5 F5 ~6 L3 g3 e - require_once( ABSPATH . 'wp-includes/plugin.php' );$ p# o% L3 B) e$ {% ?
- $title = $_POST["title"];- x$ m5 V8 e2 C+ F& }5 ~" z- n
- $content = $_POST["content"];: G' E5 G3 p. H! ^: H
- $tags = explode("_",$_POST["tags"]);
M: h5 j3 R8 w7 c+ K3 m3 z6 U - $cate = $_POST["cate"];- d! D' @1 ?) d( m! W) C, \
- //print_r $tags;
0 w3 \! c" t$ J6 U0 b. i - //
u4 U. q8 t" z$ n3 s5 P$ ]( a C0 R. ` - //4 D& I; \. X& D7 I
- $wp = new WP();
9 ?" }4 x+ b( E1 N ` - $wp->main();
# q0 y/ V& G* d; M( h9 W- I( U8 F/ c5 E% w - //
/ I" P/ S$ K' _! a V - $my_post = array();
% o$ y* n& g5 |2 _ [; U8 ~7 c - $my_post['post_title'] = $title;
+ R4 M9 _" D- b5 c9 D8 } - $my_post['post_content'] = $content;
. }( R1 o$ X3 h( Y* G+ X6 R6 q - $my_post['post_status'] = 'publish';
5 P- P' A1 k- x! G1 R - $my_post['post_author'] = 1;
! ]. l# s; |2 S. O! b$ p$ R - $my_post['post_category'] = array($cate);
' J! i1 w2 ^+ i' o: U( [4 ~ - $my_post['tags_input'] = $tags;0 l; s4 m; f* n: s- G4 o5 S, ?5 c
- //$my_post['tags_input'] = array('tag1', 'tag2');" g, M5 ?+ V+ G/ _" Z3 H
- //$my_post['post_status'] = 'future';
m* a1 O0 y3 z: v6 \2 _( j8 q - ////$my_post['post_date'] = '2010-07-04 16:20:03';- m: J; p* b( b5 ^3 N, U& f
9 n% ~ K+ `4 M- // Insert the post into the database
, ~& z. V; }$ N - $ret = wp_insert_post( $my_post );
3 J+ h5 M' s% G2 W - echo $ret;# u( n# b! [# F/ R
- ?>
8 K1 k. r! M$ n3 G
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 5 a, v5 ]* e& D$ d- t8 ~, z
- <?php! @" b: N: a x, M3 @( X7 [
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. I' m) P$ ^/ B8 ` T - require_once( ABSPATH . 'wp-config.php' );6 i/ j" `' ^8 S2 z
- require_once( ABSPATH . 'wp-settings.php' );, M# P# ]+ \: j2 T# q; l. O3 ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );& H9 t0 r6 m+ u d5 m8 l- G
- require_once( ABSPATH . 'wp-includes/functions.php' );3 N' `) o: ?# n+ x
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ x/ n( J4 _' G
- $pic_name = $_POST["pic_name"];. A# w- A) y1 i; O) ?
- $pic = $_POST["pic"];. a2 E2 T4 u$ ?# h1 c2 X; n
- if($pic != "" && $pic_name != "")
; s/ t8 {# `0 U8 v+ j9 Y" Y - {$ c2 y& i! g& p7 I8 L2 }
- $path = "images/";& L* S7 Z! c9 H, F5 U, e: r
- $pic_name = $path.$pic_name;
+ s4 T5 b% U6 c - echo $pic_name;' Q+ W: R" a, I+ }1 l3 @
- echo "||";
& X$ Q' U; E J1 L# i* w2 s6 s - error_reporting(0);
% Q3 D$ ^7 }( Q6 L - mkdir("images");
: h) r6 G& F6 J; o3 K% | - $handle = fopen($pic_name, 'w');
; l! g9 c# h3 E2 v5 b* B - echo fwrite($handle,file_get_contents($pic));
0 y! |; f% [! i# X - }' y& _* o. i3 [! _! M3 p5 D' N9 z
/ U ~4 o+ n, @# l P5 u- $title = $_POST["title"];
6 N- h( F: l6 a5 ]+ n5 N! a+ T - $content = $_POST["content"];, `& I' H, m2 G, y: J- e0 T
- $tags = explode("_",$_POST["tags"]);2 _9 W6 o1 r5 B/ n- Z( T6 a
- $cate = $_POST["cate"];
" I4 m& R; I" _+ d - //print_r $tags;
, \% N" k8 N+ H - //2 R$ G! d8 }3 h
- //
9 N. I- T# y# N6 ~4 f( X2 H - $wp = new WP();4 }: l/ t+ [1 y7 p1 E$ U! v
- $wp->main();! q( u+ F7 P' \% t1 b$ L
- //- r$ U( H( x9 R3 t
- $my_post = array();+ y9 b! v/ k. O. f$ i9 D5 X
- $my_post['post_title'] = $title;
$ u& t1 S4 E% ] - $my_post['post_content'] = $content;/ j, k" d2 C4 ^! r4 O4 k2 j; p
- $my_post['post_status'] = 'publish';
4 A0 T9 T9 X4 d6 e - $my_post['post_author'] = 1;' ]( m* t: S/ F3 D
- $my_post['post_category'] = array($cate);
* _% O/ ~5 q" G- v5 ?# t. M5 E - $my_post['tags_input'] = $tags;
$ N) W( [' x+ v ~+ T* [0 X - //$my_post['tags_input'] = array('tag1', 'tag2');7 x7 z/ N1 i! A
- //$my_post['post_status'] = 'future';
. V+ H& [6 A" P! G( h; U- y4 w - ////$my_post['post_date'] = '2010-07-04 16:20:03';! n; w% r; Y& I% Z: x- ?
6 p" o9 K Q! g7 u' }- // Insert the post into the database' \& b3 m, T0 k+ o% p8 b7 M
- $ret = wp_insert_post( $my_post );" \; K: d1 W9 _/ v4 `
- echo $ret;
) D }, D5 |. w1 n - ?>
/ Z7 g" Y* o" {0 I0 @! J ~
复制代码 我自己写的: t, f9 Z& V; k- y& r
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|