|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 0 {- V- j4 i7 C; I8 O& Q) ^3 f' D
* ^- l/ |3 n& \3 W# W直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持0 |" R) k/ |, D0 Z1 U* B3 D d
5 B, J3 r5 j* a- \我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
# t" B0 T A! h
) ^4 Z' _6 Q9 i7 Q7 ^方便实用 简单 何乐而不用呢
2 C1 D2 h) _7 J" ~! M* l) ?- <?php
' ^+ r! t4 N4 D' K+ ]" c
+ X) \: n, {+ e- ~- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 P+ O: x/ ~3 t) Y/ U# W2 b8 g - require_once( ABSPATH . 'wp-config.php' );) a6 T1 a5 L+ I; t! F6 H( ], w% b" @
- require_once( ABSPATH . 'wp-settings.php' );# I9 p9 c3 F2 f- _- G: b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );+ o) Z4 x/ z# I" K
- require_once( ABSPATH . 'wp-includes/functions.php' );" g! ]8 x) i) F; D
- require_once( ABSPATH . 'wp-includes/plugin.php' );4 c; g! k1 f' [) w4 o
- $title = $_POST["title"];0 ~& [0 x# s' L0 F3 o2 v g: b
- $content = $_POST["content"];
5 j3 h4 A6 @0 k - $tags = explode("_",$_POST["tags"]);7 w4 a5 [, g \* K9 y/ W/ a! F* G& B
- $cate = $_POST["cate"];8 h: Y% Z; ^# x9 m2 `
- //print_r $tags;
3 i& i6 y, @4 ~ - //! \2 J1 l0 g [' L
- //3 c5 }8 j! m5 y( a- v: C- @
- $wp = new WP();
/ Q% H. ]- \* J6 _ P2 K" D - $wp->main();
, M3 ?/ R; C: D/ C3 O. \, q* u+ i - //
7 [1 [# c! k- v! L- V4 u# u4 [ - $my_post = array();
- }3 E1 G6 N, j. j) y# h - $my_post['post_title'] = $title;7 H# O( n" f8 ]! V+ n, G
- $my_post['post_content'] = $content;/ [3 R9 A8 E5 q/ m) h
- $my_post['post_status'] = 'publish';% H. K+ W% W1 n& q
- $my_post['post_author'] = 1;2 ], `: W* z6 \+ U) `
- $my_post['post_category'] = array($cate);$ k9 r/ C" V9 C, B# j# {
- $my_post['tags_input'] = $tags;
U+ I" _$ p m: i/ q. T - //$my_post['tags_input'] = array('tag1', 'tag2');; D0 N' ?/ H3 \& ]) {1 C
- //$my_post['post_status'] = 'future';
8 e' U! p% g4 b7 W$ B' _1 `& S2 {% c - ////$my_post['post_date'] = '2010-07-04 16:20:03';
) Q0 C2 h( X1 `; Y - * l: x- D+ v( o. S
- // Insert the post into the database
. {: b# A; ]4 h& l1 A - $ret = wp_insert_post( $my_post );0 \$ W% M" t: U# p" h" E. D) N
- echo $ret;8 y# @' i0 O0 y$ A# v p0 f+ [
- ?>
- A, y: F1 [6 v! h$ b4 z: \) C1 t# g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, x- e- P, X4 G( p Z% g- <?php
) Z9 D4 Z) W7 M& P$ s! g- s - define( 'ABSPATH', dirname(__FILE__) . '/' );
7 `: n% X( [( B/ W - require_once( ABSPATH . 'wp-config.php' ); J- k) t: B' ]! x% Y
- require_once( ABSPATH . 'wp-settings.php' );
2 o1 D: [) Q( O - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 k2 |- y; @- d6 q' n8 q& A
- require_once( ABSPATH . 'wp-includes/functions.php' );
, j3 G( L- }5 j8 T6 | - require_once( ABSPATH . 'wp-includes/plugin.php' ); n# s. w( z0 Y# l f/ W* ]
- $pic_name = $_POST["pic_name"];
' c0 \9 M% W8 w6 y; p% W - $pic = $_POST["pic"];
! M$ H! n) W a0 ]: }4 y - if($pic != "" && $pic_name != "")
7 z2 N5 i4 m' F" `+ B8 b; V - {
, J) d+ r. T6 {0 c' z: i# X - $path = "images/";
* N3 s5 }- H( L4 F - $pic_name = $path.$pic_name;: v$ L9 t' a2 `* e M8 ?
- echo $pic_name;/ q) @2 n0 c' g
- echo "||";+ @+ b+ p+ ], Z4 I
- error_reporting(0);; k e! Q# l% ?
- mkdir("images");# p5 \+ D5 F3 M) S+ @# k
- $handle = fopen($pic_name, 'w');
3 J- b+ Q9 l# m - echo fwrite($handle,file_get_contents($pic));- f- b/ D& E6 \; F& E9 u# s' r( q
- }6 ^- c$ f" y5 P
( w" T8 W) z4 m2 \ F5 k# ]: q- $title = $_POST["title"];
* J! k9 I$ n2 R( A) }% L+ w - $content = $_POST["content"];
* {& a& b3 i |5 j# K! D/ n - $tags = explode("_",$_POST["tags"]);6 s0 G' U; ]2 ?2 }! E( b
- $cate = $_POST["cate"];
) f; |1 o! M3 f6 g. G. `) v - //print_r $tags;/ L+ N% [ }& D) v& Q- I' Y( r
- //
/ X6 q1 A" f) \) B& w$ Z - //
9 G! y z* `8 O& { - $wp = new WP();( [! A. ]" J, T* z9 c6 c$ x4 X# L
- $wp->main();
* l- S1 j$ F9 x( y# ` - //
+ f- s" e7 g& k - $my_post = array();
) W2 k" Q& v$ X+ j: \ - $my_post['post_title'] = $title;
; O& I) e9 C2 r! J- m; s$ z# \ - $my_post['post_content'] = $content;
# o5 Q8 B( n3 T4 H$ o0 p - $my_post['post_status'] = 'publish';5 {# [' a& r- S. S
- $my_post['post_author'] = 1;1 e4 ~3 b4 \+ ?' j
- $my_post['post_category'] = array($cate);
& Y6 @+ b* X' i$ ^# W7 L - $my_post['tags_input'] = $tags;
$ E( E, D# Z# W - //$my_post['tags_input'] = array('tag1', 'tag2');
, d$ Q, l* P7 d - //$my_post['post_status'] = 'future';4 h+ V/ e1 B' b- B; X7 s* e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 Y7 S' n- P. e, [1 S; J4 Y
! y1 I2 z$ u/ D. S6 w7 D7 R- // Insert the post into the database
1 j; b/ z4 E+ W! q# |% z - $ret = wp_insert_post( $my_post );
D1 e& n# h) W3 M9 }( y - echo $ret;4 W2 a0 r, T/ @* s6 b; {( X4 O
- ?>
. u% K2 a% o: Z' G9 P
复制代码 我自己写的
( R/ Q. r2 m: U _- |; t" I D插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|