|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
3 d) ]9 m& u! t) B. J& t+ j: H7 M$ P* p
5 O! x! U: ?* } \, x' m. E. ^% n4 K( i直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) o( y6 k. _9 B" E+ b j+ C1 h" ?1 O" ]6 g+ ~9 ?* q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% h0 V) P0 A4 [9 i8 k( h9 }- S
8 D% s* D; A( z7 f5 B0 s% N% W方便实用 简单 何乐而不用呢
% c5 @1 X, C- t0 E/ Z% ~( y% E- <?php1 r/ A& h' A6 c9 Y: @
9 o+ h# l3 t9 D# G- define( 'ABSPATH', dirname(__FILE__) . '/' );
" U! f$ w. P" @0 B/ x& Q* _ - require_once( ABSPATH . 'wp-config.php' );- H! \9 P6 z. @& C# r9 m
- require_once( ABSPATH . 'wp-settings.php' );
8 h" m5 Y" o: @( J6 U D - require_once( ABSPATH . 'wp-includes/class-wp.php' );4 k+ v C/ j" X& P! C2 w
- require_once( ABSPATH . 'wp-includes/functions.php' );
# d3 T) O: ]0 B+ Q* w' z - require_once( ABSPATH . 'wp-includes/plugin.php' );
) B n) j, d. J6 J/ x; L - $title = $_POST["title"];4 b' i& ^9 M: y$ _* r
- $content = $_POST["content"];. E$ N" O- w: O( N' D9 p9 T, x. T, i
- $tags = explode("_",$_POST["tags"]);% M: h! t. l1 ~) i3 C
- $cate = $_POST["cate"];1 N3 o+ G9 n" `) p" W. Q4 j
- //print_r $tags;( a8 b& g: p# Y& W5 r2 V( |/ {9 h7 h
- //
- u/ C# Z* ]1 N; Z) M - //
' K+ T3 ^ N! M' V8 k7 Z - $wp = new WP();
3 L& G$ K0 v. Y, [( Y" w, \ - $wp->main();) R/ b& }0 R E2 N9 Q: |8 e" _
- //
4 [ j) e5 J8 u: l5 r( r! N - $my_post = array();9 m, ^9 N% i4 L. Q0 n$ j
- $my_post['post_title'] = $title;
) u+ N; V( H- c6 S( o* }" S( s - $my_post['post_content'] = $content;
' i- c2 U; t% _" G* ]" M - $my_post['post_status'] = 'publish';
8 w7 t7 B b# g7 q- W( F$ M" k# r/ U: j - $my_post['post_author'] = 1;
9 I! P) K v- e, X- z% r( D - $my_post['post_category'] = array($cate);
7 `0 R+ O4 C- H. Y: v" l, v* N+ ?' g - $my_post['tags_input'] = $tags;* }. Z% [& i) _# n: r9 b4 {/ S8 z
- //$my_post['tags_input'] = array('tag1', 'tag2');
u" Z/ ^8 R% [ - //$my_post['post_status'] = 'future';" W0 P9 z9 b& W1 J
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! w, m8 m6 |8 n n; U# i3 S
- 4 K: `% ^; G/ q7 I3 I
- // Insert the post into the database, Z; G! E! F6 T Q; z, V5 v
- $ret = wp_insert_post( $my_post );
) r# g; c9 ^9 w! X4 b1 A0 n - echo $ret;) d& _4 I3 ?" r* ?2 W, u2 b" K
- ?>3 U# R2 ?4 w6 A/ v3 R
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + c* _* M# ^! w& y% Q
- <?php& [8 v! F; L- F
- define( 'ABSPATH', dirname(__FILE__) . '/' );
+ x) ?+ ~$ ?' w9 p% M6 C8 u - require_once( ABSPATH . 'wp-config.php' );: f( Z5 ]0 C O! `6 @* s3 R: j6 |
- require_once( ABSPATH . 'wp-settings.php' );& t, Y3 O# ?, v/ O
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 I8 S1 s# x! H6 C- K
- require_once( ABSPATH . 'wp-includes/functions.php' );
! o5 x; `4 L3 Q9 f! E+ N, q( i; x& s - require_once( ABSPATH . 'wp-includes/plugin.php' );
% V8 e$ q4 y/ s5 ~ - $pic_name = $_POST["pic_name"];% A5 m( m8 c2 n$ G& ? ]0 k( D& x8 ^
- $pic = $_POST["pic"];
* t3 r' d3 V3 G' { - if($pic != "" && $pic_name != "")
% ?$ c) s) _* s4 {; R! Q - {0 E) d3 a4 A+ m8 r6 d0 C/ ^
- $path = "images/";4 M3 _8 S) m3 g- o0 C9 n/ F- `$ S; ]
- $pic_name = $path.$pic_name;
+ w! t K" l; ~$ K) ?% @1 F - echo $pic_name; m4 A! k/ F. O; ?3 y o/ ?
- echo "||";+ b6 t, h0 m3 C4 I/ G+ i
- error_reporting(0);
L' K u; {$ T" s4 i3 N ? - mkdir("images");# x0 m6 v0 J1 d: A% V
- $handle = fopen($pic_name, 'w');
+ M% B( n) v2 \: [ t - echo fwrite($handle,file_get_contents($pic));9 x; @2 n$ _, v9 n+ U+ [
- }
) G& H+ K3 u- {; F2 j - 5 v; |* @3 b x6 _! o
- $title = $_POST["title"];# J' F" d. K4 ^0 r" c" c0 ~
- $content = $_POST["content"];2 a' Z) o$ i$ U
- $tags = explode("_",$_POST["tags"]);
* F6 a$ q/ v+ p4 V* p! z5 U/ J - $cate = $_POST["cate"];
2 T- d7 G, `7 a8 s7 x - //print_r $tags;
" f. L+ m7 l2 w - //2 d* v: A: b3 R- A1 q
- //) e ^! F) c" D/ l4 B5 ] U
- $wp = new WP();# j0 E k1 n1 L3 H3 P, H
- $wp->main();7 _; B/ f# x+ b( g* _: M& o
- //
* P$ R9 \6 S. N - $my_post = array();
" K# Z: C( A8 |; a/ F* c - $my_post['post_title'] = $title;
' P8 R a$ }! c# u+ I( c$ E - $my_post['post_content'] = $content;
* y* S) H+ J- g! k( B - $my_post['post_status'] = 'publish';
7 O& A. K+ u% S/ I' O+ N - $my_post['post_author'] = 1;
4 x" Y' N9 W% }$ G - $my_post['post_category'] = array($cate);
5 w; l5 k5 [* r5 z; T* ]% L3 B - $my_post['tags_input'] = $tags;
: X. O" s `6 e$ ~- ~* h - //$my_post['tags_input'] = array('tag1', 'tag2');
9 d1 G; Q7 F }( T# o1 k7 i - //$my_post['post_status'] = 'future';
) x m: M: l+ R3 `" t7 M3 E - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ t' k! x6 P5 B d - 4 v( M# K8 @ c. k5 N& p
- // Insert the post into the database
. \% ^ ~& R g" G6 O4 d+ t - $ret = wp_insert_post( $my_post );+ i! m, H; h7 f6 v7 B
- echo $ret;7 G+ Y' e. g( c
- ?>$ B, c2 U% e+ J6 E
复制代码 我自己写的# E) i9 |+ }$ @5 O! F( G
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|