|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ; a8 U" A6 Z5 q) r
, K& f" h0 X# R: \直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 K7 j X! ~5 y: w
; i" ]! C+ s% j9 h0 d- R9 u我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 y5 t# s7 l5 S( L: c _. c
9 N& ]1 l( g3 ~1 s5 G方便实用 简单 何乐而不用呢- 3 ?1 Z% v+ j" P% n. s4 g% z
- <?php
- I- g. i, x, V# L4 G. u
) l, O4 C1 R1 O) a- define( 'ABSPATH', dirname(__FILE__) . '/' );4 G$ F$ |9 A' l2 s" I1 ?
- require_once( ABSPATH . 'wp-config.php' );
/ k+ J: G6 I: a9 E3 U6 E - require_once( ABSPATH . 'wp-settings.php' );
8 |$ `0 e+ L2 u - require_once( ABSPATH . 'wp-includes/class-wp.php' );" v: y; ?- v' ~' R7 Z- Y" X
- require_once( ABSPATH . 'wp-includes/functions.php' );
0 D, e- q) N& i& P$ S3 m - require_once( ABSPATH . 'wp-includes/plugin.php' );3 X) T: p5 _; L; x# w+ F- v
- $title = $_POST["title"];) K0 O* T4 n9 ~8 q/ _- L
- $content = $_POST["content"];) f3 N+ ^4 ?) H, {: y1 c: y* ~' k
- $tags = explode("_",$_POST["tags"]);, R7 }6 }( O. |& v% k2 W6 D0 S, I1 ^
- $cate = $_POST["cate"];! i; K& A: \0 d- u' z0 S+ [
- //print_r $tags;+ y0 x1 u: g' _+ w
- //
# n6 T2 i" D/ h6 H! a% F/ J - //% K& t1 C5 Q) W7 S* ?# w7 s, w
- $wp = new WP();6 k* `) d% i, [7 b6 |; p
- $wp->main();5 j1 Q9 ^: j$ U$ i! J/ ]- Z8 d
- //
9 x, A7 N* L4 S u/ h, O - $my_post = array();
/ m( n$ z4 N0 X; Q; Q3 y - $my_post['post_title'] = $title;
- i4 ?9 g% r( j# A% J; J - $my_post['post_content'] = $content;
- s7 l. L: Q7 E - $my_post['post_status'] = 'publish';; _4 G/ @- K7 K9 t9 `* ]) l2 U# d. y
- $my_post['post_author'] = 1;" `" J- j/ w; U% x+ {' D/ {7 y
- $my_post['post_category'] = array($cate);1 h4 ^5 E# r9 ?* z# T
- $my_post['tags_input'] = $tags;8 R3 M; i% Y; {5 K
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 d0 k& k) v7 I - //$my_post['post_status'] = 'future';& U# ]8 a* z* v2 Y$ O% e" D8 p! @; Y. d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 o8 B; R' T2 m) }+ [: v3 U7 e
- 4 o5 X. h: n/ \4 W$ n4 I }3 B1 ?, n
- // Insert the post into the database, S$ y; V9 f+ F0 a& i, \
- $ret = wp_insert_post( $my_post );
0 F: d+ \# O" n' l$ Q - echo $ret;1 x" \9 H; P* |6 Z, N4 j
- ?>
& y; Z' ]9 {- G& e! [5 z% g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + `" Z2 N- b6 g0 g
- <?php) r9 |" q& T/ K0 m' p/ T, g* Q! Q
- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 ]% ` z1 q6 M( l4 _& l5 m - require_once( ABSPATH . 'wp-config.php' );
( ~ {5 ~7 Y2 h- a, n5 p2 A1 A - require_once( ABSPATH . 'wp-settings.php' );
) |8 C$ x0 `% e/ j& r: ^/ ~ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
* u' Y* o: h, @" X( X( M - require_once( ABSPATH . 'wp-includes/functions.php' );- Z- Z6 p1 m: i# e6 R) w
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 [! B0 A* K0 l* o9 U3 L - $pic_name = $_POST["pic_name"];7 }9 e# m, W! a5 a4 c4 E" m
- $pic = $_POST["pic"];* _8 U" ?% ]* O: r# p
- if($pic != "" && $pic_name != ""); ?/ v% ^# G% k0 ^
- { {- z& M* I2 w, f7 l1 H7 w8 t& P
- $path = "images/";
) U L, e O- B/ `9 F1 B6 k8 i% m - $pic_name = $path.$pic_name;
4 j A- ~' g2 I$ t3 O/ k s - echo $pic_name;% r9 ~: V5 A4 d5 p x
- echo "||";" b7 D3 E0 H) D* Y2 K" b/ n+ d3 \+ l
- error_reporting(0);
+ S- s T' K/ C4 x - mkdir("images");
i5 `' B" G& U: W) w - $handle = fopen($pic_name, 'w');
, _' d9 a8 ~7 {8 m/ ?1 p - echo fwrite($handle,file_get_contents($pic));* }! [& u8 z) x2 { U% C
- }
5 M6 H" l; j0 t% W: D. V - 4 A, V3 _1 \; B8 m9 l
- $title = $_POST["title"];# I& X( |+ E, s/ I2 z+ N3 S
- $content = $_POST["content"];
7 j: h+ D, W2 b/ m' | - $tags = explode("_",$_POST["tags"]);1 `- C3 Q: Y8 n& m1 D# z) U* S$ w3 N
- $cate = $_POST["cate"];+ W, p# J4 ^/ e4 J! t
- //print_r $tags;
9 ]1 m, C3 d) r" U - //
9 J- X6 _9 P* ]# U4 G) z* O - //' M; N* m, c( @$ Y
- $wp = new WP();
- j, w U/ I8 d0 O - $wp->main();
; x6 |* G1 ]* ?! g& y6 Q ]: p - //$ h( S6 b6 u5 ?: V2 q
- $my_post = array();
* f2 b& g$ l8 _& s0 i - $my_post['post_title'] = $title;
7 Y1 w, M2 S# F# H - $my_post['post_content'] = $content;7 X. o3 ?1 T% a/ |0 H* H3 S
- $my_post['post_status'] = 'publish';
$ ^- y" \6 }8 r+ Y% i6 z, Y* L1 c - $my_post['post_author'] = 1;
( g' Z1 M3 d" A. C! e6 S: s8 l) [ - $my_post['post_category'] = array($cate);: ~0 C" v& f4 j
- $my_post['tags_input'] = $tags;
' A) U1 K" C) s9 i# J- C0 P - //$my_post['tags_input'] = array('tag1', 'tag2');( Q" A, M- [9 @( ?
- //$my_post['post_status'] = 'future';
9 ]+ ~' q6 f6 J4 l/ `2 t - ////$my_post['post_date'] = '2010-07-04 16:20:03';6 [8 G' ?# {2 ~; q5 H' e/ y* U. h
- . G6 C$ g9 f- E. n# o* L6 H
- // Insert the post into the database
9 f3 S7 z, H3 Y+ q* T - $ret = wp_insert_post( $my_post );% k' s* s: l3 f( b
- echo $ret;
( |: ?" s! R- H1 J - ?>/ \: u% q/ p5 z: E @
复制代码 我自己写的
2 ]5 i& n1 p" A+ x+ b插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|