|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
4 x$ w5 r( S2 o; U: o* X5 Y5 N: g$ S
" F$ t4 A1 U# W1 b直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持5 |9 a n5 l- C% W m- i
/ R, X" r8 m0 [5 _, O$ C我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ ^ a1 \! Z2 Y- o- X) }( D: m7 [+ l) _% M4 E( \: I
方便实用 简单 何乐而不用呢- L, Z6 P0 w3 V& ?% V
- <?php i0 d7 |- j1 }4 h+ c6 ^+ V
8 ?: w- l u8 }* N/ M4 {- define( 'ABSPATH', dirname(__FILE__) . '/' );9 g& Z! Q' @3 ~% I5 K
- require_once( ABSPATH . 'wp-config.php' );
/ l+ l$ z+ @: t. x$ W) e! V - require_once( ABSPATH . 'wp-settings.php' );) I5 W" L7 `) Q# I
- require_once( ABSPATH . 'wp-includes/class-wp.php' );0 W3 g# f7 g" Y5 U
- require_once( ABSPATH . 'wp-includes/functions.php' );
# q0 X/ F& s$ x3 X4 ?" N - require_once( ABSPATH . 'wp-includes/plugin.php' );
# U* c M% Q$ y( A' n6 w7 y - $title = $_POST["title"];
3 e4 D- H/ ]4 ?5 k; e& w3 _- } - $content = $_POST["content"];
' v4 C" P0 J& ?/ B - $tags = explode("_",$_POST["tags"]);
* I" p/ p! t& g6 ]6 F% z - $cate = $_POST["cate"];
# Z }( C+ Q7 P9 Q: { - //print_r $tags;: G" O0 Q" {# M4 ?4 W' g: ]$ a" L" C# g J4 m
- //) o, x- n. ~+ H
- //$ w* a l3 C$ u5 @% b, q
- $wp = new WP();
2 f# N& e/ L2 _1 y% o1 B V- R - $wp->main();
9 F8 z5 |7 R! Q) r& q8 Z! S6 r - //
( W, M7 {+ k, G+ a7 P% b. m - $my_post = array();1 F7 }$ E6 U# [" o9 s# N9 J
- $my_post['post_title'] = $title;" ]: D) R& R9 J4 P
- $my_post['post_content'] = $content;
$ r. y# s/ ~; r9 u8 ]/ s - $my_post['post_status'] = 'publish';! B% J/ F! w; R: {; \2 \+ ^: K% A
- $my_post['post_author'] = 1;
' T" D) }3 o$ R8 p6 |! Q - $my_post['post_category'] = array($cate);
3 ]$ o& z9 z9 U - $my_post['tags_input'] = $tags;/ |' g$ {( {. y+ ? t8 g+ v
- //$my_post['tags_input'] = array('tag1', 'tag2');
8 [0 Q7 K' f: B3 k) X0 o8 K4 c - //$my_post['post_status'] = 'future';7 F* h# u ]5 I# z- d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
A) }1 f3 ^' X- Q
' Q0 l( ?4 \! G: U+ N3 f- // Insert the post into the database
- H: b) a5 L5 o; p2 U - $ret = wp_insert_post( $my_post );& |9 Z+ }" p& [6 h1 H7 k. d
- echo $ret;5 l# \8 D' C( U; }
- ?>
5 Q, s+ ~; l! A' ?7 N) x f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 2 `9 ~" A5 h9 ~( s! f& b# |5 j
- <?php7 [4 M3 x1 x1 K, _4 G/ M
- define( 'ABSPATH', dirname(__FILE__) . '/' );
2 f/ s0 n# S! u1 j! _" O' M - require_once( ABSPATH . 'wp-config.php' );+ i# P3 V% h8 [! F1 g# F( ^: C+ q
- require_once( ABSPATH . 'wp-settings.php' );
7 O- X9 r' @0 e; V* R6 T( d) d - require_once( ABSPATH . 'wp-includes/class-wp.php' );3 P. [) h3 {. c9 a
- require_once( ABSPATH . 'wp-includes/functions.php' );
( s9 [# a p1 l- o; q - require_once( ABSPATH . 'wp-includes/plugin.php' );
' `: `, Z' W E$ ~: D - $pic_name = $_POST["pic_name"];( y# ?. b f7 c% x
- $pic = $_POST["pic"];+ e* ~$ Q! \7 P" k9 d
- if($pic != "" && $pic_name != "")
) {* Q' r' w+ b3 r& \ - {/ T- @- w5 Y% |$ H3 d+ z7 g4 H
- $path = "images/";8 d' p! q8 X0 O8 y* \# y a
- $pic_name = $path.$pic_name;, \# d: [; K w/ j( O5 `* u
- echo $pic_name;
8 g/ d- a* ~. ] G - echo "||";
0 n( J) J+ G+ e; ~) } - error_reporting(0);# x, j6 |. f: ~' \- u* e3 s
- mkdir("images");
! c6 n' O5 b; f% b, ^ - $handle = fopen($pic_name, 'w');7 x, L3 }5 L1 U5 x
- echo fwrite($handle,file_get_contents($pic));
- B( K+ ?6 Y+ y- { - }
# L: o2 i4 P; U2 z' H0 R - 3 f1 z7 o t; r( s' _' h7 b/ K6 U
- $title = $_POST["title"];+ F4 k! }& F; t# n* F" |
- $content = $_POST["content"];" j& B7 P) w$ F" m3 k% V
- $tags = explode("_",$_POST["tags"]);
5 j0 q: E; d( X5 A/ T# e! b - $cate = $_POST["cate"];* J9 O! E/ ^( O1 z4 r" x/ m
- //print_r $tags;
* \' u7 m8 Q% M1 n5 N$ U: A - //
, d8 Z. U( G8 S7 K6 s: J* L( L - //
! @0 A9 L3 ~9 b5 d - $wp = new WP();# j0 y" B" Q% |8 {( g) v6 ~
- $wp->main();
5 b% `8 Q$ {* o! n/ Z: ^) D - //9 i( a: W6 }* W, I5 v, b1 b& Z
- $my_post = array();8 X0 _8 \$ W; O% L0 N6 K* K
- $my_post['post_title'] = $title;
( _3 a9 h+ r* @ - $my_post['post_content'] = $content;) ?! I9 K4 K L/ z9 f0 i8 u% `
- $my_post['post_status'] = 'publish';: I* y( n% g. ~7 s7 X
- $my_post['post_author'] = 1;+ S- }. y4 a6 L) |9 H# \
- $my_post['post_category'] = array($cate);" x& v, J$ c8 i* @1 B. J! e( ?
- $my_post['tags_input'] = $tags;& n* b7 s' J# i7 s
- //$my_post['tags_input'] = array('tag1', 'tag2');7 R9 |, m* Q# n* ?
- //$my_post['post_status'] = 'future';
' N3 K. h: S, m! f - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 ^9 L, @& |8 D# m4 q | F; A% b$ K
- % C- ~7 I0 C. C1 d0 q
- // Insert the post into the database
0 ]: ]* P, P& U1 h1 k7 S - $ret = wp_insert_post( $my_post );: z$ Y4 c; K3 I9 o$ m7 l
- echo $ret;6 C4 l( t$ ^% f3 I8 F, ?6 e" H
- ?>
$ o2 P- I! W( `
复制代码 我自己写的6 S3 M2 ~$ Y( `6 g; R, `
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|