|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! ^" p' l4 E9 I; X. F0 B/ W# {
: \+ l* ]; d0 p3 ^- N9 h1 J, M直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持" e$ Y/ q1 `; }
3 t# n( U5 h( [7 m' L
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
% k4 t# i* X; n1 s/ M( L
1 B. a0 ~% M( Q9 r/ u方便实用 简单 何乐而不用呢
" P3 i7 ^2 `4 Q. u! F2 l- <?php
- q; J; Z- C; u9 H- ] - 5 m: E3 R9 j% ^
- define( 'ABSPATH', dirname(__FILE__) . '/' );) x, n4 o/ @9 {! }
- require_once( ABSPATH . 'wp-config.php' );
) z4 k b$ c0 K `9 G! T4 \1 a - require_once( ABSPATH . 'wp-settings.php' );
/ @% A4 E* g- U: ?0 r- q1 ] - require_once( ABSPATH . 'wp-includes/class-wp.php' );
) C6 G( S! f- n% f, _' ? - require_once( ABSPATH . 'wp-includes/functions.php' );
. ]3 U9 L7 J5 {+ [8 j# R& L$ t - require_once( ABSPATH . 'wp-includes/plugin.php' );
% G8 g; v; S- G% W, a - $title = $_POST["title"];
& X* F/ l1 ]9 T/ N: z( P - $content = $_POST["content"];
/ a, s$ a0 n" N7 U3 E4 M - $tags = explode("_",$_POST["tags"]);
! U F7 [% E& O+ V- V3 E, T3 d - $cate = $_POST["cate"];9 T, x, X+ W+ z; x9 d
- //print_r $tags;1 w& @. e; @ L# r. o" Z
- //
. h; D7 d; Q. f - //
# \0 F) e! F! i) E0 @ - $wp = new WP();
0 `) _$ g, l6 [4 ^. A F - $wp->main();
% H1 M) b$ M9 _" L) E - //
' \& b3 [$ m9 h/ ~# T" Q0 k0 e - $my_post = array();
! ]4 U) @+ {: A8 y! R- G9 P - $my_post['post_title'] = $title;' ]3 v, a9 E& m$ x
- $my_post['post_content'] = $content;1 _3 Z- u# {5 {3 ~9 R+ q
- $my_post['post_status'] = 'publish';2 R7 E( x0 R3 T3 m5 Y
- $my_post['post_author'] = 1;
- L. ?0 f; l$ u - $my_post['post_category'] = array($cate);* P5 _2 S' T1 D' f- n6 t
- $my_post['tags_input'] = $tags;% n( f, B3 t' V# I# \' B" G
- //$my_post['tags_input'] = array('tag1', 'tag2');
: E' C0 d/ A8 G: O, ^ - //$my_post['post_status'] = 'future';
/ t! h, ^3 Q1 Q( ?6 u - ////$my_post['post_date'] = '2010-07-04 16:20:03';6 G9 T& S2 E3 X
- 0 P ^9 B: e, i- c4 G) H0 y
- // Insert the post into the database9 l J. B' `4 l
- $ret = wp_insert_post( $my_post );& ~7 Q! l' S% X2 }
- echo $ret;' p R* f, m7 f4 t4 a# I
- ?>
$ R6 ~1 M& Y7 H; B% z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
$ Z6 m* |- V) @7 B- <?php
7 c# ?6 D5 o( N/ p* g J - define( 'ABSPATH', dirname(__FILE__) . '/' );, C E! s4 [/ v$ Y& n( ~7 u. F
- require_once( ABSPATH . 'wp-config.php' );
$ K+ L, I5 N9 p; M - require_once( ABSPATH . 'wp-settings.php' );. l+ ^8 j4 _9 b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
- G `" s0 ], O ] - require_once( ABSPATH . 'wp-includes/functions.php' );6 l$ s0 G! }: G3 @* I+ ^$ J( {
- require_once( ABSPATH . 'wp-includes/plugin.php' );5 ^6 `, y. y! U8 C& L1 E, Y
- $pic_name = $_POST["pic_name"];
" N1 O1 C9 z( r/ [- o4 u% H - $pic = $_POST["pic"];
, K2 d# ?! k5 _* H - if($pic != "" && $pic_name != "")5 s, a# ~, Z3 s7 q
- {; s0 F) E" C! T6 A% o( Y; T# v5 b
- $path = "images/";
, c7 I9 x" _! V4 Q - $pic_name = $path.$pic_name;
: r ^3 R9 {" l3 O: P+ {4 C - echo $pic_name;8 t! v6 U1 m3 V
- echo "||";
5 v4 [3 w& A0 _4 h: [1 t' t2 g# @ - error_reporting(0);
f# e( G1 `. f' q - mkdir("images");- [9 N2 Z. _5 p* o z7 v
- $handle = fopen($pic_name, 'w');
+ `, D4 b- Q, V7 U: O; @ - echo fwrite($handle,file_get_contents($pic));# N; }1 _! Y' n {0 z
- }
; F0 f- u5 f" v1 {5 m& N7 q
7 O* R; l6 U& E$ k- $title = $_POST["title"];
9 ^6 ^& N6 f* O; m' z - $content = $_POST["content"];7 ?5 { ?- g; B! C( d( C! q
- $tags = explode("_",$_POST["tags"]);5 a0 A% D+ g* B# M: Q8 e
- $cate = $_POST["cate"];
5 F+ N1 Q9 N; a/ p - //print_r $tags;
$ ?# h8 W2 }7 E; u - //4 T* Q! c1 p# h2 [* o
- //5 b0 E! {6 k$ ?$ I
- $wp = new WP();
3 `( S' V) s9 [1 O; n* ] - $wp->main();
7 D" g- ^8 n" u: R1 c b - //7 a# f6 S. M5 A8 w
- $my_post = array();- O- Z2 Z# r( g8 {
- $my_post['post_title'] = $title;
5 K* x# O( J, B - $my_post['post_content'] = $content;' h$ w' Y) W7 h* D/ J$ v
- $my_post['post_status'] = 'publish';$ S y, Y5 d( w( A8 C& }' K
- $my_post['post_author'] = 1;$ c8 r" ]' I( N1 G. ~
- $my_post['post_category'] = array($cate);
' y: b7 g4 r/ n) @ - $my_post['tags_input'] = $tags;
$ G, _ D$ V5 u: P/ E( o - //$my_post['tags_input'] = array('tag1', 'tag2');2 ?8 M, u- C, L5 ]3 d& L
- //$my_post['post_status'] = 'future';
" Y( c( D7 q0 x% F - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 O2 A9 k+ Y9 d' b9 P1 V2 N - ! U* A+ ?$ w, I% N- C ^4 f- I
- // Insert the post into the database/ q: W0 C7 U! V1 M! T: ?
- $ret = wp_insert_post( $my_post );' n/ n, t( w5 z& ~& y
- echo $ret;' X8 S# U: `" Y' a- Q6 f6 [
- ?>
, o8 B' j7 s# x5 \4 l( F7 u: b
复制代码 我自己写的
# P2 l: ~% w+ [* |- B# D+ s0 Q插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|