|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 B' Z: g3 }5 e$ k# q' ~' P1 @6 I
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. w7 O( X( Q, B5 A6 o7 o7 Z( f$ ?2 ~1 O: m! \5 O
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了 h8 m: j4 S# q8 `
6 Q. l! g6 S( t; k) V/ r5 d
方便实用 简单 何乐而不用呢- * e; g! ?3 |1 U i0 M( K
- <?php( P! k5 q! M+ i7 a' o% [" t7 w
- ) Z3 `1 p2 `5 e6 m& b; Y+ v
- define( 'ABSPATH', dirname(__FILE__) . '/' );( G1 p: _1 f! ^# g5 ?8 V
- require_once( ABSPATH . 'wp-config.php' );
1 b# s% J9 a2 P+ } - require_once( ABSPATH . 'wp-settings.php' );* }2 ~- s3 [% @7 O" b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 r; _' B8 N" L+ @3 W$ W - require_once( ABSPATH . 'wp-includes/functions.php' );5 }% x, F; }: t! {$ O/ G/ X
- require_once( ABSPATH . 'wp-includes/plugin.php' ); J. z1 m# v0 Z. V. i7 X! T
- $title = $_POST["title"];, q3 {7 [+ _: Q0 {
- $content = $_POST["content"];
/ @/ P. o( k1 V8 D8 R - $tags = explode("_",$_POST["tags"]);, U' w5 H. c2 R4 S- g7 z
- $cate = $_POST["cate"];% K0 F, _$ g5 X" M- X6 {3 j
- //print_r $tags;
; g3 ^6 I/ c& v0 o - //1 t4 R q! Q H% H2 n" u
- //
" @3 ` L7 ^0 r+ v - $wp = new WP();
( |" q' @' T+ c. |5 F% N P, M9 r4 p$ | - $wp->main();8 I7 c' [8 `& o( c% C+ I* _
- //
7 a8 A* o( k0 b1 }/ e - $my_post = array();+ Y9 z3 N3 a. Z3 G
- $my_post['post_title'] = $title;
* _ h) z) B* h: a4 M: t4 i2 Q - $my_post['post_content'] = $content;
' ]# q2 T: z. m: {& ^ - $my_post['post_status'] = 'publish';- I$ l6 Z4 Z: X# y0 ]5 b
- $my_post['post_author'] = 1;% Z4 j' S! v, ~. n3 M
- $my_post['post_category'] = array($cate);
: r% f5 H; `. j9 _& l - $my_post['tags_input'] = $tags;$ G4 h* e2 _- Z( D1 Z" U3 L$ t
- //$my_post['tags_input'] = array('tag1', 'tag2');" h! W' l+ F; n3 w$ @
- //$my_post['post_status'] = 'future';3 F! y# R/ ^2 ]1 }* d8 u
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* t$ R7 ]5 W0 O0 W% }
- # _9 \2 _9 i1 L" t5 l- A
- // Insert the post into the database" M: W5 h; w" S9 S# M7 M
- $ret = wp_insert_post( $my_post );8 }% r) E: D4 |; {5 h
- echo $ret;
* i! C5 g7 d" ~, p" r/ c) i6 F - ?>+ @3 ]8 j7 ], j/ e: \& ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- " Q7 W. F0 O8 h) l! b6 {
- <?php( c& N+ W9 X6 s" }
- define( 'ABSPATH', dirname(__FILE__) . '/' );3 W/ u9 V* b7 q' `, s# ]6 X
- require_once( ABSPATH . 'wp-config.php' );
+ s. q* M) \) c, s: Q4 v3 l - require_once( ABSPATH . 'wp-settings.php' );
# w4 A1 F1 o! ]! d1 P4 |: ]3 J - require_once( ABSPATH . 'wp-includes/class-wp.php' );4 G' i$ V9 Q% m3 |: a. v8 [8 E4 ?
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 p1 ^9 d$ n$ `9 [3 I - require_once( ABSPATH . 'wp-includes/plugin.php' );
, I' f: {! \: ~3 f2 b W, z6 x - $pic_name = $_POST["pic_name"];
2 H" W& h6 z4 {/ F4 k! @. U - $pic = $_POST["pic"];
: n2 u1 d. S8 p3 M& c - if($pic != "" && $pic_name != "")
/ s ?7 {, {7 S5 V7 t0 c r5 M - {
/ K; ]& V4 g* u o q% a - $path = "images/";/ r, m) U) ]& N: @# Z) j8 a
- $pic_name = $path.$pic_name;
+ s( x8 Q' O6 b$ l) s - echo $pic_name;$ i5 B3 ]* W! i% P D: |. m
- echo "||";
- q- n3 ~4 ?) v3 J0 L - error_reporting(0);
% i. H# Q9 V c9 S1 w4 H - mkdir("images");/ n' C+ Z9 k1 V8 B2 f5 w0 I
- $handle = fopen($pic_name, 'w');( V9 B# K" K9 U! E
- echo fwrite($handle,file_get_contents($pic));
" K- ?" n* p% x7 { - }
4 V- L( g% ]6 k% I - 7 ]( M. c' N& ^( o* i: s
- $title = $_POST["title"];
3 D& ~$ o7 ]) z0 F4 n' T - $content = $_POST["content"];& f D/ }+ P8 R# }- y
- $tags = explode("_",$_POST["tags"]);
, C& g$ \3 o! r( l - $cate = $_POST["cate"];
6 m% P" J. C2 {- v3 r - //print_r $tags;4 d( {, c4 Q5 S! [8 c4 p
- //4 _7 g% I! J, O: V
- //
: o4 Y! }/ K' u F/ t& f - $wp = new WP();
( q: _" T0 \& Y0 u( Q% P* L0 i - $wp->main();
& z" g' s+ K9 V8 ^; _+ W0 k8 V - //
! D B% G. C$ l6 r7 F - $my_post = array();- {+ }' `7 Y* z" }
- $my_post['post_title'] = $title;1 L, b. }* p5 _% p* L5 i; M
- $my_post['post_content'] = $content;5 E$ F" c2 q5 t4 l! Y C; `7 U
- $my_post['post_status'] = 'publish';
( M. T' `+ I, G0 F - $my_post['post_author'] = 1;
' W. G- l9 S( r) u" t2 P6 a - $my_post['post_category'] = array($cate);
W! S/ M: o$ n$ N5 h( _+ y - $my_post['tags_input'] = $tags;
6 g6 H* i' L8 u9 H* X+ h) T - //$my_post['tags_input'] = array('tag1', 'tag2');- a# f% A# c) j% x
- //$my_post['post_status'] = 'future';* L# [9 e; h8 ?4 \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';+ {2 y. a$ w2 u
- 4 g: @8 D+ ~* m4 \* h
- // Insert the post into the database# f' y+ ~3 f3 i" p+ z# t
- $ret = wp_insert_post( $my_post );1 W: o( ]+ @- T' V
- echo $ret;
* y |0 I5 j3 W; w1 {6 O - ?>. J! E# h# E! n8 X1 c3 ]
复制代码 我自己写的+ Q" `& {: f" j$ a ^+ D6 g; ^1 V
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|