|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 ^9 Y, T0 M4 x% z
4 P9 x' x+ d# N& _2 ~直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
! ? A, Y3 G; s3 Y5 s$ W/ Q+ R& }* ^- p0 f U
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了$ r* g5 z T) e' M. I% t$ }5 q
. j. I3 K; o* @3 {- C4 \方便实用 简单 何乐而不用呢- * D: H: c/ x: h; K3 J) P$ z: S
- <?php
: D: I/ f/ b9 v; g. L
4 b/ x8 i- @" B" g1 I- u* n7 }5 _- define( 'ABSPATH', dirname(__FILE__) . '/' );
: ^) B7 w: Q( m z8 @ - require_once( ABSPATH . 'wp-config.php' );7 |) [# u" L8 \# j# [
- require_once( ABSPATH . 'wp-settings.php' );) v: M- V+ r4 a& z: K8 ~
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
: B+ W! r6 L0 d& W. d O - require_once( ABSPATH . 'wp-includes/functions.php' );2 ^ E$ Y8 R2 Z8 G/ S* t
- require_once( ABSPATH . 'wp-includes/plugin.php' );
3 h$ A0 r2 x9 G! T) t - $title = $_POST["title"];
8 Z$ t W& Y ~2 t3 J1 I - $content = $_POST["content"];
( Y3 [5 J) p9 U& x$ ^' { - $tags = explode("_",$_POST["tags"]);6 r6 k0 Z, U+ y( e
- $cate = $_POST["cate"];
3 S$ `7 I/ P2 [. B+ }% @ - //print_r $tags;
; N( i$ {, g/ R3 e/ L! n - //) j# w( f# J$ L) V. @2 |7 V
- //: }4 m* ?5 `3 p* S5 [" T* A
- $wp = new WP();2 k$ m6 H8 P. R& W9 z6 |/ @
- $wp->main();
; h# G! B# d0 f" v: X - //) e2 G3 B, Q) Q- w' Y* ]
- $my_post = array();
$ v \% A. Q0 s6 P - $my_post['post_title'] = $title;
c( \4 o% `) E8 E( [ - $my_post['post_content'] = $content;
, C! u/ A$ Q6 X G) V" X2 P' i/ t - $my_post['post_status'] = 'publish';; j! ]) j" c+ X' W1 {8 w
- $my_post['post_author'] = 1;
4 x, L6 O/ a# X0 I4 i - $my_post['post_category'] = array($cate);
5 ?5 u& j: E1 r- F; o - $my_post['tags_input'] = $tags;3 }6 x* {3 k4 Q1 N3 E: q+ G2 `
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 O. U+ H( V' H5 N+ Q - //$my_post['post_status'] = 'future';
# e0 v2 N; y* e# ]" g3 w - ////$my_post['post_date'] = '2010-07-04 16:20:03';
o! G+ m/ e/ j. n - 4 U5 M1 \0 Y6 D K
- // Insert the post into the database
3 ?# Q# G1 L# U4 e, S( B4 q - $ret = wp_insert_post( $my_post );
- T Z" X( n0 ?" e' N - echo $ret;5 ~8 \, E. ?, S; X
- ?># l: q- a8 f. o- D
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 Y2 l. x2 [+ \+ }- <?php
/ C5 P7 h1 \" V5 Q7 |# ~4 |8 _) _ - define( 'ABSPATH', dirname(__FILE__) . '/' );
, g7 T* y8 {* @* f& w - require_once( ABSPATH . 'wp-config.php' );1 U* @8 ]4 |, L$ l
- require_once( ABSPATH . 'wp-settings.php' );
k1 w" S6 e0 x! L/ P - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ u1 H) [* y# X6 m4 h% c# y( P+ t - require_once( ABSPATH . 'wp-includes/functions.php' );
3 |% o- E( T3 j; L$ q" Y - require_once( ABSPATH . 'wp-includes/plugin.php' );0 _4 O5 l4 ?- j0 x: A
- $pic_name = $_POST["pic_name"];
- U5 T3 O w4 W& ]' N0 W - $pic = $_POST["pic"];
, y- @0 L0 p' r5 V) C - if($pic != "" && $pic_name != "")0 L# G# t; o! G) ~8 }3 a% P/ D
- {
+ @/ j7 P$ z5 v O U- ~. O - $path = "images/";
4 y4 C1 v/ S( K; _/ z9 r - $pic_name = $path.$pic_name;% I3 w+ X7 e! ]: o- N" R
- echo $pic_name;
: {9 P: G2 S1 X - echo "||";6 [' ~5 o1 G6 D3 C( U! ]
- error_reporting(0);7 V1 ^$ k0 e" a% T) g; a
- mkdir("images");( `# X6 b/ V: L9 w8 ]- o2 u
- $handle = fopen($pic_name, 'w');
8 M: {8 k T# |3 ~- n - echo fwrite($handle,file_get_contents($pic));/ a- I! O+ s9 m8 l; E
- }
' D) |- ~3 J2 ^7 V; l. c( Q6 g - ' C$ p0 L4 _6 G1 C8 ^5 k) Y# q* n
- $title = $_POST["title"];) ?7 `& ~* T! {4 P( I) ^
- $content = $_POST["content"];
R9 W- A" q8 y* p* F2 b0 a( y - $tags = explode("_",$_POST["tags"]);1 F7 U8 Q* H9 D0 o' M: \- G
- $cate = $_POST["cate"];! q; ^6 n; T2 w- }) F
- //print_r $tags;
* R7 X3 i/ y2 B2 E - //
0 w; O) f: B: | - //8 {' n3 I) M3 ~. |; z# ]
- $wp = new WP();
% B6 k# `& l4 o5 G* O! |9 x4 x - $wp->main();- X0 M; Z3 v8 W
- //. _3 h& S; d4 G2 b1 K
- $my_post = array();# T: n8 d' l! e/ Q; U
- $my_post['post_title'] = $title;' m1 k0 G" r" [ m
- $my_post['post_content'] = $content;
2 \0 k7 @- k7 K/ p% X: ^ - $my_post['post_status'] = 'publish';
0 `) t. q8 f6 J - $my_post['post_author'] = 1;% O g2 e! Y) P) T$ N% S
- $my_post['post_category'] = array($cate);3 a5 k, z. P$ u/ D
- $my_post['tags_input'] = $tags;; {7 a% K% J6 i
- //$my_post['tags_input'] = array('tag1', 'tag2');
# _! m" k' j7 \& @! k - //$my_post['post_status'] = 'future';6 _& g5 J+ p# k+ }7 D
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ t, M: N2 J, z) D
: d6 [0 M5 o. H- // Insert the post into the database
) O1 B" g* N( e0 P9 K5 d - $ret = wp_insert_post( $my_post );
/ h1 l, {# ~/ T$ [# Z - echo $ret;# _; ?) w- b+ L3 `* c; h1 M4 p7 B5 Z
- ?>
$ q! H. i6 E& l- b
复制代码 我自己写的7 G- h3 ] w* ~
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|