|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, j0 F) {6 F2 A6 w
& U- f; S4 M5 ?/ ]7 {+ F" {直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持. ~9 z- D: }# a2 F, ~- u! _7 p
( Q& T: K2 P# E) R; R
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
3 p6 E$ F, x( Q+ [3 Q) O) B4 T2 h1 r# `' {: G
方便实用 简单 何乐而不用呢- 0 b$ d) [6 g. s' V/ I/ F
- <?php1 |! I; z+ B7 ` k0 {( ~
" j9 |2 w( A" X# ]- define( 'ABSPATH', dirname(__FILE__) . '/' );
* N- i; d1 E N M2 J - require_once( ABSPATH . 'wp-config.php' );
! H, j5 ^/ @5 C r2 @ - require_once( ABSPATH . 'wp-settings.php' );
g& s4 g& P% C4 F - require_once( ABSPATH . 'wp-includes/class-wp.php' );
) `0 J2 @" `3 t3 q0 z5 Y9 C; l - require_once( ABSPATH . 'wp-includes/functions.php' );
* E, i8 Q2 _4 P* W' `/ R3 w1 i2 \ - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 T5 R6 [ e4 _ - $title = $_POST["title"];
0 R6 P3 M- M8 X6 r) {1 C7 j - $content = $_POST["content"];. P1 u- f8 q0 E" X1 v0 I# G
- $tags = explode("_",$_POST["tags"]);* i' t+ e' e- S
- $cate = $_POST["cate"]; L8 H3 R1 G. d0 S" N3 Y
- //print_r $tags;
& u. t% e, p) V7 o# Z: c l8 U - /// _8 Y5 b' q# D' Q8 w" G
- //
0 R4 S: s! _/ Z& L - $wp = new WP();
- W$ h7 m- o' O/ w, Z - $wp->main();
1 o5 \0 Q, I' C: z - //
2 r1 h- @/ W, b+ S; c - $my_post = array();
& w( L4 p+ I/ K: U - $my_post['post_title'] = $title;; }" B x% l! H/ y% F
- $my_post['post_content'] = $content;
/ F# H, B- E; n! s+ v - $my_post['post_status'] = 'publish';7 B. }" r/ O! b6 n
- $my_post['post_author'] = 1;
3 \; m1 @0 I1 z1 u; | - $my_post['post_category'] = array($cate);; U& ~; a7 x6 g+ I
- $my_post['tags_input'] = $tags;1 u7 I! X \( i
- //$my_post['tags_input'] = array('tag1', 'tag2');
0 P6 p- ^$ j4 e6 R) F Y' K& Y - //$my_post['post_status'] = 'future';
4 |, h& p- G8 C* W4 W - ////$my_post['post_date'] = '2010-07-04 16:20:03';: q: e& k* a/ k: S9 ~! N* t
- ) ]( \6 R- I+ v1 N' E
- // Insert the post into the database
$ l3 a7 {$ s, G& J% o9 D! z5 I - $ret = wp_insert_post( $my_post );0 Y: K7 P' s4 H( Q3 m
- echo $ret;
- E# R& |, j9 x& ~7 G' J - ?>
& K+ H& E' B$ i( P \ j8 I+ g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & B9 ~0 W2 u# y& k
- <?php; r* S) w8 b. z# v2 W
- define( 'ABSPATH', dirname(__FILE__) . '/' );
, x5 \4 M: w6 {. H3 z - require_once( ABSPATH . 'wp-config.php' );
" `/ A" K6 ]3 W# ~# i, n Z3 v2 {) Y - require_once( ABSPATH . 'wp-settings.php' );' F4 L! ?: A+ ?" |
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 N/ l V& o/ |( R G0 Q. U
- require_once( ABSPATH . 'wp-includes/functions.php' );
6 q4 b- h& ?- O5 e( S - require_once( ABSPATH . 'wp-includes/plugin.php' );. V- p1 H# _) @, W% b
- $pic_name = $_POST["pic_name"];5 j: L' R/ ~$ C1 t$ |. g5 r
- $pic = $_POST["pic"];
5 S+ N9 Y7 {: h1 X0 P2 f - if($pic != "" && $pic_name != "")' s. h" d) x! E! u: p8 @7 l
- {
( }- ?8 `, I0 ]" d6 G2 a - $path = "images/";' w: S2 f! U# G! B
- $pic_name = $path.$pic_name;6 x0 g: o p9 s" `
- echo $pic_name;$ c( B, v" H0 i8 G; l
- echo "||";+ V8 w7 t9 B) |! |$ N; _
- error_reporting(0);' K) B: J7 I: b
- mkdir("images");* T: J# u; \0 ~: C# c2 O4 W
- $handle = fopen($pic_name, 'w');! G/ ~ W8 t! p( H% I* U1 m
- echo fwrite($handle,file_get_contents($pic));
1 d. `9 G) H3 P+ | - }0 P# b+ O3 R& \# s8 a
- ' j& y U9 x# [ Z
- $title = $_POST["title"];
6 u0 m2 {9 C, t - $content = $_POST["content"];( S) ]$ ^ `, x
- $tags = explode("_",$_POST["tags"]);
5 z# P2 n( }- P- K J - $cate = $_POST["cate"];. U+ ?4 e ]/ w$ Q
- //print_r $tags;- D0 V% _5 v2 {+ r/ g
- //
* P) Z( l# ~7 \) i - //
5 P- `! G0 t9 }4 ]0 o - $wp = new WP();7 Y2 |) c% p' H: j! Q9 _. y. U
- $wp->main();) q( ~+ B9 F! m+ H0 t
- /// ?7 T( A% {/ V6 W8 @9 a
- $my_post = array();
! N4 S7 e3 @ p# V3 G8 v - $my_post['post_title'] = $title;6 j- t- o/ D4 z3 C& c2 B# \
- $my_post['post_content'] = $content;+ B7 w) w0 T( @3 H q; c0 z
- $my_post['post_status'] = 'publish';1 u% G$ g% ?9 `' p
- $my_post['post_author'] = 1;2 h9 z8 }" i# R4 v6 J% y, p
- $my_post['post_category'] = array($cate);
) ~7 T$ {) q( |5 f$ [! n) h - $my_post['tags_input'] = $tags;( | U6 e' f' g) v
- //$my_post['tags_input'] = array('tag1', 'tag2');
8 d" M* V$ ]5 ^7 z( G; | - //$my_post['post_status'] = 'future';
$ {. U1 `8 P4 G$ h* [( S - ////$my_post['post_date'] = '2010-07-04 16:20:03';$ S1 X# e9 ^( x, S7 Z2 T' [
% |2 t2 o* ?# D% ~2 r- // Insert the post into the database
7 D9 Y$ e8 V+ ]- J! V: Q - $ret = wp_insert_post( $my_post );
; F2 i1 D) g! a9 w4 N+ D( G9 o - echo $ret;
4 U% [) H8 e4 v) ? - ?>
; p* p* H" t o. m' g
复制代码 我自己写的6 J4 S% C# r# d9 W
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|