|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 # A E; y1 N @6 s
. V! ~ o& W8 T/ m
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
2 J& i: @* ^! o0 a, n% @5 v5 B4 s: l7 S+ u6 @ |7 B+ y/ _
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, o3 W* Y' w! }3 S' T* l
! T `/ [ K2 b5 W
方便实用 简单 何乐而不用呢
6 c; o% h* e. H( C1 B- <?php
% Q/ ]4 g8 c, g8 c$ O1 K2 x' v% L - , t7 J. j5 A# z3 Z. ~) h, k
- define( 'ABSPATH', dirname(__FILE__) . '/' );- E7 q& A1 T- ] d+ Y2 }
- require_once( ABSPATH . 'wp-config.php' );' H! G4 S* D- _3 V) Z) {
- require_once( ABSPATH . 'wp-settings.php' );/ d3 O( `* t' v. N* u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );% s9 Z6 v- `, }
- require_once( ABSPATH . 'wp-includes/functions.php' );
* d" a$ r) X T' H% Y2 A - require_once( ABSPATH . 'wp-includes/plugin.php' );
4 x t+ N5 N$ n9 f7 q: i - $title = $_POST["title"];
1 H4 F( B0 _6 ~7 o" |1 s1 Q - $content = $_POST["content"];6 X" z. ~2 o0 ?: d5 e% i5 z
- $tags = explode("_",$_POST["tags"]);
$ d1 v; A+ { E7 ~1 Q5 U( o - $cate = $_POST["cate"];
, u, G# G* K; Z4 D3 F! G% R0 B - //print_r $tags;
+ \0 c5 {4 b* v' v2 X8 I) f - //0 I% `3 m5 H. |; t5 t% a
- //# p5 L5 f$ m) [7 E
- $wp = new WP();
! {& ]( R: K& E) F - $wp->main(); d* A8 g- @5 }6 ^. n. o
- //
1 U* F! i/ G5 Z; X) P1 z - $my_post = array();8 A4 Q8 n; M8 ?0 ^& }
- $my_post['post_title'] = $title;
8 T) _' x. h3 B2 R1 `0 A" ?, a - $my_post['post_content'] = $content;0 k$ a5 @$ ^$ w& O7 o7 L
- $my_post['post_status'] = 'publish';/ O- o2 G4 [/ U% \$ i
- $my_post['post_author'] = 1;
' v% Z6 Q/ N$ S - $my_post['post_category'] = array($cate);- t, z& p1 s. B" R4 @5 f$ n! p+ Z
- $my_post['tags_input'] = $tags;: P+ f w* N& u) ]3 E
- //$my_post['tags_input'] = array('tag1', 'tag2');, b0 H4 W' E r! z( t
- //$my_post['post_status'] = 'future';
& X- H0 ]! }' r: t - ////$my_post['post_date'] = '2010-07-04 16:20:03';
- y- I8 e6 V% l1 v
& L/ P2 ~# d L( \- N- // Insert the post into the database
9 O: b5 }9 e6 U - $ret = wp_insert_post( $my_post );: i' y8 J/ n9 r
- echo $ret;
' k7 \% `' x2 E - ?>% d; v! q) ?5 g( a6 F. f3 Q, H
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- : K w2 ~% w# ]( Y/ Z1 E/ J& E6 ^
- <?php* |0 c/ R' a. H) m8 Z( [5 Z. {
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 Q h3 B# k4 P0 x
- require_once( ABSPATH . 'wp-config.php' );
. s% D2 G( S; D# y6 m - require_once( ABSPATH . 'wp-settings.php' );3 H; U5 R! Y( ~
- require_once( ABSPATH . 'wp-includes/class-wp.php' );2 J" s8 b! [# }
- require_once( ABSPATH . 'wp-includes/functions.php' );3 P' B6 L% J* w! }2 s& j
- require_once( ABSPATH . 'wp-includes/plugin.php' );! v' P T9 F) ~
- $pic_name = $_POST["pic_name"];
2 U% F4 J! x1 T; f* q - $pic = $_POST["pic"];' ^& B+ W# E9 ~. G
- if($pic != "" && $pic_name != "")
( S5 C: x9 P2 Q. F - {3 N+ U& J* q) Y( P; B4 {9 r) B- j
- $path = "images/";5 W4 {5 E5 ~( e; m8 J9 ^
- $pic_name = $path.$pic_name;& ?" @5 s8 F3 I- A2 g6 C
- echo $pic_name;6 [" v4 w* l: O
- echo "||";
" H K" p/ M% G( }- w( G& W( Z, T5 ` - error_reporting(0);
2 {4 l' k4 L* ?% a# p5 } - mkdir("images");
- B. r( @) n' i% L p - $handle = fopen($pic_name, 'w');7 i% R) P( S7 v( x0 V0 a; p
- echo fwrite($handle,file_get_contents($pic)); _9 c% `6 ^. ^' n
- }! T' E* W; A# D( Y U) b5 Y( N
" p, c5 k( i1 T; z# c- $title = $_POST["title"];$ H7 o0 D- m# }( n* l
- $content = $_POST["content"];
5 F) X, S: @7 ]4 i' u - $tags = explode("_",$_POST["tags"]);
9 ~" W3 H u! s G$ c" U - $cate = $_POST["cate"];, w* P1 m u7 r. O$ E
- //print_r $tags;( S; p4 f+ U* H3 @ D
- //
7 n! r1 ~; Z K5 |+ N6 } - //: a2 T0 E" N6 L. f9 W9 S
- $wp = new WP();; Z1 N; ]; x, ]( C- I' G/ _' X
- $wp->main();5 z6 \0 D+ P p& G
- //, f: h4 e- d9 i9 N0 g4 L
- $my_post = array();: s1 m+ E' n, t% P2 @, M. v
- $my_post['post_title'] = $title;
3 C9 S9 \, a- c - $my_post['post_content'] = $content;: s- O ?2 q' [/ J7 ]/ |
- $my_post['post_status'] = 'publish';
( K4 w' c7 e1 b( p - $my_post['post_author'] = 1;, k' b y8 Q* c
- $my_post['post_category'] = array($cate);" r# M0 g& @+ t2 z
- $my_post['tags_input'] = $tags;3 b$ ?% m' f+ ]0 E! O' g) R7 |
- //$my_post['tags_input'] = array('tag1', 'tag2');5 |) X/ w9 z0 W/ S) ]$ v
- //$my_post['post_status'] = 'future';8 o4 J# h9 M0 {: u" z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 ?/ A( s7 Y$ Q4 q5 y
- * r& t* P6 y9 t
- // Insert the post into the database
y( F6 G/ n2 y# x - $ret = wp_insert_post( $my_post );. J: _8 ]+ @' `/ c) ^' P3 j
- echo $ret;. _1 _' @# @) C& u2 r2 L/ m
- ?>. E. u* ]# f& V, @9 V# C. [
复制代码 我自己写的
+ ~4 J" L' f. m' X: N5 d$ z插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|