|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 % h* a. {9 m9 t
, c! V: ?/ r7 o7 v4 |* Y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持8 d {. M1 D4 b) E. L* j+ Y6 U
- r; D' E+ V7 S+ M1 u0 s1 d8 P
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
- ]: G6 w4 k( p9 \/ |" }: a* B/ |$ c$ S. @" v6 t" Q
方便实用 简单 何乐而不用呢
6 D( z4 B0 ^7 G- <?php7 p2 q# R; W1 s- p9 ^+ |+ G
- ! Y. R, q4 q/ W% W
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. {: h6 Y5 x; k6 ` - require_once( ABSPATH . 'wp-config.php' );
% U2 S6 L3 u2 d! @: X - require_once( ABSPATH . 'wp-settings.php' );
. g. a. j4 Y2 ^ L - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; ^# h$ L0 @, J0 t' r - require_once( ABSPATH . 'wp-includes/functions.php' );+ d3 w: R5 c3 r
- require_once( ABSPATH . 'wp-includes/plugin.php' );
5 Y1 I& X% U S# x; g9 o - $title = $_POST["title"];
: N. n" M* q9 `1 j - $content = $_POST["content"];
. S+ R5 W" F: ]+ J - $tags = explode("_",$_POST["tags"]);9 \/ ~0 ]- s: @5 X( s: E- \8 W
- $cate = $_POST["cate"];
/ y! ^" g$ O7 B/ `/ s - //print_r $tags;, l% }/ l1 x( Y; i1 Q0 k
- //
% G# v; m2 D! W4 B6 G% ]$ d - //& H/ i! T- j; O
- $wp = new WP();
; o5 g! |8 H$ Q- c4 i0 t - $wp->main();
! |4 b" ]+ G, @; }6 `- R7 l - //
m# H3 b' n3 @! Z! e0 x2 m - $my_post = array();" w: q- b* f. @+ ]: O
- $my_post['post_title'] = $title;- I5 S& J) Q* l% N- v8 S' j
- $my_post['post_content'] = $content;
c; H6 E+ t9 c1 L - $my_post['post_status'] = 'publish';7 T1 V- l% j% j+ b* m& {) V
- $my_post['post_author'] = 1;5 ]% D' ^2 y* u( \) t% A$ m
- $my_post['post_category'] = array($cate);9 o5 N) W( G, K
- $my_post['tags_input'] = $tags;
6 e# n/ d0 Z$ x# a( f, ^ - //$my_post['tags_input'] = array('tag1', 'tag2');- P) _7 n* J! \; r$ V4 W
- //$my_post['post_status'] = 'future';
9 a& W: v7 O2 R# S- v p - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. v( t2 Y' p. `) U; S2 | - % w% s" u$ h8 X# D/ l
- // Insert the post into the database. B* Q( J# N5 k/ e* i
- $ret = wp_insert_post( $my_post );
" Q1 Z8 {. }- X/ b. e2 l. B - echo $ret;
9 S3 i1 _( b, a6 d$ N4 } - ?>' B; S6 L8 Z; f& D8 ^( M. m% ~; k
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 [+ |( ?( L6 j* I: h: u- <?php
L+ ~9 ?1 T4 h/ a/ ]% z# W - define( 'ABSPATH', dirname(__FILE__) . '/' );2 t, N2 _9 m% Y* E+ {- l
- require_once( ABSPATH . 'wp-config.php' );
4 h" q3 [2 C- {! x9 |0 w - require_once( ABSPATH . 'wp-settings.php' );5 E1 Q6 c! H3 }) `" R/ O( j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );* a% O5 L' O: u5 |
- require_once( ABSPATH . 'wp-includes/functions.php' );" q2 E( [+ z) G c1 A$ O: T
- require_once( ABSPATH . 'wp-includes/plugin.php' );
- K L" b; o; a( |/ a- j6 m - $pic_name = $_POST["pic_name"];0 ?1 k! X$ J$ @; `
- $pic = $_POST["pic"];
" A! I4 F% f" b& }% d - if($pic != "" && $pic_name != "")
9 t2 b5 i A: f; k& t, J( Q4 E - {" W Y$ X" @5 T8 Z+ |* r
- $path = "images/";+ x. r: ?9 R" }3 w+ F4 Y
- $pic_name = $path.$pic_name;
- H* ~0 P+ z/ `- J) N! X* p - echo $pic_name;; L8 N# K3 b3 O. k3 z: N
- echo "||";
4 [& T/ _$ L+ p" `. y* R f - error_reporting(0); {+ _4 \* Z- M2 a' ~, _
- mkdir("images");
9 O/ V: U6 `! {* M7 A - $handle = fopen($pic_name, 'w');
! Y2 S) T4 n/ Q8 ?2 B: v9 i9 y - echo fwrite($handle,file_get_contents($pic));
6 X$ s1 M8 P8 U - }! b- u5 r8 }8 B, T6 l
- * V) R; N1 y0 [; _1 U o
- $title = $_POST["title"];
9 O3 j, N6 K% Q - $content = $_POST["content"];6 S/ ?5 z4 h% M/ ?& f
- $tags = explode("_",$_POST["tags"]);
3 P. c% j4 ^$ { - $cate = $_POST["cate"];( q# ^) | c3 g* Y+ p) d8 m: l! `/ L* Q
- //print_r $tags;
# I' r+ _! a/ r; O' R( p" d - //
* `. a7 t' H+ L; g - //6 e: L7 Q& b# M0 T* U/ I; Q0 m
- $wp = new WP();; O( F/ Y1 d& X4 ~
- $wp->main();
: H- x- E: Y3 M$ b7 C5 d - //
, u# ~% n, l; } - $my_post = array();5 }( L! i' j3 V
- $my_post['post_title'] = $title;
' |7 _( l- k1 E& H9 K - $my_post['post_content'] = $content;
" a' a! p$ Y* {( M! u - $my_post['post_status'] = 'publish';, T, ]% X. j: z$ c, Q% e
- $my_post['post_author'] = 1;
; u7 P+ Z1 c4 N& F - $my_post['post_category'] = array($cate);
0 H4 W- a6 }6 \! {9 N - $my_post['tags_input'] = $tags;! `( \- H- u# t% K, [1 |- q1 l* K
- //$my_post['tags_input'] = array('tag1', 'tag2');* U% R, h* ]& w' O0 E+ P, Y
- //$my_post['post_status'] = 'future';
6 q+ l& b( _) w; q - ////$my_post['post_date'] = '2010-07-04 16:20:03';% E8 n0 \( S( Q) Z7 |/ e8 {- G& U
- - k8 p4 B- Z6 b
- // Insert the post into the database$ d. }' ?" B) T
- $ret = wp_insert_post( $my_post );
' T V: V- U& {# Z/ k% P - echo $ret;
- g, \+ d- m- O6 H - ?>
; V; u+ d( f- u/ T) b
复制代码 我自己写的0 r0 r; N. ^, M% N9 n { u
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|