|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 + W' U2 N" X: N5 x1 Y
; x& o: R L7 g* t: c5 ?
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
2 M1 t/ k% Y2 M7 Q) D" K6 M7 T5 r K- |, n5 k) y
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 b( d4 t4 G6 L8 }; q: d8 Q* q
# d# s; g. c; T# x
方便实用 简单 何乐而不用呢- ! `+ U$ e2 a0 U) _: k% y
- <?php+ ]; A) j$ T: r3 m+ N
- ) o6 T( W5 V$ ^! p8 @5 G( K
- define( 'ABSPATH', dirname(__FILE__) . '/' );) p+ C& k+ `) U3 ^0 P. O% ?' A
- require_once( ABSPATH . 'wp-config.php' );& L9 c, b0 A0 j2 p7 G$ |- S; ?" T
- require_once( ABSPATH . 'wp-settings.php' );
( \1 Y: S, Q8 l- u ~5 X+ D - require_once( ABSPATH . 'wp-includes/class-wp.php' );" @4 n( q9 _$ U0 u5 q6 H& f
- require_once( ABSPATH . 'wp-includes/functions.php' );
- ~9 @. ?, s5 m - require_once( ABSPATH . 'wp-includes/plugin.php' );
) l6 ?3 o! z' T2 ~1 i - $title = $_POST["title"];
# A: Q$ U' N) Q7 r; G6 ^2 P3 t) ` - $content = $_POST["content"];
8 a8 P) k" |: e: [ - $tags = explode("_",$_POST["tags"]);
( q$ R6 l1 o/ f% }+ r3 ] - $cate = $_POST["cate"];. E* M- l& I2 s
- //print_r $tags;; o1 Y) N. G6 J/ A4 t
- //
" A, F% y0 ^ a$ j - //
( E( ]1 @% X+ ~ - $wp = new WP();5 P; W: M. x, T9 H# p7 M3 z
- $wp->main();4 v9 I/ m' H8 }# b& [6 W4 y% [
- //
. q7 U6 F3 N( A3 S* n - $my_post = array();7 y0 x& ]6 K! w* B2 t8 h' h
- $my_post['post_title'] = $title;6 Z7 C. t) P4 B! s) L
- $my_post['post_content'] = $content;% @4 Y' k2 J- v) q5 U$ ?% t+ ]
- $my_post['post_status'] = 'publish';
! U: X9 {& r" ~% r; ~ - $my_post['post_author'] = 1;+ l6 ~; |* }! n4 U: e! ?% e8 E
- $my_post['post_category'] = array($cate);
1 t' g; |# H- N - $my_post['tags_input'] = $tags;
1 B/ S3 I6 j" ?, O7 G - //$my_post['tags_input'] = array('tag1', 'tag2');
2 X# d+ @/ i2 Q - //$my_post['post_status'] = 'future';3 v, W/ L0 p0 ~
- ////$my_post['post_date'] = '2010-07-04 16:20:03';& x# W: f; N! c9 q1 Z
0 j0 s& \- ]( B8 R( h$ a- // Insert the post into the database
3 x, @& t/ g# C+ N6 R - $ret = wp_insert_post( $my_post );8 j# s4 A i4 I$ n% N2 `
- echo $ret;
: d! ^, l5 s3 K( o - ?>9 R; K; @5 ^1 p8 ?
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 e6 b; Q3 P" C' }- <?php9 ]* b9 o0 f8 n' |8 ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ |# s" H) G6 i& Q' }6 |- `# P - require_once( ABSPATH . 'wp-config.php' );
S' v* r$ E" x( e$ q - require_once( ABSPATH . 'wp-settings.php' );
5 C! U3 X$ _6 D% O) O - require_once( ABSPATH . 'wp-includes/class-wp.php' );, \0 i. v* X. `, L+ o1 k
- require_once( ABSPATH . 'wp-includes/functions.php' );
- c+ E9 O) P) p5 ]7 @ - require_once( ABSPATH . 'wp-includes/plugin.php' );, N0 j2 w& D8 X- ?7 _" @9 g! i% L& H
- $pic_name = $_POST["pic_name"];( ?7 j/ o, I# Q7 k. d; ~2 k
- $pic = $_POST["pic"];! c4 f7 o3 ]* W: D+ ?: ]* j+ }9 o
- if($pic != "" && $pic_name != "")
`2 Y! x6 E) c3 z9 y! t: ? - {* T% Z% A8 z: s' o
- $path = "images/";
; P& R' S3 U1 l s; F5 a - $pic_name = $path.$pic_name;
. u0 g# r- E! D* ]# j2 s1 K* }$ @ - echo $pic_name;
0 w, p$ t7 Y4 N3 n3 [ - echo "||";& G4 o: C( k3 Q
- error_reporting(0);' f z H2 o% a3 W
- mkdir("images");; v. n! j1 ^0 j
- $handle = fopen($pic_name, 'w');
# e) n S4 ^ N4 J4 z( G% [ - echo fwrite($handle,file_get_contents($pic));2 o. K, I; j- N# c
- }
+ D3 L& {' S8 ? - + E+ [0 N- H# U7 C
- $title = $_POST["title"];) T% |8 o' \/ n
- $content = $_POST["content"];
. D: {! n- C9 @3 F, t& M; u _ - $tags = explode("_",$_POST["tags"]);; P, x0 Q: [' K: ?; ]* X
- $cate = $_POST["cate"];
' `1 s! S3 U* x- e8 V - //print_r $tags;* X/ q$ J; H% r+ b0 ]* x
- //: F. p% ]4 E; [4 w
- //) I- |% b& F+ Z* q
- $wp = new WP();
; c4 D! i: L# T - $wp->main();
0 F1 Y( d4 R b( K8 ?( C7 X0 h - //
2 D: [" y$ ^1 c# \" p; @) M# a - $my_post = array();
; k. G* y) V0 h1 m" H5 a7 Y# k - $my_post['post_title'] = $title;
- ^: x7 T( P0 k: V: f - $my_post['post_content'] = $content;0 ^+ f. F0 w; B% C; X
- $my_post['post_status'] = 'publish';
$ x, Y# _9 x0 P* J - $my_post['post_author'] = 1;
# C n8 F1 m& [& `8 |6 g) k - $my_post['post_category'] = array($cate);
( W% e# K) H7 Y" l3 d8 u - $my_post['tags_input'] = $tags;
8 @ q* M& ^4 _) V - //$my_post['tags_input'] = array('tag1', 'tag2');
3 ?( e: N. ?6 w, Y8 C. D; m4 g - //$my_post['post_status'] = 'future';
! R5 J. r) t0 V6 j2 L - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ E. [. k; g8 m3 N" S, K# Q
. Q1 z7 R J- i6 n4 _7 t- // Insert the post into the database5 ~. R, w; d9 W! b
- $ret = wp_insert_post( $my_post );
) b0 b; L, c5 X1 U2 H+ w: ? - echo $ret;( j" m) r4 z- a5 S% I" r1 {+ a0 n/ n, n
- ?>7 x+ G* f; S- k* e5 |. D
复制代码 我自己写的4 j) t& V0 v$ G" [
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|