|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 c/ _" f; ~" ?3 B2 s5 u. t
& q4 x7 w/ k- D" g' C; y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
* }8 {9 L, H, G2 e: x% |) T1 H7 n* X
( s+ m; g; a. ^: ^/ ]1 F# j我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
[. {, W; y: H8 ^3 k5 r
$ W, R/ F. n( U1 l8 d/ x; L方便实用 简单 何乐而不用呢
/ w6 u0 y) o! Q; _- c- <?php
! P5 G. g9 K2 s( [
8 Q- [% v6 h5 V3 J/ z- define( 'ABSPATH', dirname(__FILE__) . '/' );; ^0 L* e8 S) O, H! ]; x; h2 H4 P
- require_once( ABSPATH . 'wp-config.php' );
) ~# x. v4 L$ R, f, ^) K3 o( q - require_once( ABSPATH . 'wp-settings.php' );
/ [# M' z) T; y# F% ?( z- ?; K - require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 G6 q4 Y. @3 f s5 y d* M - require_once( ABSPATH . 'wp-includes/functions.php' );
+ D* B# w6 f. f) w* R. o - require_once( ABSPATH . 'wp-includes/plugin.php' );% ~7 o; y* O8 c2 E6 R* t
- $title = $_POST["title"];
) U+ Q% y3 R8 g6 a5 R4 z" ^, o6 N7 }' U - $content = $_POST["content"];
3 h" n8 X& | P5 N0 t3 h- K6 O% E - $tags = explode("_",$_POST["tags"]);& \$ g" B2 e$ ]" V- @3 |- }4 w
- $cate = $_POST["cate"];
, y1 z4 M% r L0 t! ~ - //print_r $tags;
- \ R6 b! g: L2 I; F- i. s3 c/ l, Y - //
* \5 b% B/ D" ] - //7 G( ]& f/ s0 K3 N
- $wp = new WP();
' w2 r# h0 d: i1 `! o - $wp->main();2 \$ F% b+ s: Q/ Q% `' ?1 t9 l6 G
- //
- G7 y% k2 i& Z& M - $my_post = array();
% K( J* D, b- m ^- }% Q - $my_post['post_title'] = $title;; g: h8 V {( M7 L1 ~/ b5 }
- $my_post['post_content'] = $content;+ F. D9 r9 d; O; {- R# w# q
- $my_post['post_status'] = 'publish';
L/ w0 j8 x" l: o0 r1 j - $my_post['post_author'] = 1;
0 b+ @' R* \" `$ u% h7 a2 M - $my_post['post_category'] = array($cate);
' X4 X! f7 [+ l, K7 G - $my_post['tags_input'] = $tags;6 H: [6 l; M2 |! x( e0 m! Z6 N
- //$my_post['tags_input'] = array('tag1', 'tag2');! l ?, z* d, K( n' D9 C* n/ n
- //$my_post['post_status'] = 'future';! M# _) C% {$ Q4 G5 H. V
- ////$my_post['post_date'] = '2010-07-04 16:20:03';) ~: _6 P* w# b; V- N
- - |+ Z" s+ I: a) n( u3 s8 N
- // Insert the post into the database
# K: Q- }$ l: n' B6 J) w% j - $ret = wp_insert_post( $my_post );& t- i$ h" V( o+ x" s3 A
- echo $ret;9 W! G( p. ~3 Z+ K, ]
- ?>
9 z& Q6 p ~. Q" x. t( U% u9 j8 [0 b
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + M& I" n' C0 m0 D
- <?php. x/ P3 ^, e' T* G0 L. k4 X5 y
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: {; d. m* ?3 d; T7 u - require_once( ABSPATH . 'wp-config.php' );4 a' T' m& R" P, f" K8 d# k: p3 k
- require_once( ABSPATH . 'wp-settings.php' );
$ U: t4 C$ e3 e9 e7 S - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ O0 Q, }- m+ Y+ W - require_once( ABSPATH . 'wp-includes/functions.php' );4 w" e- b) W/ T$ n( u
- require_once( ABSPATH . 'wp-includes/plugin.php' );
' u) i4 s4 W+ h4 b X - $pic_name = $_POST["pic_name"];
- ]! {3 D" \+ ?6 n3 I9 M% j; G; O! p - $pic = $_POST["pic"];/ s$ i( Q5 R. i7 ^
- if($pic != "" && $pic_name != "")$ D! ^- E! v% ^. t4 Z
- {
$ ~9 ~* |7 ?# V. n - $path = "images/";( M: T# L `$ Q# x4 d! F
- $pic_name = $path.$pic_name;
9 D6 D; G9 S1 ]3 T* l - echo $pic_name;
2 }3 y6 e* r! k4 m% Q$ L" k - echo "||";3 h6 D d# b J- J$ ]8 ?/ X8 i
- error_reporting(0);4 Y; i; x R$ d
- mkdir("images");) ^ Z( G% F+ L
- $handle = fopen($pic_name, 'w');
2 d$ l# o* ?0 U' T5 e3 c8 [ - echo fwrite($handle,file_get_contents($pic));
' }. H, Z9 \) x9 }; C$ u$ H+ v - }4 L1 i3 y A: E* D' ]/ j
- 3 t% j0 l c' B+ i, B3 a1 {: @
- $title = $_POST["title"];: G5 J2 @+ S" L5 ~1 Z, ^- T
- $content = $_POST["content"];# @0 V g. I$ }9 p
- $tags = explode("_",$_POST["tags"]);6 w2 g1 _8 G7 e/ J- @0 h( }, ~
- $cate = $_POST["cate"];+ W: P+ {+ N+ G* X( O; j& F; [. Q* z
- //print_r $tags;# W4 n. _) s6 B# z( p( ^8 [
- //
O1 d; [1 \6 V - //& t" `, J9 j! w+ g
- $wp = new WP();
9 p" R4 L; D: H% E. f - $wp->main();
6 ?6 f* \" x7 C9 u5 \ - //
, E! N% Q, d: u z. R5 M1 \) A - $my_post = array();6 b/ A! x: {, o6 T1 _2 I
- $my_post['post_title'] = $title;
1 h# U. b# Z" H$ {& p - $my_post['post_content'] = $content;+ u& V4 t V. X! |, u3 w0 W
- $my_post['post_status'] = 'publish';2 Z% v' K* B& c3 s" R, c
- $my_post['post_author'] = 1;) X+ a/ t/ b; _! b. L
- $my_post['post_category'] = array($cate);# Z7 E* U; x, Y# D
- $my_post['tags_input'] = $tags;
4 R ~2 L( ?9 l/ |. K" `$ @ - //$my_post['tags_input'] = array('tag1', 'tag2');; a3 ^' _& Y0 t' g+ X2 V. e" W3 g; j
- //$my_post['post_status'] = 'future';3 q6 }7 V! {/ M
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! w" H$ G. |+ T" z, ?
- ' S) d. `8 F' @# B
- // Insert the post into the database
4 ~+ r7 W5 n, ~5 n# b$ j9 A. D - $ret = wp_insert_post( $my_post );
6 v! F* K! g, q. U, f) y - echo $ret;
+ o8 p' B4 z" m4 i0 @9 i0 k( C/ k - ?>
; h4 A' o5 z, F6 S9 X
复制代码 我自己写的
% e* w( P; h/ i) h插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|