|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
0 {7 P; F E& Q6 S
* B" f" Q0 |4 w$ v3 ~/ x直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
2 I6 V8 Z, r( K" e9 i
- E6 B9 r( w. f, f' ?2 B: F7 L我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
0 m5 s" i( d) ?6 N U8 w" ~2 F. I3 e/ _: ] p6 M, E
方便实用 简单 何乐而不用呢- 1 r i, `1 y( l
- <?php) g: w! m+ h) g
* U& n/ X& X6 e+ I1 ~5 Q5 O- define( 'ABSPATH', dirname(__FILE__) . '/' );6 T) R$ r. L2 g9 x6 a% J( i: o9 J
- require_once( ABSPATH . 'wp-config.php' );
# B1 R: y# _1 [, T9 _2 p7 ] - require_once( ABSPATH . 'wp-settings.php' );
, m) l( z1 \" [* o - require_once( ABSPATH . 'wp-includes/class-wp.php' );8 \" i/ j; d) T9 h) ?- @' B
- require_once( ABSPATH . 'wp-includes/functions.php' );0 Q, N5 U n% @) X# r5 W
- require_once( ABSPATH . 'wp-includes/plugin.php' );
; ^' z' g2 [$ K( I% Z& c3 ?% Y - $title = $_POST["title"];9 i4 T# Q3 Q: ]- ?7 y
- $content = $_POST["content"];
4 A/ e; e7 I" `5 B' ~3 V - $tags = explode("_",$_POST["tags"]);6 H2 b) X2 M5 ]: p; O# p! L
- $cate = $_POST["cate"];: Q! J' R n5 X0 P
- //print_r $tags;" O9 m) m: s& o+ s( U5 Z4 ~
- //
]+ g% l% r# c& w- o% @ - //+ B$ B" Z/ V7 {5 i7 m
- $wp = new WP();
& y. Q& T0 v8 w4 z( S - $wp->main();
. y; w' V+ C9 y, G. A; ]- T. _; W' B - //
H7 a+ @" @, G( Q - $my_post = array();7 g0 p7 c, m0 A. ^0 W
- $my_post['post_title'] = $title;2 a) D5 U0 [8 k; L0 z& \) X% S
- $my_post['post_content'] = $content;
. U* x$ w l' D5 X! e Y - $my_post['post_status'] = 'publish';
$ E) x6 e% J) x5 b: U7 y# L - $my_post['post_author'] = 1;
7 G/ S0 v5 v, o) k - $my_post['post_category'] = array($cate);
1 R" W) `$ i. W7 ~6 Z! H4 U - $my_post['tags_input'] = $tags;1 }- c3 U! r9 ~, }
- //$my_post['tags_input'] = array('tag1', 'tag2');$ v" o( N# v. r, X. @* M7 B1 V8 D
- //$my_post['post_status'] = 'future';
6 v+ a* R' \, E* O* Q# d' y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
# X$ M" J+ \; w% m7 ^: M, X1 _ - 9 q; c- H8 @2 ^7 m% `
- // Insert the post into the database
! E0 G v* Y3 W5 g8 g! `! X% y - $ret = wp_insert_post( $my_post );
1 @* G' V! b" ~8 u - echo $ret;: F. |5 Q, P; l8 U5 I
- ?>4 k2 N8 ?6 W6 a1 H
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! V6 T/ \; U5 U3 M% b- <?php3 E) T& c0 U3 V* y; d& |
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ Y: [; L1 l% y. D! w" n$ S
- require_once( ABSPATH . 'wp-config.php' );& l' ]: L$ u$ u. _2 h
- require_once( ABSPATH . 'wp-settings.php' );
4 C. S( O+ T2 }/ A9 R - require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 s i& {' @! h, |7 p3 f8 R/ }' ` - require_once( ABSPATH . 'wp-includes/functions.php' );
9 r8 q% P' S6 o8 U: B - require_once( ABSPATH . 'wp-includes/plugin.php' );
$ t4 y0 r7 [! Z: @6 Y& c - $pic_name = $_POST["pic_name"];3 E# ~1 J+ p) u [( W( Z$ a
- $pic = $_POST["pic"];
! P5 [ S. P- d - if($pic != "" && $pic_name != "")
* I8 s' v- k, x N5 i N7 q' h1 O - {
) D' F; h# U# f$ k% ^2 e - $path = "images/";
( }$ F2 @/ d Z5 }( } - $pic_name = $path.$pic_name;
5 ~( j' W6 l* g' s6 e6 R# l - echo $pic_name;
7 x4 ~" x% x9 j9 x7 z7 \9 r. v, ] - echo "||";. I' ^& {; x( Y4 j4 R- A1 p+ D( l! i0 a
- error_reporting(0);; w1 |0 Q1 M g3 K& P
- mkdir("images");3 I R; L; G @! ^
- $handle = fopen($pic_name, 'w');% u- |& a3 ~: w
- echo fwrite($handle,file_get_contents($pic));
- c* c8 i, R0 \2 m$ h# |: w - }
+ }, q& F! G- i2 P% P - # _4 f# O' Z" o1 N5 w0 f
- $title = $_POST["title"];
1 m9 c( ]* E3 \% S9 m& ~5 S3 H& m - $content = $_POST["content"];# n; p) `. {3 S: X* U
- $tags = explode("_",$_POST["tags"]);
3 N. P" L+ L F& I6 O) U: C - $cate = $_POST["cate"];
( \% h9 L. |: @7 ~* Z. Z - //print_r $tags;
& k, [( v& C9 J+ T# c0 j - //4 _; p; Y# H! z' f6 z, ?
- //
9 O1 P9 T2 i6 @" K$ E( j - $wp = new WP();
: o( D. I. z+ c" r8 T! ] - $wp->main();
q8 I' F' }1 O - //+ l7 g7 C% n# n7 y1 C3 A* ?
- $my_post = array();6 ^! D: f: |6 z
- $my_post['post_title'] = $title;5 }3 `+ [8 T; U: n0 m
- $my_post['post_content'] = $content;
* f' r; K! n" x- H+ n! Z" e! x - $my_post['post_status'] = 'publish';" B1 J9 G, F ]# G2 J% J
- $my_post['post_author'] = 1;
3 y( `& w6 \1 o - $my_post['post_category'] = array($cate);
1 f6 Z9 M! U( [8 Q! L+ d- H - $my_post['tags_input'] = $tags;
7 h, ]; J% K/ C0 l- `( M" Z; e - //$my_post['tags_input'] = array('tag1', 'tag2');- O' B% L- Y: E6 @: z P
- //$my_post['post_status'] = 'future';
; a5 T! \; x- O) N - ////$my_post['post_date'] = '2010-07-04 16:20:03';% q" E, _9 l; ^' w
3 v2 g+ {, j% B- O6 ? n- // Insert the post into the database
X. X! v" Y' @1 Q" f6 {" e: h - $ret = wp_insert_post( $my_post );9 G" T2 |; u- p) a
- echo $ret;" Q3 T! K4 j6 n; k5 x
- ?>
! s" l; f, @$ q4 O
复制代码 我自己写的4 e0 Q/ W E+ k6 y* P8 S
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|