|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
3 t/ E7 {, L& R0 Z4 Q7 c/ t% p3 h) ^ m. H4 x8 a; N( I! y. D9 a
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持: v- m6 T/ Q$ L
) ?; Q2 a' W+ [5 K W: U, q我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ S4 v6 n0 R1 b0 _+ N( }8 W }) L0 n+ X9 a# m% c
方便实用 简单 何乐而不用呢
2 l V# W* n. @: d- <?php
+ R# N; ~* P% J; H4 i' P c
# E: q- r5 S2 g5 a: q0 ]1 q- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ o% d% u, r: O. c - require_once( ABSPATH . 'wp-config.php' );
: k2 Y4 U0 l( r" U! @ - require_once( ABSPATH . 'wp-settings.php' );
& N4 ?& ~- k/ O5 F - require_once( ABSPATH . 'wp-includes/class-wp.php' );3 e% n2 l9 t& e/ J- M7 g
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 S# O& m9 ~# e; c - require_once( ABSPATH . 'wp-includes/plugin.php' );: g Q( v# w. T- Y' }
- $title = $_POST["title"];$ n0 R- ^$ e1 s k& i& X( x( T
- $content = $_POST["content"];# i- \6 I4 R: y# @7 e/ y- S) U
- $tags = explode("_",$_POST["tags"]);1 E! O' X z8 m* f& v6 K
- $cate = $_POST["cate"];0 @% ?, `0 ?( b" F9 u/ e
- //print_r $tags;
9 j/ Q& }8 k, K8 x0 z - //4 |) M, v0 c% A* ~ @
- //! ?0 s. D8 Q5 Y9 D1 g
- $wp = new WP();- ?/ B4 Q( p- M+ k+ o8 B9 a
- $wp->main();
( S& f L" g( Q1 y( T( Q8 E: c4 s - //9 C; y2 k" A U# Q
- $my_post = array();
. ^ i4 w. s2 q0 h, H2 w. @& K - $my_post['post_title'] = $title;
; d7 R( M: v. t V$ \, p' X - $my_post['post_content'] = $content;6 e `$ C: S3 p& E- |3 d
- $my_post['post_status'] = 'publish';# Q; m$ |) a1 Y* R6 K0 s
- $my_post['post_author'] = 1;
( x& |, r6 E: \) F! e3 E - $my_post['post_category'] = array($cate);
( D9 J7 h" ^/ G6 P$ Q - $my_post['tags_input'] = $tags;" A/ F; H9 s% K: d W
- //$my_post['tags_input'] = array('tag1', 'tag2');
h! H8 n( Z9 T5 S% E& z - //$my_post['post_status'] = 'future';" P8 M3 {# |2 V7 N5 Q$ z& W& T
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
( p! G1 S$ r6 b- K9 U7 G r
: w4 P7 e" X( w7 B/ B- // Insert the post into the database& \$ b9 o! W. E) O" ^
- $ret = wp_insert_post( $my_post );
3 q8 A1 f0 R2 H: t3 k1 Z( | - echo $ret;
" p9 o6 a6 r6 i, f$ ? - ?>
; {4 u! J5 U6 M- G
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- * G$ N- k9 W. ?7 E& [' M3 A' p) Z
- <?php- J+ D0 f. S/ g& J# {
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. ?9 X' @" }' y" A0 O. V/ K# p/ t - require_once( ABSPATH . 'wp-config.php' );. n0 x; s' U# F$ }8 I- A& R1 `! ~
- require_once( ABSPATH . 'wp-settings.php' );
6 P" A$ B$ t% {" U, v- C2 C - require_once( ABSPATH . 'wp-includes/class-wp.php' );
" ~ ^5 j1 V+ X# Z0 L B' S5 D$ X - require_once( ABSPATH . 'wp-includes/functions.php' );
' K% V& Q" E& J1 G5 r - require_once( ABSPATH . 'wp-includes/plugin.php' );
' L) V! _' N* b - $pic_name = $_POST["pic_name"];
; J: W, F; H7 R7 F* ` - $pic = $_POST["pic"];/ p* {8 n$ [2 B+ y" @1 m' t
- if($pic != "" && $pic_name != "")' F5 b1 E" X% m
- {$ N4 D* ?: k4 [% X/ m) \
- $path = "images/";6 ?, P# L6 D/ m5 R) G( u2 d I) h% I
- $pic_name = $path.$pic_name;
% {! n( c9 B2 b7 h" R - echo $pic_name;
6 u0 I1 Q0 N" P) p1 M- R0 ? - echo "||"; k# `$ G. @* l! v* ~) r/ e
- error_reporting(0);2 {- ?3 l, }8 C
- mkdir("images");
. B; S- v6 t( P) v4 q1 n' Y* m - $handle = fopen($pic_name, 'w');
K2 U+ x8 K, ?7 X m$ o: c - echo fwrite($handle,file_get_contents($pic));
9 L% {9 Z& K6 G; A8 [- z3 y - }
0 }3 O9 x0 q6 L7 O9 w+ k - 9 x; i: O* n& n9 L3 H/ P: ?3 y( W
- $title = $_POST["title"];
# r2 H' N8 M/ t( E$ C e" l - $content = $_POST["content"];: @- a/ {" Z9 {% m; t* J. z: H/ ^
- $tags = explode("_",$_POST["tags"]);
& }1 C( q+ ^7 W - $cate = $_POST["cate"];
; v4 m' k, Y6 L0 [' o% |$ ^8 s - //print_r $tags;* U8 r0 P: H7 Y% f
- //( t! m; d2 l. |7 g* f) ?+ `4 C
- //
/ n% ~! m6 o J' k. g P6 X - $wp = new WP();4 I* L& W+ f# ~: P8 l1 a
- $wp->main();
6 Y ^. [* t m( f' m$ D0 Q1 K - //& J: _$ x1 q# q7 X7 p# N' E* j' v
- $my_post = array();
% J$ c/ S5 k% ]4 d. p8 y, l - $my_post['post_title'] = $title;3 t$ O/ s- c; `
- $my_post['post_content'] = $content;5 l0 v6 o6 O- k) y3 W6 |7 o" ~+ f" I
- $my_post['post_status'] = 'publish';
* x# ^- g% P2 w9 o- r1 B# n - $my_post['post_author'] = 1;' A- u; L; J+ g8 |8 g& o5 G
- $my_post['post_category'] = array($cate);7 x+ ~* m+ Q! Z. \+ c2 j. A
- $my_post['tags_input'] = $tags;3 s, F9 l1 f$ t" b8 J! ]* z
- //$my_post['tags_input'] = array('tag1', 'tag2');- T% L& D( r9 O0 L2 Z' K
- //$my_post['post_status'] = 'future';- \: [1 ]; m$ a( A
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 b, ]: m0 e2 {6 P. C
% F8 W7 f: t% }, y: |- // Insert the post into the database
3 T" V9 q& F2 _& p T - $ret = wp_insert_post( $my_post );
" F; E; u& \ y3 K& w - echo $ret;& B2 ?6 G$ b7 O! Q# `$ F) x; c- @
- ?>
9 Y" ^# G1 X! R
复制代码 我自己写的
" ?3 e1 h0 e' i0 ?5 {" d1 X插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|