|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 0 j7 Q' [6 @5 [! I2 s& D. [
4 I* j5 o% k7 s6 C( m" U0 k5 B Y( L直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
4 A( r- d; v9 g6 {9 p
; d4 K9 w6 i& u2 i" G; u0 h% H* w& j我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# D4 V; Y1 n0 t$ h& I F' T
! [+ J7 k- F+ q7 H% d
方便实用 简单 何乐而不用呢
/ n0 p0 A8 t' u* t& _- <?php/ R# p# Z" k" o4 f. \% a. P: f
3 l5 V/ r' `8 }3 y- define( 'ABSPATH', dirname(__FILE__) . '/' );7 G# t8 E; Y/ A+ v6 Q/ W) n
- require_once( ABSPATH . 'wp-config.php' );
5 S- B6 ?+ D4 W - require_once( ABSPATH . 'wp-settings.php' );
}" T4 ~$ b* Z8 X! l4 O# Y - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, V# v2 i5 b2 I% O6 `8 u - require_once( ABSPATH . 'wp-includes/functions.php' );
- B6 S2 }2 Q& v4 a - require_once( ABSPATH . 'wp-includes/plugin.php' );, U3 {' |9 B1 X$ M
- $title = $_POST["title"];
# p, S* `. O5 \, w - $content = $_POST["content"];
8 ]& A* M! w/ u% K# e7 o - $tags = explode("_",$_POST["tags"]);( Y7 ~& U( X7 _" ^# l% J: L# u4 l
- $cate = $_POST["cate"];( V# k% e5 R7 A, x, g
- //print_r $tags;! P- f& Q5 l# V# g7 Z
- //
5 Q# u$ u% {$ F5 n# u& p& a - //
# }$ Z, e+ {: ~" l1 f' Z9 o$ V/ A$ } - $wp = new WP();. t! \9 e2 Z/ Q! p. g2 G w
- $wp->main();
+ O, ]# X$ [9 P- W ~5 r3 @ - //$ R8 `! Y; h2 ?" N' R
- $my_post = array();( e6 l- z2 F" @& v! m
- $my_post['post_title'] = $title;
7 E- g8 L% t" D q% z! k. S: v3 ] - $my_post['post_content'] = $content;5 [2 h, H& _: o0 X. I/ `
- $my_post['post_status'] = 'publish';0 ^8 c7 d9 t7 L0 K& Q
- $my_post['post_author'] = 1;
" Q% O% |. u' e' I y - $my_post['post_category'] = array($cate);
& b* _3 g$ a9 P- H) V" d. ^ - $my_post['tags_input'] = $tags;: ]% F4 k+ q: m7 X3 ^& L
- //$my_post['tags_input'] = array('tag1', 'tag2');. ^5 ? j- h1 ]% @' u7 q9 }9 a! t
- //$my_post['post_status'] = 'future';
) y2 W2 |1 }: y& I4 s2 ]+ K - ////$my_post['post_date'] = '2010-07-04 16:20:03';
) C7 ^* {+ r) d" L; o M* C7 a9 i
% [& b, U' r% w- // Insert the post into the database6 q+ M' A0 o1 F
- $ret = wp_insert_post( $my_post );
- K v5 f" A+ m/ g - echo $ret;& F. S; ^6 B2 J, {% |
- ?>
7 t& i* x) a4 C) j7 H# H
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
5 I" O, w& Y: ~0 ^- <?php
0 [ |2 L$ ?& U6 F - define( 'ABSPATH', dirname(__FILE__) . '/' );
. r& k( Z( @; x; j - require_once( ABSPATH . 'wp-config.php' );
+ G! o( w/ l1 s - require_once( ABSPATH . 'wp-settings.php' );. t$ j" U% L" H1 E* y+ B
- require_once( ABSPATH . 'wp-includes/class-wp.php' ); e; k. f* o, v+ R* Y6 i6 U
- require_once( ABSPATH . 'wp-includes/functions.php' );
% P3 z. w& u. I8 P7 K$ \9 Y y( l! v' o8 W - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 i2 Q- ?' I3 P/ U# Z - $pic_name = $_POST["pic_name"];3 ^8 `1 G/ f0 t2 D4 n; `
- $pic = $_POST["pic"];
: D! t9 ~9 |- K, V - if($pic != "" && $pic_name != "")5 p V4 [/ {. X3 t) f
- {
9 D1 c7 o" l6 q% [2 T7 \' u! E - $path = "images/";
0 ^ F5 f9 q9 W- Q - $pic_name = $path.$pic_name;
& c: ?# B( K2 b( ?6 R" ? - echo $pic_name;. B0 _9 v# [3 o' |* d
- echo "||";$ O5 s9 T* F' p6 y5 ]5 M
- error_reporting(0);
# J/ p4 {0 Y/ i9 N! z* Z - mkdir("images");% t) \5 o( k) a* Q6 n, M6 P
- $handle = fopen($pic_name, 'w');
5 J/ g1 Z5 r. }" ^7 ? - echo fwrite($handle,file_get_contents($pic));0 P& S+ g3 ~# Y; v+ w
- }" D) ~1 w) {0 a' p$ U
- + T' e0 C5 N D6 d t7 v* j
- $title = $_POST["title"];
* p; b, E" B a+ U. @$ S- r - $content = $_POST["content"];: M* ~: S" T! t& l* Q. f0 _# I
- $tags = explode("_",$_POST["tags"]);
; X8 j4 F4 U. K3 Z! O - $cate = $_POST["cate"];
7 ?7 u! L# [8 W8 X - //print_r $tags;
* v+ [0 |6 W+ L* V$ A) B% j - //
/ L! d D+ Z/ o5 I, t4 T1 h - //
/ D( W. }+ m( `& w( Q) c - $wp = new WP();
/ J9 \$ L' _6 U' H7 }8 _. | - $wp->main();
" m- u+ a/ N1 C9 B2 z8 Q. z - //: Z* B! y/ o3 u
- $my_post = array();
5 w8 `7 n' {9 B+ B& J s - $my_post['post_title'] = $title;4 E. S2 w& `+ [& I4 H
- $my_post['post_content'] = $content;/ q+ s! B$ S i2 K/ }
- $my_post['post_status'] = 'publish';
4 i3 L; F0 p5 V: h5 I, O* B - $my_post['post_author'] = 1;
" l% {/ B: M. [5 T" N - $my_post['post_category'] = array($cate);0 u/ j! c# c5 T
- $my_post['tags_input'] = $tags;
& i+ J; D$ k: q" x5 \$ N/ ?- J - //$my_post['tags_input'] = array('tag1', 'tag2');
$ Q5 q9 ~) R6 j% p/ f8 Z3 E* \ - //$my_post['post_status'] = 'future';
m8 m3 T" R) F, C/ a3 ^! { - ////$my_post['post_date'] = '2010-07-04 16:20:03';' @1 _2 S, c: q
: h0 l% x( s x" P' Z/ ?) o- // Insert the post into the database
9 e$ X b; x1 Y) G: V - $ret = wp_insert_post( $my_post );
7 u5 ^- d& {% f- p7 K. k3 C3 l - echo $ret;
5 u$ }* T: h- G, d0 ` - ?>' d+ i7 j$ A) \) z
复制代码 我自己写的* V# f+ ^& G' X
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|