|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
5 }0 r5 u3 ]) U3 R" y/ Y
) l/ E8 K/ {5 j* R& X直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持6 F4 _2 l+ S `. {( V: u
' g u- g3 p3 T我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 U9 H6 i- F8 c4 U" }2 z: s9 h3 h8 u% d2 Y& r+ X4 h [
方便实用 简单 何乐而不用呢- H& H' u# i% Y E5 ?$ f6 q7 L; _
- <?php
! ]% J( @3 [$ `9 _0 W, M - $ H3 Y) n! j- e4 ?% P9 W5 E' }
- define( 'ABSPATH', dirname(__FILE__) . '/' );
; u3 z2 R' R" h2 _6 J, o - require_once( ABSPATH . 'wp-config.php' );
5 g5 ^# M: n# C4 e9 W - require_once( ABSPATH . 'wp-settings.php' );* V1 D) D+ f7 d% R, n" I: U
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( D7 n' h3 m7 f8 B) d - require_once( ABSPATH . 'wp-includes/functions.php' );
( p, X0 z. L, Q0 x( S+ ~: J6 R - require_once( ABSPATH . 'wp-includes/plugin.php' );3 P5 u. _1 T7 l* A9 ?2 ?
- $title = $_POST["title"];
! r3 Z8 O# L! B$ {5 f2 [9 Y4 W - $content = $_POST["content"];+ Z# z) Z2 z. e; S
- $tags = explode("_",$_POST["tags"]);* E3 {5 s5 o. Q- r. |7 r$ p% [
- $cate = $_POST["cate"];* T0 Q9 N, w0 Q9 L9 A6 T2 y4 ]+ K& a
- //print_r $tags;" w7 F6 `, ]& T$ b
- //" c3 t0 n8 _$ S8 d4 B
- //9 R1 T% h) P4 S. b& e
- $wp = new WP();
$ e: C/ h$ |, C( Z# m$ f - $wp->main();
- j6 S: G- Z' ^. w# x T - //+ Y) n* E% c1 T! [, O6 n+ F' p
- $my_post = array();) L" [$ u4 @$ ~& n; @+ _
- $my_post['post_title'] = $title;
/ {0 M! D) K7 I2 V' Z: l$ t. F - $my_post['post_content'] = $content;$ z" V. K! X8 `3 g6 K0 F
- $my_post['post_status'] = 'publish';! ]: A! c6 B1 X+ ^# l
- $my_post['post_author'] = 1;! e5 ~# f# O8 o/ C# h$ L
- $my_post['post_category'] = array($cate);
# w# a; ]4 w3 @9 |4 ~5 @% n - $my_post['tags_input'] = $tags;
+ t0 k" S3 t0 N' h8 T - //$my_post['tags_input'] = array('tag1', 'tag2');
! K0 d" f2 W) T' a' [5 n3 {, D - //$my_post['post_status'] = 'future';
9 Y+ F9 n9 N: B: X* q" v - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 n# f: l: u% ?& e/ N( Z( ?) H1 J
; k w& k3 h9 Z- // Insert the post into the database
8 H$ I4 w1 R1 B. w$ s' J - $ret = wp_insert_post( $my_post );8 j& A" ^$ y# j7 ]. A; A4 W
- echo $ret;
# W \3 M$ g: C4 j u - ?>
. W& v, F: f: G" u3 ~9 N6 _) u# u) C
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 L% t2 ]- [7 N: z* D4 K1 o- <?php* s8 Y8 j$ {% j& f
- define( 'ABSPATH', dirname(__FILE__) . '/' );/ r) m ?0 U/ T; ^
- require_once( ABSPATH . 'wp-config.php' );
3 W0 v: G$ b9 }6 M: s2 @) J# M - require_once( ABSPATH . 'wp-settings.php' );
% l" G x" l$ \- @ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
! J6 W7 G& [- |2 G0 O* D) O - require_once( ABSPATH . 'wp-includes/functions.php' );
. D7 O1 B4 R6 A7 p7 H) @7 D% a. n - require_once( ABSPATH . 'wp-includes/plugin.php' );
( O( W& q$ P9 s3 b& G3 u6 ] - $pic_name = $_POST["pic_name"];
, U4 F6 y* L4 [" { - $pic = $_POST["pic"];' g+ ~7 v6 m) W3 z# m: m' O
- if($pic != "" && $pic_name != "")
2 V+ \( e) I0 A( E! q1 J9 T. m - {' I# t6 O6 i, k" ]5 r6 G
- $path = "images/";. d! i2 q! R7 K
- $pic_name = $path.$pic_name;& v/ Y4 p( A" P; G
- echo $pic_name;
9 Z" R, \& M; V% O - echo "||";
0 U( x3 A* j) ]+ ~3 \2 n6 k. F* \ - error_reporting(0);( _1 R) z( m7 w+ M' i+ _
- mkdir("images");0 O) c4 n# d2 `' ^6 t1 x7 I
- $handle = fopen($pic_name, 'w');
2 z! u! |: P& ]8 t6 W - echo fwrite($handle,file_get_contents($pic));
: t8 c( J4 w. z. J5 k7 O - }
$ ^+ \7 J( N: x/ _' y - ' Z1 j1 |7 Q& l* g
- $title = $_POST["title"];
8 e$ D3 h5 j7 A! X/ F( y6 L& H - $content = $_POST["content"];' k- M v6 v/ F
- $tags = explode("_",$_POST["tags"]);
+ l. A& r, \) P0 l u2 ^( h - $cate = $_POST["cate"];
& b0 ~$ W: S) v% h" `9 S2 S - //print_r $tags;) Y" o. z% S4 q( o
- //
( B! J- Z# d# _- [: E - //' x P' T* t c
- $wp = new WP();
F8 \6 s* @- |* L* R' O, I) m6 J- z - $wp->main();
+ C) \7 C! i2 C! r7 _2 c3 | - //" ~ W; s. X" [' v
- $my_post = array();) M0 _8 s9 ~+ P
- $my_post['post_title'] = $title;
% G$ K% G3 f* I5 r - $my_post['post_content'] = $content;
4 f2 ^* S2 p6 Z) [3 a/ j3 x - $my_post['post_status'] = 'publish';4 f0 M- a+ N+ W" A* U: q
- $my_post['post_author'] = 1;
4 |6 V& b4 h( Q( r - $my_post['post_category'] = array($cate);
- T" F" `8 L: d- _) _% m+ w" R! D - $my_post['tags_input'] = $tags;# s* j. k' B- T, ^4 M- o
- //$my_post['tags_input'] = array('tag1', 'tag2');" h; `* x) U8 q
- //$my_post['post_status'] = 'future';3 u8 C. `1 U" ]
- ////$my_post['post_date'] = '2010-07-04 16:20:03';8 O5 f( Y; p* [
3 I. j; u. m4 W1 g! h3 O' I' N) n- // Insert the post into the database A( K. }: C5 h. ^+ p/ L. i$ ~
- $ret = wp_insert_post( $my_post );
( B* _# p4 V* o( I$ ~# c - echo $ret;
7 h1 G/ y) o# T! I5 P. o - ?>
4 \! R6 ?8 d8 q: J6 X, P
复制代码 我自己写的/ x1 \9 Q& c& h8 K, x# t( w3 r L
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|