|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 D* I B* y. W4 Q6 e+ Q
" l: @/ j' k, A- z; \# `6 r直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ D) \& m3 z( O6 ^
& A% {. D, ~0 @& ?3 k我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' H7 o! X+ l+ ] y; j
3 l2 G9 t4 S# j+ m2 p# ]/ T方便实用 简单 何乐而不用呢- ) y5 C; C+ {: j/ P4 u
- <?php
$ W& b& k" M% F5 j
- Y! t& q! \2 L( t" E' s- define( 'ABSPATH', dirname(__FILE__) . '/' );
# \! ^2 `6 J1 i" P7 w( G$ I& Z - require_once( ABSPATH . 'wp-config.php' );! N8 ^, s/ m& n7 M. B# F5 C9 i- y4 M
- require_once( ABSPATH . 'wp-settings.php' );2 h1 g6 b) V" J3 A. J0 c4 U
- require_once( ABSPATH . 'wp-includes/class-wp.php' ); ]; u% J% V& ?' n) d5 v7 @
- require_once( ABSPATH . 'wp-includes/functions.php' );
7 j9 w6 B, }* [/ `, X - require_once( ABSPATH . 'wp-includes/plugin.php' );7 f+ \' O7 {6 U: m" J4 m5 A. _
- $title = $_POST["title"];. R$ M P4 p7 E% L7 Q6 q
- $content = $_POST["content"];
: e2 U0 t7 l6 F& q1 a" d: M - $tags = explode("_",$_POST["tags"]);/ B) r: {$ v% w/ T5 }6 W
- $cate = $_POST["cate"];. y9 c3 T; h# D1 O J- g
- //print_r $tags;' R, F9 {; R; n; x. z9 N; O5 {( p4 z
- //
& X7 r* T% X- @' a5 A) A( S - //) x0 J. U/ C& y6 ~, |
- $wp = new WP();
% S; P8 l& B6 m4 r3 p* b6 s7 E - $wp->main();
) x4 e; e. }2 F; X! S - //# B6 L$ f- Q) g' S+ Z5 r
- $my_post = array();* z& `+ _. {& {6 U7 {
- $my_post['post_title'] = $title;
. h9 T' g$ T+ N3 e" \ - $my_post['post_content'] = $content;/ V5 E7 i7 u, i3 V4 {0 M: }% e
- $my_post['post_status'] = 'publish';; d7 A' w4 [" }! \
- $my_post['post_author'] = 1;, K/ w. D" T* a1 X/ p9 ]
- $my_post['post_category'] = array($cate);
9 m, Y6 ^( F. M) s: x - $my_post['tags_input'] = $tags;" C: k! g8 M6 m. m
- //$my_post['tags_input'] = array('tag1', 'tag2');/ J, P7 E( [! W% I1 s
- //$my_post['post_status'] = 'future';
$ ~1 \% L$ z8 a! H$ }6 |, X- }( r2 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';. i" s5 s5 L; l1 h( c
- % R" x V: }" Q# ~
- // Insert the post into the database
- U( q" y! {( d9 Y$ { - $ret = wp_insert_post( $my_post );+ s* H0 X( O3 n* d; R3 `3 Q
- echo $ret;- a; a/ I0 G, [0 i- }
- ?>% U6 L! S1 T B0 z) x& r: n- u2 v- ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 ~9 }5 n$ w; G7 S7 j- <?php
2 ^5 W0 O( x; _, |8 B7 ~ - define( 'ABSPATH', dirname(__FILE__) . '/' );5 n% U3 a+ d; j7 Y b- Y' S1 W
- require_once( ABSPATH . 'wp-config.php' );
' c5 G1 K2 v4 x0 e5 s1 `6 { - require_once( ABSPATH . 'wp-settings.php' );# A" e% j6 F6 T% X' R. b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 [( y7 N1 z" N. w( v, z% n
- require_once( ABSPATH . 'wp-includes/functions.php' );" h& z+ T3 F9 G' c. e0 v' y p
- require_once( ABSPATH . 'wp-includes/plugin.php' );
/ c9 r# x: d8 x! |0 P - $pic_name = $_POST["pic_name"];
1 d3 y$ b2 q: I - $pic = $_POST["pic"];, }+ E6 P4 z8 H; p- L& V
- if($pic != "" && $pic_name != "")
+ Q; q. F9 t1 v1 B) k! E. Q - {. X9 s2 D. t! B* i) ]/ L* I
- $path = "images/";: o% ?0 x3 \. x$ o
- $pic_name = $path.$pic_name;' E4 e9 k. n G' W
- echo $pic_name;/ s p4 a. _' f& Q$ M1 T
- echo "||";7 g& J, l+ F' c4 B1 C0 v1 l# w; s
- error_reporting(0);8 T* N# R9 N5 |/ h9 Z
- mkdir("images");0 J" K$ v* {/ B$ o9 {) }
- $handle = fopen($pic_name, 'w');. `; V6 y( @. I6 R7 n8 H7 l4 N8 n
- echo fwrite($handle,file_get_contents($pic));
4 w6 p. j8 T- ~+ n; {) A - }3 X9 C0 w& U* @- F
) r# [9 y8 p& ~, |. l2 g- $title = $_POST["title"];4 v& I7 f+ X* I# f
- $content = $_POST["content"];
1 E& ]% q! Q4 w! f% \5 ] - $tags = explode("_",$_POST["tags"]);" ~8 p7 i; H1 s
- $cate = $_POST["cate"];' V1 | s; m) t+ E% U d d
- //print_r $tags;
% N1 \' e- l1 Z5 t0 c - //
; u0 I# ?) j) p5 V/ H1 \) u - //
4 ?# f4 i5 S! y7 g0 i; d - $wp = new WP();- q8 N' H2 k1 p8 M
- $wp->main();
8 Y* `- }- c) b, W - //
# c/ p: V8 }' H - $my_post = array();5 C! h! [! c8 W% t; v
- $my_post['post_title'] = $title;
, _! j: M( _6 u4 d! ?; U+ y - $my_post['post_content'] = $content;
; b% H3 ]0 { x1 v" J" g6 Q' J1 L - $my_post['post_status'] = 'publish';
- E, d; k/ W! c7 X2 E - $my_post['post_author'] = 1;9 I; |+ ^2 v! ^' y0 {: q1 t
- $my_post['post_category'] = array($cate);- E0 b) v3 }" w9 r6 x6 X- T
- $my_post['tags_input'] = $tags;, }- w" k9 p% c! q5 O. o; m
- //$my_post['tags_input'] = array('tag1', 'tag2');
! B9 h4 t- e; }3 h1 p5 ^& E& C - //$my_post['post_status'] = 'future';. L, s- y' ]6 T- k# O' q0 W4 B
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
% P+ \3 B! k0 D% H1 T9 u1 b/ E( S
5 |; v3 z% i( G- // Insert the post into the database+ N- y+ f0 |/ _2 u3 M3 @& ]% U
- $ret = wp_insert_post( $my_post );
, c9 `0 s+ [" s# F9 E - echo $ret;
1 N8 e! G1 m+ L! i+ n8 j* ]. { - ?>
4 Q7 }$ u* G: s, D" q9 R
复制代码 我自己写的" \6 j. p$ G9 w' F" Q9 b, X) S
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|