|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ( x! s0 G! A5 S
! C6 Y+ a$ x3 d直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- a9 X2 a' m8 S+ g+ n e. H" u# B" x# K. l1 y: G
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 q1 M& u Z) Q2 h. o
& f/ n2 I- \" L4 M
方便实用 简单 何乐而不用呢
! @/ f- ^# {( N4 o4 v2 s7 x- <?php% u }' s5 T$ r6 a
1 z# u1 O( C7 `5 Q; S- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 o0 ]9 I7 @' U1 w) _ - require_once( ABSPATH . 'wp-config.php' );$ E1 a# I- F- j) ^# n" S
- require_once( ABSPATH . 'wp-settings.php' );: b8 F" v: l8 E' E! ^5 W4 M
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 b& Q5 I' K1 d, G
- require_once( ABSPATH . 'wp-includes/functions.php' );
- V. C/ n* V# r8 C1 z3 b6 X - require_once( ABSPATH . 'wp-includes/plugin.php' );
9 M$ }6 E, e3 ^/ ]3 M5 V2 f5 ?5 p - $title = $_POST["title"];# g) ~, k+ ]: {6 |* ^3 h
- $content = $_POST["content"];7 Y* O. B. g3 m" C
- $tags = explode("_",$_POST["tags"]);. V4 m) T( Q. ^# x) x" A- L
- $cate = $_POST["cate"];) p9 r: @/ _% w- B1 @6 I
- //print_r $tags;
$ y0 g7 B" N8 W5 V P$ {: h$ g- b - //2 F$ O* m& ~* y0 s! I
- //
1 ] U0 h3 \6 P4 ?* ^$ t - $wp = new WP();
3 k) z+ t9 `, Z& j0 Z( g - $wp->main();( X4 U# ~0 j2 V% P
- //7 P: S( \- ^2 a* ?% d
- $my_post = array();. n g3 H8 ]' N3 e5 i
- $my_post['post_title'] = $title;
/ N" e/ g7 y2 L2 G7 u: G - $my_post['post_content'] = $content;
& w5 s1 i! R1 w9 B0 V/ I8 Y; u% |1 F - $my_post['post_status'] = 'publish';
, W; t! N8 D, s0 g- X- I - $my_post['post_author'] = 1;9 y0 ~5 g5 x# e
- $my_post['post_category'] = array($cate);* B( ^. A' ^8 E8 q$ S
- $my_post['tags_input'] = $tags;
! ^: Z5 B8 L, R+ m - //$my_post['tags_input'] = array('tag1', 'tag2');
* A( s, V) I3 j. F- f: O9 C+ k5 z - //$my_post['post_status'] = 'future';
y4 ]& x! c4 q- w7 h5 a$ i - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 c* O: ~$ X1 B. }2 {% c
; q2 F% J/ _$ W Q I4 ~! v- // Insert the post into the database
; {4 M4 T- p: }5 n) [$ ~$ h2 R8 i. c3 H - $ret = wp_insert_post( $my_post );
5 w1 b4 v5 ^, V1 }$ Z - echo $ret;2 Y3 @1 p! k' `" E% n/ q% v
- ?>
8 h9 J- M" F0 D+ D! G
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ' m4 `5 h K% `5 M8 Y
- <?php/ S0 E" L8 `2 Y. c5 Y
- define( 'ABSPATH', dirname(__FILE__) . '/' );
! Y1 ^# e$ C; N) t+ ?3 h' a7 ?- e - require_once( ABSPATH . 'wp-config.php' );
7 r% e/ n% B$ ^ - require_once( ABSPATH . 'wp-settings.php' );, Z k3 s/ a) Y4 w7 V6 F7 n
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" e. x% P+ k r* J7 f- A/ U1 f* D
- require_once( ABSPATH . 'wp-includes/functions.php' );
8 F/ l; w e, y3 o4 u - require_once( ABSPATH . 'wp-includes/plugin.php' );
: K( Q% Z% @% j, D" \2 ^$ T - $pic_name = $_POST["pic_name"];
* }% H- g: I9 u5 F. r - $pic = $_POST["pic"]; r9 b$ @$ ]2 y/ e. \6 X9 ?
- if($pic != "" && $pic_name != "")# A- ]* @4 q |) v1 L2 v
- {- k7 t& K B$ O+ ?
- $path = "images/";
! m& l2 S; P; a" @8 a2 V - $pic_name = $path.$pic_name;3 }4 J9 |/ K& P3 E) U8 O, g2 R) @
- echo $pic_name;
+ p$ f- N+ v* B) @# ^. \ - echo "||";
" x- }5 g% b/ n4 z- M- i - error_reporting(0);
( |; S/ H+ [* g) f7 G/ C - mkdir("images");
3 f, c0 U7 G3 B - $handle = fopen($pic_name, 'w'); L0 a9 D9 M& k9 [) }6 c& Z
- echo fwrite($handle,file_get_contents($pic));
8 ~! I# c: T) H# r, m0 [2 J - }2 H/ U [# Z+ O! r
8 h! M7 E# R- V- q7 |) l- $title = $_POST["title"];
G* e& | {! i3 y: z* n - $content = $_POST["content"];
' t3 K6 Y0 U, a3 a9 d& V - $tags = explode("_",$_POST["tags"]);& \4 E$ c# x! N+ b3 |) m4 @1 ^
- $cate = $_POST["cate"];
5 @/ B: X/ R) K4 d6 J - //print_r $tags;
. I6 J7 b0 W8 Z/ C" w5 _" t - //
! e6 S; I ]5 B( J0 S - //
- b8 o1 @+ e6 P5 S8 Y2 c& k+ z8 g+ t - $wp = new WP();
- _5 O8 f; O8 C3 ]# g! y! ? - $wp->main();
, l0 O$ W+ ?0 k5 l( D! V - //# w1 h, C% E& @2 j3 M
- $my_post = array();& w( y C9 t1 L, T& J7 J
- $my_post['post_title'] = $title;! B' F+ D( f$ c
- $my_post['post_content'] = $content;
1 z4 G8 q, @5 V( ^ - $my_post['post_status'] = 'publish';
3 H, k, j( [% a8 v - $my_post['post_author'] = 1;
; Z& M3 y, |* G% G) s - $my_post['post_category'] = array($cate);
% o2 }9 p" G: E* p- j5 h - $my_post['tags_input'] = $tags;
$ \ j' e) E5 p1 a; U: E. M - //$my_post['tags_input'] = array('tag1', 'tag2');
( ^% ~1 V6 M# `: W- M - //$my_post['post_status'] = 'future';
7 b% Q2 R! [, v" g: a0 | - ////$my_post['post_date'] = '2010-07-04 16:20:03';
" I- H8 g2 c' q
! J' z; E; X9 C( T- // Insert the post into the database
2 b2 B3 G; C3 r; q6 a' p - $ret = wp_insert_post( $my_post );
7 w- Y' Q4 l2 R2 D6 b% x. k - echo $ret;
) t% S. s8 c* w; D, J, ?* f - ?>
' s! z. T8 B- x3 e
复制代码 我自己写的1 }" B& L2 z1 d E0 \4 c* U
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|