|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
% j4 g8 I. e! U% ?( L" z( q& `6 q4 \7 V# i c, j/ ^
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
# @) j* ], j. w; ]8 [- z3 i6 L! @
6 _0 a9 [: E1 x! |3 j3 k( l5 k我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
8 L7 H6 ~) ^& a u$ C
7 V7 z" }0 |% `% [: R9 V方便实用 简单 何乐而不用呢
8 a v8 Z9 F- p" j- h/ H0 ^0 K- <?php
( B/ S/ y9 i2 r, w9 I0 s( p5 H
$ i0 N% g) u- y- define( 'ABSPATH', dirname(__FILE__) . '/' );& U& X+ b8 H5 G+ I! [( D$ @
- require_once( ABSPATH . 'wp-config.php' );
5 [8 K, @* k, k - require_once( ABSPATH . 'wp-settings.php' );" \) O) x: p5 w4 `' E ?& L2 K
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 Z( o4 Z& c- ~ - require_once( ABSPATH . 'wp-includes/functions.php' );
V( K+ a4 {9 _ - require_once( ABSPATH . 'wp-includes/plugin.php' );4 `2 a4 @+ R4 N6 c
- $title = $_POST["title"];2 Y6 ?8 G' b. L% d" i
- $content = $_POST["content"];
9 ?- x$ W0 q/ u- c, H, w: j - $tags = explode("_",$_POST["tags"]);
/ A+ n1 t& ^ g' V# A2 a* S7 x# \( a - $cate = $_POST["cate"];" X' \, w9 Y' m8 b; i8 s3 } f
- //print_r $tags;
+ d; v+ e! B5 f/ d5 \, p - //
: {. I, t h9 Q8 M: B - //6 r5 c7 Z. [; f7 _1 d2 m
- $wp = new WP();/ x9 b3 X8 H5 C" @, W! y- i
- $wp->main();: w5 R% r% w8 N) M8 S7 h, f6 \- m
- //
8 E$ V9 J5 ~: s, r: |# l( `. k - $my_post = array();2 y0 n8 _! J8 a, m* W' |$ B+ z; t
- $my_post['post_title'] = $title;
! { a4 J" }# F# \7 v( P, x# G - $my_post['post_content'] = $content;
3 C; _# W' L# O0 \2 q; f - $my_post['post_status'] = 'publish';! y7 u1 C# _( r: y" ^# W6 I) z
- $my_post['post_author'] = 1;
. x+ J" }7 W8 c' c4 L - $my_post['post_category'] = array($cate);
* N) F) V9 P. R8 M3 T7 n* Q! H - $my_post['tags_input'] = $tags;
2 ~+ O. H) E3 Q- ]! g3 n2 N* U - //$my_post['tags_input'] = array('tag1', 'tag2');
9 I# P! M6 r Q3 [0 f - //$my_post['post_status'] = 'future';
0 N& `5 l$ q' c - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 c0 _- @' B* j% s
0 u# H) t! ^0 o. z& \1 r. Z( \, y- // Insert the post into the database; r/ j/ P7 Y! J9 W! k0 W5 w
- $ret = wp_insert_post( $my_post );
; e0 g1 O& O4 q2 g& R% N - echo $ret;
2 x9 P6 W5 @! p$ T- ~ - ?>
% a. \# T( v$ u9 h+ S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & q& Z4 K7 r3 C' c5 I5 D
- <?php
# I7 S. h; q& [8 _- q0 p1 P- T - define( 'ABSPATH', dirname(__FILE__) . '/' );
5 F2 k5 ]# J0 ?% S2 X - require_once( ABSPATH . 'wp-config.php' );! h, q/ J4 K% f/ f9 j
- require_once( ABSPATH . 'wp-settings.php' );
9 l- h2 `9 \) `% `: G+ f' A( W - require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 Y4 O" k: R1 m - require_once( ABSPATH . 'wp-includes/functions.php' );) I: _" z# r+ b1 g* x$ s8 @' u4 Z
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ B3 E2 U6 i& V3 x5 J' I# H
- $pic_name = $_POST["pic_name"];
( @3 B1 t _9 \+ [) u: z( w0 g - $pic = $_POST["pic"];9 U+ i8 z+ z! p, Y
- if($pic != "" && $pic_name != "")
- l9 X' F+ x9 @+ g7 \( R5 o0 z Q - {
6 t& K* f! e H. s - $path = "images/";& Z0 R3 i x; k& M1 H
- $pic_name = $path.$pic_name;* s) X2 S* g6 z" M J
- echo $pic_name;
! @6 w! o8 U+ o- Z. \1 c2 e. `# T: h - echo "||";
, m9 `9 C9 e+ \4 Z4 \, t3 V - error_reporting(0);
; }0 T/ Z/ q* s( I- F( @ - mkdir("images");! s2 ^# \8 b$ J3 a ^7 I1 t% H
- $handle = fopen($pic_name, 'w');4 Z- ^7 A& j' x3 L
- echo fwrite($handle,file_get_contents($pic));3 B/ R2 D& \: J# W( W0 w4 Y9 l0 y3 c
- }
+ q0 P. D- @+ o& ]3 ^9 j - - y) X. h& O" v! ]7 X. C# `8 B+ e
- $title = $_POST["title"];" X4 }$ H/ s( L, S
- $content = $_POST["content"];
# Y L/ `; B' L! I - $tags = explode("_",$_POST["tags"]);
! f5 k( G8 S) K) L - $cate = $_POST["cate"];
7 S: d$ r; W: F! L3 l/ T/ ?. u6 ~# A - //print_r $tags;+ d W# h$ u7 ?+ x
- //
4 d4 \# y8 u' x6 D6 @; u; _/ ` - //
0 Z9 ?. `# l" [& L0 s6 ~ - $wp = new WP();9 S- d' \9 ^* G( Q7 ?8 y/ e
- $wp->main();
3 i y. x3 u3 Y7 l M - //
9 F( o3 u. R' s5 e8 p5 S - $my_post = array();8 ?" m+ U/ j% Y) z- W! S% O
- $my_post['post_title'] = $title;
_2 t! A$ `1 X. u9 M5 ^( J - $my_post['post_content'] = $content;7 s0 k6 D7 B! ]- s/ u$ F ?
- $my_post['post_status'] = 'publish';- d; J$ o- \0 \* q3 W( d
- $my_post['post_author'] = 1;
# e+ d( b/ r: q2 Q0 R5 Q - $my_post['post_category'] = array($cate);( p1 d$ n4 U( h
- $my_post['tags_input'] = $tags;3 @& ~6 p0 [0 S8 ^; H4 x
- //$my_post['tags_input'] = array('tag1', 'tag2');
: Y$ s, q" ]6 z( M( R - //$my_post['post_status'] = 'future';) H6 E& o: q* O1 f! S- j
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
; O a2 I6 P5 @' R& E
) ^9 r5 g( l% a( z6 @1 }; _- // Insert the post into the database
7 L& x4 c& r( j" Z) d - $ret = wp_insert_post( $my_post );
# t% O7 {/ q. g$ d - echo $ret;
$ r6 D, }5 E5 V) U& T* z2 M, ] - ?># ?9 n' @! }. e. y7 V {+ g
复制代码 我自己写的
w5 t: C) Q8 ?0 ?5 ]0 f插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|