|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 * T6 H/ v4 d* Z6 u1 r) I
0 {8 c" y! @! J( y' q' W- c直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
& \1 g# x2 a G# ?% X W+ K+ x& Y+ P7 P6 v
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ ~/ R/ i2 Z" K! W& ]( j. ^/ t$ `( c9 L6 q; Z% A! o
方便实用 简单 何乐而不用呢
1 X A( f) |# R) F1 L4 q$ }% l- <?php! j2 G" O1 A4 J/ \
! g2 A/ B4 F% l E( ]# H+ y- define( 'ABSPATH', dirname(__FILE__) . '/' );* z* N3 J9 I0 Q) I* c
- require_once( ABSPATH . 'wp-config.php' );
, ^2 m5 ? Z9 _4 o% E - require_once( ABSPATH . 'wp-settings.php' );
8 y4 i6 I2 q, \# a. E1 A9 Q0 z - require_once( ABSPATH . 'wp-includes/class-wp.php' );
1 m+ w. Y* U% t) G! j6 a5 S - require_once( ABSPATH . 'wp-includes/functions.php' );- F. B& M6 b# g1 W4 y
- require_once( ABSPATH . 'wp-includes/plugin.php' );& E4 l1 K2 ]0 G4 i) t8 ~! k# S
- $title = $_POST["title"];
E; A q8 {$ U - $content = $_POST["content"];
, }, W( F. ?8 T9 h3 y$ v# F) ^ - $tags = explode("_",$_POST["tags"]);
7 s; ~) C1 w" q9 z" d - $cate = $_POST["cate"];( G: m0 g! E3 s$ O1 z
- //print_r $tags;
' q1 g7 L) m0 o - //3 ^5 D3 j7 C' T& W# ]
- //1 c- n* A) S: o. ?3 t
- $wp = new WP();
% i8 r. S7 P( ?) S: I3 a& a - $wp->main();8 J$ |$ T( `7 E& R
- //
% h, N6 ]. ^, a! G - $my_post = array();
3 ] X9 ?# L h# o8 W1 }# j - $my_post['post_title'] = $title;% e( ]* U/ m( Z. m3 c) U
- $my_post['post_content'] = $content;( G; X @, G5 I+ v* Q9 t
- $my_post['post_status'] = 'publish';! S9 _4 r; ]/ R1 R7 f$ K
- $my_post['post_author'] = 1;
5 R( X) d# x4 ?4 C( m, m& G& {" {) R - $my_post['post_category'] = array($cate);- z1 e2 e" }* Z
- $my_post['tags_input'] = $tags;
9 w) \( A' [9 z - //$my_post['tags_input'] = array('tag1', 'tag2');1 r# `6 h. T. R
- //$my_post['post_status'] = 'future';$ `# O# S" U' D1 `% Q- g* F
- ////$my_post['post_date'] = '2010-07-04 16:20:03';2 W5 L! q9 X$ I
- 3 X) x9 {/ A1 m. J( s
- // Insert the post into the database& E4 L( c; N4 Q7 m8 c! \ B( \
- $ret = wp_insert_post( $my_post );) |% D, V9 }+ O# q* P5 X
- echo $ret;3 B2 D R3 p, b. E
- ?>
$ ^" Q$ f" J1 ~6 K
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
% R7 ^; t. y( [0 f( y, f- <?php6 q% b% _& U( \! {2 n6 D# E
- define( 'ABSPATH', dirname(__FILE__) . '/' );
! b/ I- B: i* d5 a* ^" ]: P - require_once( ABSPATH . 'wp-config.php' );! @ E9 G0 w2 g7 i9 p; ]$ z6 q
- require_once( ABSPATH . 'wp-settings.php' );9 S6 o/ n6 n3 l/ f. D; q$ @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
# j8 G4 x0 F* Z' r3 p - require_once( ABSPATH . 'wp-includes/functions.php' );/ d7 X/ ~; }6 X( V5 W
- require_once( ABSPATH . 'wp-includes/plugin.php' );- a+ l. d7 j$ A
- $pic_name = $_POST["pic_name"];
0 A( L. t& ?- d& g+ N# f - $pic = $_POST["pic"];
. Y4 ^% Q* h" C0 X$ l - if($pic != "" && $pic_name != "")# K5 i8 ]8 E0 y. _ y2 [) G
- {& }0 q/ [. Q. G4 J& Q
- $path = "images/";7 a: ~9 R9 N* _, ^6 s3 L
- $pic_name = $path.$pic_name;6 D0 c& J# x3 ^& f+ @
- echo $pic_name;2 R9 p/ s' k: ]. ]% \
- echo "||";' p/ l& E9 j# e. p/ ?# k" F
- error_reporting(0);7 z0 H7 h- F- Y9 ~ R
- mkdir("images");
$ { j5 E6 q- H5 V F. y - $handle = fopen($pic_name, 'w');) S5 @; k6 p; x7 u/ ]1 Q2 o
- echo fwrite($handle,file_get_contents($pic));& Q/ X8 ~) M4 w8 n& X; o7 \# i- U
- }
Q- H1 F0 G' h& m' w - 7 W' q6 }: I# j- j3 |' m6 l
- $title = $_POST["title"];+ s% p) b6 M6 c1 H7 \( U, N4 {8 U9 |
- $content = $_POST["content"]; | a: F5 T4 j
- $tags = explode("_",$_POST["tags"]);
. ~: Z5 G: _4 t - $cate = $_POST["cate"];2 P* k5 F0 u$ X! I: s+ I- ?6 n
- //print_r $tags;
$ q3 ?% V! S$ ?$ ?$ g - //
% o3 V' v- \/ f5 H# J3 _ - //( N: o9 {+ n" d) J7 ?+ s
- $wp = new WP();, O1 o4 ^. X5 A& C, u, x: V" d
- $wp->main();$ _6 z* n" N' w& _6 Y- ^
- //
. M; l# `( g7 z& Q - $my_post = array();
* Q3 x: w& t ~$ O8 X$ c - $my_post['post_title'] = $title;7 c' g" L: A' F+ l
- $my_post['post_content'] = $content;
( ~8 ~: ~' u) C6 a - $my_post['post_status'] = 'publish';, _$ g' u0 R+ @; I% D9 f: n; @
- $my_post['post_author'] = 1;; J$ H' n$ @, G# l2 Z, S: |
- $my_post['post_category'] = array($cate);
2 u0 }$ [4 ]- X - $my_post['tags_input'] = $tags;" R$ U: _* F+ S- F2 \5 Q
- //$my_post['tags_input'] = array('tag1', 'tag2');7 h" f4 S( z# Q& u, Y5 `+ [ n
- //$my_post['post_status'] = 'future';5 \( O# t4 E( k d4 k5 ~
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 p- K$ H4 n% W! Z! m - & m$ g8 }6 F2 v3 X* f8 P% e- j, ^* H
- // Insert the post into the database
# {1 I7 M8 r# F& b7 X: Z) Y - $ret = wp_insert_post( $my_post );, z1 }( m% H" `9 N( y# K" ?4 s- U0 s
- echo $ret;
% T+ L- p* ` F9 k4 S% U! r3 ?# s - ?>
8 Q# L- J+ M; {+ R
复制代码 我自己写的
6 b! V# J2 B0 P- b插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|