|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; a- ?9 d( S- s1 M
6 w/ R: F1 M2 d: b9 U7 p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
; k u5 u, ?0 w! @
* p( S8 h1 R! g* U! ^我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了" y0 J5 A* o7 Z3 c, x' H# C7 C
$ A4 w# I( o0 |
方便实用 简单 何乐而不用呢- , h, D. z! `9 d x9 x
- <?php/ t% H) ?. u& @# \) K
- ' g4 ?4 ^6 G* Y$ H) q9 j/ R* |. t9 v
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 G4 G2 G) }) Q1 r2 B8 J
- require_once( ABSPATH . 'wp-config.php' );
6 I7 o8 |) d$ k c1 Z - require_once( ABSPATH . 'wp-settings.php' );
8 _- b/ o# W6 J - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. L2 k3 i6 v8 \- Y6 k - require_once( ABSPATH . 'wp-includes/functions.php' );
- t1 T+ K A+ h) q$ b t5 H( X - require_once( ABSPATH . 'wp-includes/plugin.php' );
- O: l: }3 Z( D% W' V - $title = $_POST["title"];
" P7 f* N: D. Z6 a - $content = $_POST["content"];
, _5 n- {2 W* W0 U( x$ n. U - $tags = explode("_",$_POST["tags"]);
/ J8 T$ }0 q0 L/ y! ` - $cate = $_POST["cate"];
4 Y6 T0 G" ]3 |: e2 J" t - //print_r $tags;, j) u, i" i, k; l6 T4 z/ i, [
- //
4 e; i, O P, \- I - //) |- }% l0 ^ I' a4 |
- $wp = new WP();# J' F& r, }4 t& M7 A( s4 y
- $wp->main();
6 o: p* h6 {4 c - //7 Q' k, ?. r6 M+ H. v
- $my_post = array();
! n5 G# ]8 v5 G& O0 A7 z9 e5 V5 y - $my_post['post_title'] = $title;$ n# ^( a; V" W3 @ }1 j
- $my_post['post_content'] = $content;1 B' A {6 f& i* l% J2 A! W0 e
- $my_post['post_status'] = 'publish';4 R2 U( ], F/ j
- $my_post['post_author'] = 1;6 l% i& J8 o) A9 n4 g9 Z; N, Y4 _
- $my_post['post_category'] = array($cate);
: P* b6 w, T, e# E" P3 O - $my_post['tags_input'] = $tags;' V1 F1 {2 P/ h6 z& l
- //$my_post['tags_input'] = array('tag1', 'tag2');& x9 i7 t& Q+ h& M! F9 a
- //$my_post['post_status'] = 'future';
( G5 i3 B3 v/ H1 m, O* R* |# w7 S - ////$my_post['post_date'] = '2010-07-04 16:20:03';
# |4 F- G4 \" ?( P1 d( [5 D
5 X4 i; r2 l0 k7 N1 h- // Insert the post into the database1 x$ r: I: Y1 h% y. _; ~1 y
- $ret = wp_insert_post( $my_post );, u. A0 B7 \4 W5 n$ }' i9 ~" ^( T
- echo $ret;
; V0 v+ Y# M! ] V. _; k7 K s - ?>' Q) l" M r& Z! A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 0 O. M# b& V& A# S+ P6 T- }
- <?php! z- B% w; i/ z$ G
- define( 'ABSPATH', dirname(__FILE__) . '/' );- v. R$ ]* p& n Z+ t( m! `. N' Y3 |
- require_once( ABSPATH . 'wp-config.php' );
8 Z9 y8 R% Z6 W3 @2 V - require_once( ABSPATH . 'wp-settings.php' );
4 }2 e5 s T; ]/ W - require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 p# a% ]' \( S- \8 `6 S# e - require_once( ABSPATH . 'wp-includes/functions.php' );6 h( H1 }5 h- F1 G3 y4 J* K
- require_once( ABSPATH . 'wp-includes/plugin.php' );
( ^' q+ R' p; l7 b6 {' R5 B - $pic_name = $_POST["pic_name"];4 ]. [$ T+ f9 [- F) \2 I9 y
- $pic = $_POST["pic"];
~' F4 I) T; ~5 t @9 | - if($pic != "" && $pic_name != "")
& f) x9 G$ O: f$ [7 d- Y - {
1 C, r) Q) |( O4 U) z( S2 b - $path = "images/";
% n1 t& E2 g; r; N4 c' f2 x8 B2 D" { - $pic_name = $path.$pic_name;
h! Z& c; T* x3 ^, R6 f - echo $pic_name;
8 p, }* b: f5 g, H2 L7 K8 x, V - echo "||";
& X$ p0 O2 I6 |( k' O - error_reporting(0);
6 E6 ?* l/ L( A8 _, b9 ^8 C - mkdir("images");
0 \+ Y& R$ H/ ~9 P0 A1 s - $handle = fopen($pic_name, 'w');
6 C: V! U" I# F4 [3 a1 b0 \/ [ - echo fwrite($handle,file_get_contents($pic));- A" v9 V5 [: E" t# v$ n$ O
- }
O9 V8 Y, f$ W8 O
0 |4 }2 J3 r6 C' k* o1 R! r' G3 n7 g- $title = $_POST["title"];
9 G& a3 H8 G# Q, f. Z - $content = $_POST["content"];
3 u! x- k+ p v# q - $tags = explode("_",$_POST["tags"]);
" V7 y* f+ s+ D! [, Q - $cate = $_POST["cate"]; n9 a8 ~ ~, f3 E# k
- //print_r $tags;
7 N7 x# O1 ^ h G( T7 k( f - //
% U+ m8 x E, I - //
8 k; C9 W. ]6 G9 K, f8 m - $wp = new WP();# `/ C! I; t9 Q! Z
- $wp->main();+ L6 n" s- m4 [
- //) W4 P/ E1 c" U8 \
- $my_post = array();6 }1 B! E0 ~$ g" ?, b( W; V. H$ s, p$ v# j
- $my_post['post_title'] = $title;
* h W5 r. Z" q - $my_post['post_content'] = $content;
; m! l- e# v* |1 K' H - $my_post['post_status'] = 'publish';" M# u5 o* ?; ~3 y" O
- $my_post['post_author'] = 1;6 j0 u3 U/ ?/ t, C
- $my_post['post_category'] = array($cate);
+ \) A4 j6 o; Y - $my_post['tags_input'] = $tags;
- E4 J Y+ s. n7 a - //$my_post['tags_input'] = array('tag1', 'tag2');& Q- [& y% b0 i3 U7 f0 F
- //$my_post['post_status'] = 'future';# i* C( F4 [3 D* ?9 M8 ^, A
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ ^* H5 U% O/ l- r J: R) b - ( @9 r8 K8 f7 j" q
- // Insert the post into the database
) m7 n# j2 s, R! k" d" I* a$ p - $ret = wp_insert_post( $my_post );( v) f A* q# D! ~7 y7 f6 b6 N" B
- echo $ret;
5 R- ? W# v- r. A) D' g; { - ?>% K6 L! F( U( l' N& [
复制代码 我自己写的
' Q. v) }2 Y3 B& G# p插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|