|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
$ s4 z G/ }* C! n1 V/ R- {: v
) Q0 ~' L4 M: U( }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
0 {# A. s* f/ u/ ?/ l+ K% f
. I; ?8 t" S- z: X% g) @我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 U7 C. d* R. u0 X& Z0 B
! Z1 {4 \" h, h ]' }. u* S3 A方便实用 简单 何乐而不用呢
: t3 Y; q) s/ Q% f. l9 \- <?php q) c) b$ M) B' k1 ]5 i: P, {8 \
4 p" K) b! A: z! @( A, s- define( 'ABSPATH', dirname(__FILE__) . '/' );+ z9 g3 R" s: b5 z2 y& Q
- require_once( ABSPATH . 'wp-config.php' );4 s9 R' Y, h9 ^0 t- x
- require_once( ABSPATH . 'wp-settings.php' );8 G: n1 k/ e) e4 n) X4 V) ?7 V4 k
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 m# y$ S9 x6 ~6 f: R% p2 H - require_once( ABSPATH . 'wp-includes/functions.php' );
" T2 ^; h6 V7 y. ~; h+ G5 N6 v - require_once( ABSPATH . 'wp-includes/plugin.php' );3 F4 e2 H$ p: g- f0 w( Z
- $title = $_POST["title"];, a7 |) S' `3 S5 Z/ [* u
- $content = $_POST["content"];* Q2 c: \+ E% l. T* f/ h5 W6 c) ?
- $tags = explode("_",$_POST["tags"]);, Z$ C6 m- x! P8 s2 s+ m! R
- $cate = $_POST["cate"];6 _8 z9 @7 @' a; i/ L9 |* m
- //print_r $tags;
! `9 Y* R5 E# [0 S; e5 w - //
9 a0 T B: G4 P: V) {5 { - //1 H) r2 h3 e% b
- $wp = new WP();
! ~0 l& H' ?4 _$ @2 C - $wp->main();
$ z4 b0 r9 y, ^5 ~- }* l u - //
' F2 i2 f) `& P2 L/ \& y: } - $my_post = array();- q$ {1 _1 Q$ D, V* u a& G
- $my_post['post_title'] = $title;* n$ x0 O1 d: |" u7 I8 O3 E0 T
- $my_post['post_content'] = $content;
6 ?) g9 i3 H. A! @! N% Q& ~& F' q - $my_post['post_status'] = 'publish';
( r( d5 I9 S7 l1 S - $my_post['post_author'] = 1;: y, C& M, d s: c2 G1 \
- $my_post['post_category'] = array($cate);7 n( N* D* F3 B4 N. n% `
- $my_post['tags_input'] = $tags;# e) a1 x# Z+ h( b! Y
- //$my_post['tags_input'] = array('tag1', 'tag2');
9 n6 V9 ~. F. }5 Y& S5 {$ l5 S: e - //$my_post['post_status'] = 'future';
$ d! L, U( \6 n+ B4 t, F - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 ]$ O0 k" v" ~+ F5 K- }
- ( Q- O5 w6 q/ M9 I( S+ P6 ^
- // Insert the post into the database
' _6 g: @4 f f: r s$ Y) C, m - $ret = wp_insert_post( $my_post );) @6 C5 u8 z; o# `1 `. a
- echo $ret;9 l. ^. @, f2 j$ W; c- m; ]5 N/ y
- ?>, m2 K+ z& M3 c5 E2 B
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + l4 X" {& g) L; Y q- x
- <?php7 S; V5 N# A+ v& R3 w" g' |# k, U: o, Y" b
- define( 'ABSPATH', dirname(__FILE__) . '/' );
) Q" K8 V, ]7 s - require_once( ABSPATH . 'wp-config.php' );- G% A+ h! u* S" \; G
- require_once( ABSPATH . 'wp-settings.php' );! d5 W: ]# G5 q/ a6 e
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 m- r5 C( h. c, X( g( `' f5 E - require_once( ABSPATH . 'wp-includes/functions.php' );
/ K; t$ A1 R. g; M9 p - require_once( ABSPATH . 'wp-includes/plugin.php' );
9 a- f5 Y; } F5 S5 D - $pic_name = $_POST["pic_name"];
3 R- T% J+ C% b$ i. Z4 B* f# p% v - $pic = $_POST["pic"];
" g! e5 e3 H. M - if($pic != "" && $pic_name != "")
) g, o1 z' T4 z5 y - {* X5 }1 k# D0 a
- $path = "images/";
, e1 t' J @; @* | - $pic_name = $path.$pic_name;4 e2 P0 o" a9 C- O r. `9 m1 [
- echo $pic_name;" U( F8 l9 d2 [: O; l* c
- echo "||";" L; ]! C9 k$ `5 a6 q$ W# M
- error_reporting(0);2 C/ R1 x! y9 k2 M
- mkdir("images");
. s K o& m0 i; |/ x, Y9 ] - $handle = fopen($pic_name, 'w');9 x3 @5 q2 W; h/ g
- echo fwrite($handle,file_get_contents($pic));
- ~3 i% L. c" a. q* n; e - }
. f7 J- j( U- q0 k) U/ D - ' l9 \9 j: [: T3 a! I; J0 q
- $title = $_POST["title"];
# s( M7 l' _9 U; X+ g - $content = $_POST["content"];( V" q- _4 [ I. o" D: D
- $tags = explode("_",$_POST["tags"]);
! M7 J' a1 F# |( i1 V/ y - $cate = $_POST["cate"];
/ I# _# p+ x3 K( X3 H - //print_r $tags;
8 _0 S, [2 G4 F n3 R - //
% `. b. |4 {, I4 Z. F - //; ^' p2 z- r) d0 R K$ N* G
- $wp = new WP();6 l* p, P; E$ W: d, i
- $wp->main();0 j+ J/ _" [$ Q. y* V2 x) s
- //6 T1 m4 S8 h; y- w$ C0 X
- $my_post = array();4 E7 A9 r% Q3 ~# r! T
- $my_post['post_title'] = $title;
6 b7 W1 F+ ~9 V4 q - $my_post['post_content'] = $content;1 H' k2 C+ |9 J! l7 ?" Z
- $my_post['post_status'] = 'publish';
+ ` J- a9 ^- S( ~1 r& A - $my_post['post_author'] = 1;- ^ Z1 C, _7 n* _
- $my_post['post_category'] = array($cate);1 b( v) \, A0 [1 q B/ S- k
- $my_post['tags_input'] = $tags;8 l3 `1 Q8 D T
- //$my_post['tags_input'] = array('tag1', 'tag2');- S2 ?1 Z) M! X: o
- //$my_post['post_status'] = 'future';
7 d: L6 I2 k9 \: V( r( x0 I - ////$my_post['post_date'] = '2010-07-04 16:20:03';( A6 [8 c6 P; ~2 j {, R3 S
0 P6 o4 K* G2 t& h- o- // Insert the post into the database& Q( O6 D) ~. \* I. J8 B+ V
- $ret = wp_insert_post( $my_post );! a' ?( Q, E" e
- echo $ret;9 d$ K3 g. t& C; l
- ?>
5 `7 D* }' V @% J& z' J/ K
复制代码 我自己写的
* z4 L9 W* l' k `& i& I: j. V插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|