|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 F2 A5 v" V) [- b8 Y
2 n9 j c8 Z/ O: f- d直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) S7 }: Z U4 e! A) E' Z* c
Z6 ^, d: z- ^( r+ f6 O ~我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
# f% T) b! U( n. z+ |1 v' C; W M4 T* o
方便实用 简单 何乐而不用呢- . c. A0 K# Q9 F- y/ y( I
- <?php
4 [" X: L! y+ G
% x. u3 w* K6 P, m+ o- y* l- define( 'ABSPATH', dirname(__FILE__) . '/' );
% a# V3 v* Z( l/ P* | - require_once( ABSPATH . 'wp-config.php' );
/ [! O" T" ?9 I6 {- r# c4 C - require_once( ABSPATH . 'wp-settings.php' );2 W9 [; ^9 J* u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );. a U, E7 H# p& b. W
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 F4 M3 J8 G% g, ?" H - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 M) p2 L' h9 n* U3 v( } - $title = $_POST["title"];
$ B2 z" i: i' D6 s4 N0 z - $content = $_POST["content"];
' r9 x5 f+ b5 C# `5 E9 A' @ - $tags = explode("_",$_POST["tags"]);) i2 v& P* K& X. Q. P$ Y; t
- $cate = $_POST["cate"];
$ T' f. F0 Q2 W: W1 e - //print_r $tags;
( X: a5 n/ W& t9 D% P+ { - //3 j: @- K8 M! y. m
- //
4 K: G" Q2 v1 ?, s, ~ - $wp = new WP();
a) k. f! B3 w/ q) R) a l - $wp->main();
- @- {3 w8 Y/ r4 N, T3 j - //+ N+ Q1 u1 T& c4 X
- $my_post = array();
\: W ^& n6 p4 ~. B) x, S) @ - $my_post['post_title'] = $title;7 M, w4 O5 J+ s+ C
- $my_post['post_content'] = $content;' `. [8 f" d+ q X
- $my_post['post_status'] = 'publish';2 U, W& Y# C# Z @' b
- $my_post['post_author'] = 1;! Q1 x$ m4 b$ Z! W+ k
- $my_post['post_category'] = array($cate);
! J9 [' C; X+ c" A; B1 ` - $my_post['tags_input'] = $tags;! F7 [4 i% R" G! u
- //$my_post['tags_input'] = array('tag1', 'tag2');
A! x( C1 i4 w1 H& j - //$my_post['post_status'] = 'future';$ y a7 k: o3 M: A4 l! Z6 |- f, g
- ////$my_post['post_date'] = '2010-07-04 16:20:03';4 \- ?. h, e$ M4 R w& B8 @
( s! O0 q4 q4 F( u3 |- // Insert the post into the database$ m; a( V: h i( _ r. i
- $ret = wp_insert_post( $my_post );; x2 t/ Q- c; G0 @' G6 b
- echo $ret;0 e4 O% G$ P- L4 a! Q1 U! I5 }
- ?>3 d0 i* {, ]' W: E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- - V' ^9 K9 \- e. A2 U, S
- <?php
3 C0 N2 H0 A' F+ ` - define( 'ABSPATH', dirname(__FILE__) . '/' );+ q- w0 V5 s; a) P$ E" p- C
- require_once( ABSPATH . 'wp-config.php' );
' c1 J1 F5 D: g9 T9 Z8 }4 T; l: d - require_once( ABSPATH . 'wp-settings.php' );; v, l, ~/ N% U9 Q: @0 m3 H0 d
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 j6 L, G) c8 Y" E - require_once( ABSPATH . 'wp-includes/functions.php' );
( ~3 j' T# ]% C7 N4 b7 c Q - require_once( ABSPATH . 'wp-includes/plugin.php' );
: ]2 ]" m- E9 v$ u: d' ^ - $pic_name = $_POST["pic_name"];; F, M( Y4 @+ a0 j* D
- $pic = $_POST["pic"];
' l3 b2 ~# V- C4 X! r - if($pic != "" && $pic_name != "")
+ T1 K1 O [% E; T5 R - {
2 s4 W% `' I4 P8 z! s/ L; `2 l$ P - $path = "images/";3 Q6 J* F8 x7 S0 `
- $pic_name = $path.$pic_name;
. _9 L- {+ ^9 f6 [( B+ s - echo $pic_name;& h% [! F- `, W( H# N, Z4 y
- echo "||"; t, O% g* m6 P+ w
- error_reporting(0);
B3 _; R+ R! E' U - mkdir("images");
) C0 q t$ N& U2 R$ d, G* \ - $handle = fopen($pic_name, 'w');0 q7 P( u( i* T, D+ W
- echo fwrite($handle,file_get_contents($pic));
1 m3 E6 q2 N* G - }
6 Q' R! j' X) m
3 z/ r V( |* R, s. i8 f( _5 D- $title = $_POST["title"];
! y0 U1 L8 F8 j' h0 S8 _5 A7 ` - $content = $_POST["content"];& |: Z- z4 u2 @. U( N/ K
- $tags = explode("_",$_POST["tags"]);
# U! w2 c4 O* i: _: x) ?' m - $cate = $_POST["cate"];8 H# b+ n2 g* V
- //print_r $tags;+ ?" n3 i9 p4 }8 I8 B) c0 r5 D
- //% w& |* s! ?- V' ?: L0 i
- //% T" X8 v3 K- H
- $wp = new WP();5 @+ s2 ]* I5 e
- $wp->main();
, ^2 o h: K1 Q5 N( S+ D' r - //
& y8 e( |5 P' D1 q- d W+ C' C& m - $my_post = array();
8 F8 R p5 L+ f6 t2 Z" D5 V3 M+ H - $my_post['post_title'] = $title;
. q6 b" k: p% {4 W h9 r - $my_post['post_content'] = $content;
8 T; [& \/ {* {/ @* q2 x1 p5 J - $my_post['post_status'] = 'publish';
4 |) b3 \5 \6 H4 l - $my_post['post_author'] = 1;- U5 S( o0 D& C6 R$ o0 s9 U
- $my_post['post_category'] = array($cate);; `: C* n; @8 v
- $my_post['tags_input'] = $tags;. X. B' b, S# q) X3 i- A
- //$my_post['tags_input'] = array('tag1', 'tag2');2 d$ z: y1 s6 u, R
- //$my_post['post_status'] = 'future';
/ I* ?* M7 y, [- O8 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';
* D& Y/ j8 z3 v7 H
" e {! ^# |8 ]5 p8 Z- // Insert the post into the database
1 V/ N/ L6 y' J' M1 Y! N - $ret = wp_insert_post( $my_post );$ ~( Y, N+ {0 k. a" d' d: m
- echo $ret;
% r* P# ~# D; ` - ?>
^% [" V8 z7 \. A
复制代码 我自己写的, Y% o0 A2 h5 t9 ? R
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|