|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & j: |5 o% {- C( _) B! Y
2 E) k. X; B: _" |- p) x) t* x9 F直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持' D8 u: ^9 y3 Z4 Y3 J# e
7 u. _/ V5 z0 @, U1 ^5 E" `) ~# b我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
" T/ D! \! H/ @) Q# i. a3 ^* F* [' W0 B1 p y
方便实用 简单 何乐而不用呢
$ s, L# n1 m9 u- <?php
5 V5 E! d& |5 ?/ c x - ; p K; R% Q. x2 C+ b5 y' z( S
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& I! n' g. v0 k8 J! A5 R- Z o% u - require_once( ABSPATH . 'wp-config.php' );" F5 S8 B% _1 i: z+ u& b3 N7 y
- require_once( ABSPATH . 'wp-settings.php' );7 b+ l" w _7 E/ a
- require_once( ABSPATH . 'wp-includes/class-wp.php' );( Q9 G: @3 \: H5 T7 ?5 h. ~# A" q, M: O
- require_once( ABSPATH . 'wp-includes/functions.php' );
* b" R! l0 S9 F0 f% o, f9 j - require_once( ABSPATH . 'wp-includes/plugin.php' );
1 Y5 j, {3 M: g: N0 D - $title = $_POST["title"];' Q/ _$ H) `* N$ G
- $content = $_POST["content"];1 t; T/ O7 O* n
- $tags = explode("_",$_POST["tags"]);
' r+ b; w1 _% K; a3 ^* K - $cate = $_POST["cate"];$ d7 J4 x9 h/ ?# X |( ~7 P0 O; I
- //print_r $tags;
7 X/ @( w: h- v( x O. } - //: i/ V0 e5 B6 Y ~) C2 k% _6 f
- //
9 \( M1 l/ b: M& T5 a - $wp = new WP();
4 R \: \# j0 o1 i2 U8 I - $wp->main();
# i3 \$ u c4 R$ x L/ O% b( a - //
; v$ V$ t! Y! w - $my_post = array();5 d. b/ e' S# k) {6 h
- $my_post['post_title'] = $title;7 I# }8 A# I x* f
- $my_post['post_content'] = $content;" [0 k/ c" x/ S6 V: x. P2 [
- $my_post['post_status'] = 'publish';
. h6 d" ^% s: U+ m* }9 [1 T$ z - $my_post['post_author'] = 1;& H& b. J- o8 s5 p: \
- $my_post['post_category'] = array($cate);5 g; K# ~; V0 u f8 n
- $my_post['tags_input'] = $tags;
! l2 |8 z' @- p% O9 Z" b* U - //$my_post['tags_input'] = array('tag1', 'tag2');& M! \0 O& J/ u% b
- //$my_post['post_status'] = 'future';
1 o, U# M y) y( F - ////$my_post['post_date'] = '2010-07-04 16:20:03';5 f8 g# J4 J C }8 w8 d9 Z8 F
U0 ~; e* w3 a. Y+ Q& ~- // Insert the post into the database. g, M) p6 _% y4 ^
- $ret = wp_insert_post( $my_post );) J# Q. E! E. f: N7 _2 M
- echo $ret;+ y* x+ D2 }6 M9 u* p
- ?>
9 G* n! M5 L$ D" p `
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 f3 i% }0 g3 ]) Z: x- <?php
" }4 E, Y. W, h8 u/ j - define( 'ABSPATH', dirname(__FILE__) . '/' );
# ^7 a- A: K5 x( q [ - require_once( ABSPATH . 'wp-config.php' );( V/ P6 j5 k! O8 @* W
- require_once( ABSPATH . 'wp-settings.php' );
% q ]* c$ B. |# n- E6 X - require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 S' l2 h$ C b- |; i - require_once( ABSPATH . 'wp-includes/functions.php' );
2 F: ~% A4 h+ g - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 m- }" C4 {: _1 o5 I0 [ - $pic_name = $_POST["pic_name"];, q6 a# A1 Q, M9 C3 _& _ W5 ?
- $pic = $_POST["pic"];! J2 \+ o* ^7 N( n3 }) V
- if($pic != "" && $pic_name != "")
( p7 u9 q, Y: A8 z3 z# n5 z - {9 O) r9 Q$ ~+ G' y @( r8 j
- $path = "images/";, Z. J% @) Z$ z o2 H
- $pic_name = $path.$pic_name;
& e h: E, E( n! w: V! Z2 u - echo $pic_name;2 J% x* M+ _. }9 X3 @0 P0 f( X
- echo "||";7 }$ l) [5 q+ g- ~. \5 m
- error_reporting(0);
$ |* m2 V$ W$ f6 g1 d - mkdir("images");
/ Q5 R% }# K3 N5 L! W - $handle = fopen($pic_name, 'w');
' g# c. Z a+ T# o# A - echo fwrite($handle,file_get_contents($pic));" y+ K/ m0 f9 {6 {( G" |" o1 |
- }
7 f& ?! e* V; G: I# L4 n6 A9 o7 X
; d7 f! g( h8 P# \: U/ a) m/ i5 P' P- $title = $_POST["title"];
{0 x) Z) D# @9 A( c& Y- X& M - $content = $_POST["content"];
9 g: l, F( w/ g% \8 L/ B - $tags = explode("_",$_POST["tags"]);
; W3 a( @! o" E/ g' h9 z% Q - $cate = $_POST["cate"];- U% k! ^5 E5 q7 D
- //print_r $tags;
2 `* _& M7 L$ R( ^ - //
% Y' |, I& J4 H% l( q* E7 ? - //3 s( i* _! F7 C; H
- $wp = new WP();3 g( Y) e7 s2 ^1 c
- $wp->main();, I5 l" k3 p7 D7 O- Z
- //
# O( O' x% V* ?( A# m% B0 w4 a - $my_post = array();; i w& v; @% \" A) z4 v
- $my_post['post_title'] = $title;
; ]% p7 p' U% k - $my_post['post_content'] = $content;- L7 @0 e% M, q/ n" s" o9 ?) s) x
- $my_post['post_status'] = 'publish';
' g3 ^3 I% J. a9 [2 v5 K - $my_post['post_author'] = 1;
: n* l! u4 n3 b' P" o# n5 O - $my_post['post_category'] = array($cate);
% C- g+ w. J! S4 `; C: u. e - $my_post['tags_input'] = $tags;% m1 ]0 I% y* w! E" V0 t, a. h2 \" ~
- //$my_post['tags_input'] = array('tag1', 'tag2');
2 z5 m# ]# L' @5 C1 l3 e& L - //$my_post['post_status'] = 'future';
! C* o4 J7 |4 g5 I O3 s$ Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 y, G# T" A% w' X
+ H+ g4 \ M6 \8 P- // Insert the post into the database- N$ ]0 R) W2 W0 T# C
- $ret = wp_insert_post( $my_post );0 y2 B4 ^! T, U( h/ l3 p6 c, C
- echo $ret;
4 c) F: K$ X1 x% ^* ` - ?>
+ B! w1 e; l1 Z5 j E) Y
复制代码 我自己写的
' G; I* J! ?. N; j8 c插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|