|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 j" s P. n, M7 f2 ?* q# T$ T. u( u+ [( a: P" T6 m0 C
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 d* T" D+ D2 J# @0 H$ T
% e! G5 [! m1 k4 G6 o我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了& s& Q* S( d2 e" g3 z
2 g. P& J! R- U; Y' Z% j+ A方便实用 简单 何乐而不用呢- ; {; V$ r+ E; V. A# Z P% d
- <?php% `) i) P9 [; w n4 g! F
( L# O! o/ @. ^# P5 K- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ \7 `' i, _, Y" h/ Y - require_once( ABSPATH . 'wp-config.php' );
4 U/ s8 u4 f* M- V" A - require_once( ABSPATH . 'wp-settings.php' );1 j2 C% |% K: P9 K, g% A N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ p0 w4 k. | S4 e4 Q; {+ G+ y - require_once( ABSPATH . 'wp-includes/functions.php' );
4 R& H7 C9 ~6 n# l$ d( @; F6 O - require_once( ABSPATH . 'wp-includes/plugin.php' );
8 l. Y6 e$ R \9 { - $title = $_POST["title"];
5 _% n4 r; Y. e - $content = $_POST["content"];, O( R* }9 |9 f3 R2 z+ Y$ {
- $tags = explode("_",$_POST["tags"]);2 Z, d- u! F; X5 \+ r# E
- $cate = $_POST["cate"];4 p9 d$ {+ I& ]3 L
- //print_r $tags;
6 \( z/ R) b. v- _# ^9 s L - //
5 B* s1 V8 M2 l: G9 z0 H' P - //: F0 A0 V8 ]) x: A. C- x3 g" c
- $wp = new WP();
0 j q8 t+ k4 q - $wp->main();
+ K, s, y8 s2 r& ?' A; A3 g# }+ d - //+ f& ~" E( ~( x2 D: n
- $my_post = array();
0 v6 F0 e ~5 w. K - $my_post['post_title'] = $title;
. L E4 _: J9 O6 f - $my_post['post_content'] = $content;, R* }8 C% |5 ?# L/ E2 S% V; T' k
- $my_post['post_status'] = 'publish';
8 g% r$ Q- ]1 X6 F( u: P U' G: S - $my_post['post_author'] = 1;
& Y d# R {' z5 p- J f - $my_post['post_category'] = array($cate);
0 j# H3 o) B4 F. I& K D4 I - $my_post['tags_input'] = $tags;
# h F2 j8 z3 l8 ?7 h* I - //$my_post['tags_input'] = array('tag1', 'tag2');4 B4 U& s5 E k
- //$my_post['post_status'] = 'future';3 x( T( d: I9 |8 X$ t
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
* ]& @$ ?1 r6 `
. i* v1 z: U) H2 v$ @2 @% K8 ?( O! C- // Insert the post into the database* A. p+ M# n4 _9 Q
- $ret = wp_insert_post( $my_post );
: n4 S" O! X8 `, y$ m+ r# j - echo $ret;
/ S7 E+ Z; p7 ~/ p - ?>
. n4 i, w# B( P: W( {! ^
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! i/ D; s4 s, q, _) w4 s- <?php( F' B$ u, x* C% U. C( q- C
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ u) Y" S/ h! O: o - require_once( ABSPATH . 'wp-config.php' );: E4 n) d7 W1 \0 @1 w
- require_once( ABSPATH . 'wp-settings.php' );, s- U. A! Z) [) r. v+ c( w$ J
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- I1 R$ L& w0 T! K& q
- require_once( ABSPATH . 'wp-includes/functions.php' );2 D# Y; B. \9 y8 r8 Q7 G2 g& n
- require_once( ABSPATH . 'wp-includes/plugin.php' );
7 \3 G& p2 Y; J$ p# @3 e- T - $pic_name = $_POST["pic_name"];" v' g- Y+ o# Y
- $pic = $_POST["pic"];
3 P/ W7 T8 p# d! U - if($pic != "" && $pic_name != "")
! [4 H' w" p3 T - {& }9 T# G( J) p B5 c& b4 z
- $path = "images/";: K9 c/ |4 W2 y$ d9 D
- $pic_name = $path.$pic_name;; C) w% m1 B! w _7 Z, `
- echo $pic_name;1 R: g T& {# i! ~
- echo "||";
1 C* z0 \5 a. y3 j% H: d/ G - error_reporting(0);; P" Z9 k2 ^# i$ @8 q( N% w. d; t, O
- mkdir("images");
& c6 [" \6 H6 D# z* f - $handle = fopen($pic_name, 'w');$ X* e# ]8 f4 H, _, p( [6 [
- echo fwrite($handle,file_get_contents($pic)); S9 g) m) V/ z/ D; [& i2 K- }
- }* J) N. `; c6 R5 \1 n. [8 }6 P
- ( b. h' k8 o& C3 k' a% `5 v
- $title = $_POST["title"];* d2 H b1 b. ^) @+ O1 @ O
- $content = $_POST["content"];5 ]. k8 A9 e/ m5 R* \+ b) Z! y+ X/ z9 L
- $tags = explode("_",$_POST["tags"]);
2 Z& j p( O: L B - $cate = $_POST["cate"];1 I- @ U& Y- v! t5 Z" x
- //print_r $tags;
! L+ g4 V3 _3 f0 _; L+ U! p - //
. S9 K) R' D+ f: ~4 I2 @" c7 d - //
9 i) Y. K+ B# f3 @0 f8 I9 ^! @2 k, g - $wp = new WP();
4 Y- X9 A4 l1 i8 n) @ {3 h - $wp->main();8 m8 f" U0 l0 k, I: {" w4 l
- //# E1 \9 C u& J a) r8 y/ ?$ E
- $my_post = array();
( K8 t+ N6 ~: D# h) Y - $my_post['post_title'] = $title;
4 x8 E9 h5 T2 u w, u3 @ - $my_post['post_content'] = $content;( W' Z) w3 P$ y: Y+ N
- $my_post['post_status'] = 'publish';; `7 }3 Q) }; R* [
- $my_post['post_author'] = 1;
, E5 Z/ Y$ t' ~, b* r r+ Z% ] - $my_post['post_category'] = array($cate);
6 \/ `6 r3 R7 [/ Q7 W7 J - $my_post['tags_input'] = $tags;
* e: O4 H# f! v E - //$my_post['tags_input'] = array('tag1', 'tag2');
3 [9 ] p1 `7 O+ h8 h& [. B - //$my_post['post_status'] = 'future';& m/ [2 r5 e4 M
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 b! ]1 c8 ^+ H7 s2 }6 ?3 Q - + o; a9 }' @( [# ~
- // Insert the post into the database
9 Z2 ]6 I! N% v/ y; {' w% f# v - $ret = wp_insert_post( $my_post );
0 l1 [' J- r$ j& j8 n - echo $ret;6 f: f5 s$ I8 Q2 u
- ?>
8 u( _& N2 ~6 ~3 S' _7 B" }
复制代码 我自己写的
! C& E# F9 u4 t; x4 v- S% S插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|