|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 b" W4 A0 t4 ~: w6 b% g' O7 G% F1 ?- a3 C
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
$ ]! Q, l6 q% A6 E; \0 d% e' |! Z: Z! i5 t1 e# g ]) h- o7 Z
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 H$ ^8 X( Z0 `( ^6 c
' d5 _+ `3 I* w, r- `# f% U) F& L! i
方便实用 简单 何乐而不用呢
6 ~; t: _( m2 m& N P4 y* [- <?php
5 V; |# V# P, z+ V6 Y9 h - ; w4 i: _: T& x# a" R
- define( 'ABSPATH', dirname(__FILE__) . '/' );
; I! C: y2 o& d, _ - require_once( ABSPATH . 'wp-config.php' );* |3 ?7 u. h; i7 B. f) c( P
- require_once( ABSPATH . 'wp-settings.php' );
, K' _# C0 @4 ?2 B - require_once( ABSPATH . 'wp-includes/class-wp.php' );, a) @# g3 H& B+ [3 b1 L/ k3 w q7 U
- require_once( ABSPATH . 'wp-includes/functions.php' );
9 i9 b( `/ t5 _6 H* i# l* p& L - require_once( ABSPATH . 'wp-includes/plugin.php' );
( X6 V1 V; j/ A. P - $title = $_POST["title"];- p0 N) h5 L$ A7 ?9 g/ J
- $content = $_POST["content"];
6 b7 |1 @8 q+ O1 g - $tags = explode("_",$_POST["tags"]);
; e* P: j5 t5 o4 h - $cate = $_POST["cate"];
2 g) L- ?& h; v8 ?# r& a- R - //print_r $tags;3 `8 J" r4 C# M) }" {) [/ D- L
- //
7 x m" P z0 N$ Q7 O! ?1 ` - //
8 M1 A4 b, Q' ~ - $wp = new WP();8 _+ N9 t% |$ A2 w2 p9 t
- $wp->main();7 S" `1 U; z& \* D
- //
2 n) V- R5 l! x* I - $my_post = array();
8 K" A$ I f/ B/ C& g) j6 Y - $my_post['post_title'] = $title;
) `; p$ \/ H k9 S% E - $my_post['post_content'] = $content;. I j& Z; a3 W. ?; Q
- $my_post['post_status'] = 'publish';% w- g" x1 b. {9 O
- $my_post['post_author'] = 1;3 R" a o1 J) p: a+ s1 D: {3 j3 H7 d
- $my_post['post_category'] = array($cate);4 a/ ?/ D5 @1 E( C
- $my_post['tags_input'] = $tags;4 ^% Z5 ~5 @: h3 g3 Y, Y* d
- //$my_post['tags_input'] = array('tag1', 'tag2');/ X# n3 F: S+ U+ T+ W
- //$my_post['post_status'] = 'future';% d; `0 e3 P7 n+ j4 }
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 c1 J. `' E6 G, q
2 w( @3 R7 H% A8 m- // Insert the post into the database& p7 P+ M" x! z& d1 q
- $ret = wp_insert_post( $my_post );0 [+ Y- U+ ~. [* a' ^$ H
- echo $ret;
$ j0 O7 c) }3 t' d# a3 \ f - ?>
6 P6 ~- o3 I5 j4 F5 B9 O
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; {# E& r$ `' e+ S5 `8 A" _
- <?php; `1 ~& E$ V/ Q+ N7 N
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 _. e% t8 k2 W
- require_once( ABSPATH . 'wp-config.php' );
/ N8 O' a8 G3 J, Y% { - require_once( ABSPATH . 'wp-settings.php' );
) R1 o G$ U J - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 G3 ^* H# Y D$ t: M U! A7 t - require_once( ABSPATH . 'wp-includes/functions.php' );. C( s. Q7 J& q( j, P3 g( o
- require_once( ABSPATH . 'wp-includes/plugin.php' );
0 i* {: Y& e7 n* I( ]% C# t - $pic_name = $_POST["pic_name"];
. n x1 ?* p4 C' I. j7 V7 S - $pic = $_POST["pic"];! q4 o" u6 ^; q& O/ [
- if($pic != "" && $pic_name != "")
9 r9 l3 [: t+ U; W - {; q1 D, `( ]4 Z- M" J6 a- A
- $path = "images/";
, I( c/ G4 [# f - $pic_name = $path.$pic_name;
9 f) A1 R! m' { - echo $pic_name;7 x" L% J; K8 a1 E) ?
- echo "||";6 G) d- o% h3 h/ Y$ ]5 V
- error_reporting(0);1 T/ P: G, A& Y' f+ B% b7 j
- mkdir("images");9 M9 ?4 [' J/ l$ f( b
- $handle = fopen($pic_name, 'w');% p# n3 q8 a3 y! X
- echo fwrite($handle,file_get_contents($pic));' R7 F! N$ n! `# z3 Y, { ?
- }
- `! d {5 n9 c$ t' x- I
5 K: @. D, |) `/ Z. r- Z- $title = $_POST["title"];
( v$ T9 Q; z$ F% @ - $content = $_POST["content"];6 O& w' b! l% o
- $tags = explode("_",$_POST["tags"]);
7 C8 E; w3 \/ Y: H7 {1 r - $cate = $_POST["cate"];
: J- z) P5 j' S. q6 x+ z - //print_r $tags;
% f- Q( K7 p6 R, P5 R1 ^6 }, C - //* w u2 O @" x6 B4 K$ @1 A6 l7 G( B0 [; q
- //
/ d7 f: {. {0 R) [8 W) [) U - $wp = new WP();+ o, y1 _( y9 L+ M5 G
- $wp->main();- @1 T8 |$ a, S4 @& ?1 \3 ]; J
- //
9 d8 N( ^3 F. x" z3 ~: t - $my_post = array();1 E: q7 L/ Y: Y! a2 I( f" b2 j
- $my_post['post_title'] = $title;/ T" F1 W, T: H- s ^
- $my_post['post_content'] = $content;
7 H Q, L# }4 p$ r7 ^" s - $my_post['post_status'] = 'publish';
; W) S) x1 v) |9 u - $my_post['post_author'] = 1;0 N) j3 N2 K" i) ?' |5 U0 i
- $my_post['post_category'] = array($cate);- J3 k8 h0 V6 O6 Q+ n j
- $my_post['tags_input'] = $tags;
' j, |/ ]! ]) a& J - //$my_post['tags_input'] = array('tag1', 'tag2');6 L1 x$ [1 n" y- \8 H! e
- //$my_post['post_status'] = 'future';8 O; r9 p5 D A% S! v5 W% D! E
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
- u2 a/ E/ o, _8 y
6 D; }# z# V0 [# `4 {- // Insert the post into the database4 G6 g1 p5 K( I# T3 j& U$ B' }
- $ret = wp_insert_post( $my_post );
, o" a% U& X( O0 e. ]1 t7 B - echo $ret;) o1 @/ M0 ]6 c- L5 l$ `
- ?>! s: d7 n R, w; Q
复制代码 我自己写的) J/ D% S: b& @, |$ `; w
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|