|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. |* d( g6 X% [; O; c' O- {; I. X# r) _: T n& Q, Y; B+ M
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持/ a+ D) J/ x7 V F
! K4 o: X( c# K* f5 d# @
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了8 z, g* q$ J# A( u
% C4 R. w% W9 _
方便实用 简单 何乐而不用呢
9 ]) |. W/ `+ p7 x9 O0 }/ ?- <?php
5 u8 ]1 |8 x) F+ a1 [; d
% N4 l6 Z; X7 A' B) ?2 |- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 I4 s5 J% ?( a( d. r8 c8 O3 ^ - require_once( ABSPATH . 'wp-config.php' );
; I& j; G K+ B - require_once( ABSPATH . 'wp-settings.php' );
/ k9 q+ }1 [/ V. b5 U) O4 d# t - require_once( ABSPATH . 'wp-includes/class-wp.php' );
f% S a5 A" s5 J) l( n - require_once( ABSPATH . 'wp-includes/functions.php' );
0 s' k, R- J5 a6 j - require_once( ABSPATH . 'wp-includes/plugin.php' );( I* k+ ^2 V R3 u" V+ T8 |
- $title = $_POST["title"];
! u% Y* W4 ~- b+ v: ]+ U - $content = $_POST["content"];1 [1 ~2 x0 X, U2 r; H( f' J
- $tags = explode("_",$_POST["tags"]);$ H- E9 W+ T, u+ v4 y; E3 }1 t# K; r) h
- $cate = $_POST["cate"];1 O, E) v1 O J2 Q! Q( d1 A
- //print_r $tags;2 J- X+ ~3 L6 B: T! k
- //
' Z0 ]* P% I; {3 t* a - //
5 Y2 a5 Y- B9 Z4 H - $wp = new WP();. r: ?# Q2 k0 g- ^# w2 M( h
- $wp->main();5 n$ W3 c0 ~% B
- /// g3 V* s# W/ Z W$ B
- $my_post = array();
6 ?- ^& d; A, I; H - $my_post['post_title'] = $title;6 y m2 o% J3 W0 A* E* p
- $my_post['post_content'] = $content;. w, ~) L) k; |5 k# f! z- D6 L
- $my_post['post_status'] = 'publish';
# I! M B m% y, } - $my_post['post_author'] = 1;
: s$ t0 y1 U. N- D5 A - $my_post['post_category'] = array($cate);& f* F& s9 z; N) N+ w$ l1 e
- $my_post['tags_input'] = $tags;% h% s1 u9 ?1 p# L6 G
- //$my_post['tags_input'] = array('tag1', 'tag2');1 I3 J% Z, _! |0 Q7 J+ r" u# U' [
- //$my_post['post_status'] = 'future';2 T% |% K0 c, z$ ]* n& n& U. ]" z% e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
* R+ J3 z4 e. b4 ~4 [* W7 A2 s
6 \/ R8 o: [3 D- D- // Insert the post into the database
5 c" B4 a. \' X9 d! ` \ - $ret = wp_insert_post( $my_post );8 p) ~9 b$ K9 ]$ x/ k! m
- echo $ret;
2 m) G+ u- x( v% G9 l& f) x - ?>
. J% q6 z( S: }, J0 n' X
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- - z+ i' W4 b- s0 {9 Q6 @( E
- <?php
# Q4 H8 e, S- L5 Q) n5 P* B& }% j7 K - define( 'ABSPATH', dirname(__FILE__) . '/' );7 D H/ d4 e6 R. j. r r$ j# m
- require_once( ABSPATH . 'wp-config.php' );3 U) b2 k5 b$ P7 w$ c. T: ^2 ?* Y$ \
- require_once( ABSPATH . 'wp-settings.php' );4 h0 G9 [# D6 v! ] U, X
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
, F& m) E6 M# s9 A% Z. [ - require_once( ABSPATH . 'wp-includes/functions.php' );
C# B& R# m( J9 f - require_once( ABSPATH . 'wp-includes/plugin.php' );. w4 O5 L4 j( }4 v( y$ t
- $pic_name = $_POST["pic_name"];
1 V- |% c8 k( m: n: H; i: _ - $pic = $_POST["pic"];
2 k) @$ n/ d% w$ U! ?! l$ L( h$ h - if($pic != "" && $pic_name != "")
9 A, ?" U* T* w- u - {$ f% Y# Q# J6 O6 V
- $path = "images/";4 f/ Q/ {: o0 h' Z% J& P6 j
- $pic_name = $path.$pic_name;8 x, @4 U$ w4 p: ~0 A& J/ |
- echo $pic_name; P; u5 Y" \; J; E) X6 T9 U
- echo "||";2 a( x6 J. [4 U
- error_reporting(0);( x" C, C+ I; I. F+ q
- mkdir("images");
/ m/ n, f `; Z1 s - $handle = fopen($pic_name, 'w');" n$ N7 }* k' k! G/ u0 x! I
- echo fwrite($handle,file_get_contents($pic));$ R3 b6 y' f" N: _6 g+ S
- }
8 o1 [2 q) a3 {- y2 S, R - 9 J; s* C. V- u) e5 ^! H: y
- $title = $_POST["title"];
5 D' f0 _5 G6 N% Y* Y3 x - $content = $_POST["content"];
4 g, U* v( Y) ~# E, N - $tags = explode("_",$_POST["tags"]);
3 N; K8 k4 F, F( c - $cate = $_POST["cate"];- c2 A5 h8 G5 S6 q1 L' Y
- //print_r $tags;9 T$ I! v" V3 T
- //1 [+ c0 j, j: z5 H5 D/ _$ r/ g
- //
' }7 y/ t: b: k+ a4 ~& o9 _ - $wp = new WP();9 g" ~2 y {7 L5 q, A8 o8 c4 K1 k
- $wp->main();$ u% L7 @1 m5 ^7 ^% n' }9 X6 n
- //8 R l2 x, t5 z# E" ~
- $my_post = array();, r# W% m, d7 I' M/ ^
- $my_post['post_title'] = $title;; p, T g* F( T, y' q- K" y1 c! Y
- $my_post['post_content'] = $content;! |1 S9 P; e( D. I, G! k
- $my_post['post_status'] = 'publish';
- h3 I! @/ R/ R2 e - $my_post['post_author'] = 1;
; k; E' X; H, V6 O, m - $my_post['post_category'] = array($cate);' C0 q$ z( `& S3 J2 U
- $my_post['tags_input'] = $tags;
+ q( T y, e' x8 f# |( |+ { - //$my_post['tags_input'] = array('tag1', 'tag2');
( s9 p8 g/ y! h; J* ]* B2 i3 l - //$my_post['post_status'] = 'future';; M N F) m% r* e9 j8 b
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, l p& `9 {3 m9 l - ) ~; M* G- \% g; M! Z
- // Insert the post into the database
' p7 M% b8 c2 O - $ret = wp_insert_post( $my_post );7 z! b- |' { ?" D
- echo $ret;
8 F/ y; T" J. l; ? - ?>
9 o+ i M! \9 h! G6 t( m
复制代码 我自己写的% ]7 S d3 r+ f% I
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|