|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ) V" D& H4 z7 W, J
/ y6 A6 g7 ]- l) ^! K7 g& \直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ i2 ^& E3 F2 } D O0 c: ~! v( U/ t* \" \- @' M( D! Y8 H
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了2 `1 n5 U' L0 k7 x6 Y
. f: [+ B% s+ R# X5 h
方便实用 简单 何乐而不用呢
; \& u: G- F* t6 @- <?php5 U2 N, K6 b5 \* k, A, P( M
; i5 A$ N) l- ~5 P1 @- define( 'ABSPATH', dirname(__FILE__) . '/' );
) Q' T, X" I0 }; L3 | - require_once( ABSPATH . 'wp-config.php' );
+ {3 S, M% G0 @! |6 J) i/ [ - require_once( ABSPATH . 'wp-settings.php' );! v0 S U) B( C& `
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 b4 w2 n' v0 e8 y. ~* L - require_once( ABSPATH . 'wp-includes/functions.php' );
& |1 s! @# l) r& {. c. _ - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 C0 Y8 Z" x9 j0 _2 f# j - $title = $_POST["title"];# x3 ?' r$ m9 _& y
- $content = $_POST["content"];/ B2 e. C- ?- F, n
- $tags = explode("_",$_POST["tags"]);& @! X) v& M; ?" L2 _4 R% T
- $cate = $_POST["cate"];: ? y4 E% B5 g- [! A& r
- //print_r $tags;
! N) g; S$ M6 O( ~ - //
3 g4 K3 _3 r! j - //% q; S2 ]1 r- E5 O
- $wp = new WP(); ?9 \" b& C% H
- $wp->main();0 S2 m- h9 M( b( w, [) K
- //7 L* x# T8 g4 k( b
- $my_post = array();
% D2 l5 B. M+ S8 j2 [' c - $my_post['post_title'] = $title;4 o! c+ i F% D, ^& k( D
- $my_post['post_content'] = $content;7 R3 Y4 m& Y* R3 i" ^6 u
- $my_post['post_status'] = 'publish';* x! i4 l, \ f0 x Q4 S; Q
- $my_post['post_author'] = 1;
; Q9 Y A7 ]8 X1 x! k - $my_post['post_category'] = array($cate);; J! c: V2 |4 c
- $my_post['tags_input'] = $tags;
5 I, ~% T4 M# ?: k - //$my_post['tags_input'] = array('tag1', 'tag2');1 h3 E+ l+ n& i4 |/ E
- //$my_post['post_status'] = 'future';( C) g0 d) j# y U6 F- E+ }
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 y( Q/ `7 \# j0 u( K6 A - & ?: Q- g+ y6 k" u; X; j) |
- // Insert the post into the database2 g2 O) \, o! m8 e1 A: \
- $ret = wp_insert_post( $my_post );0 O$ \# ]# _4 |7 }" Z
- echo $ret;
( g0 E' s$ U6 ]9 ]# c! o# ] - ?>% _5 W* r7 o0 q2 K8 p1 R& r, Z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
) c6 ]+ x8 \2 m9 ]5 O2 @( g3 i- <?php/ Q1 x! \5 J. y3 K0 d6 u2 m
- define( 'ABSPATH', dirname(__FILE__) . '/' );( \+ ^5 S1 n! c5 ?
- require_once( ABSPATH . 'wp-config.php' );
: V6 \7 r2 r: ^% L - require_once( ABSPATH . 'wp-settings.php' );* y/ n% ~; M/ _( u4 [+ e
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- G) z1 i! H% }6 `- g
- require_once( ABSPATH . 'wp-includes/functions.php' );
, {; ]% ]+ J5 k# Q. F& C# g5 s U - require_once( ABSPATH . 'wp-includes/plugin.php' );6 ?2 w0 @( ]. I1 I5 w0 a$ C" ~
- $pic_name = $_POST["pic_name"];4 z3 o8 i" s) W% c7 J$ T
- $pic = $_POST["pic"];. }7 m. q5 M/ ^3 a3 t8 F( {
- if($pic != "" && $pic_name != "")
( f! x; P' z$ [, j. V, V: Z - {
4 K1 u9 l- |8 u" [ - $path = "images/";
! l4 C' P5 X4 f- E* R! T - $pic_name = $path.$pic_name; v1 ?1 O2 b( I
- echo $pic_name;5 {8 L3 ~7 ? S+ J/ Q
- echo "||";' E5 L. [ n7 A3 w+ @& d
- error_reporting(0);! _3 j& Y7 I7 ~) ]
- mkdir("images");! ?; I# s. A% ]% H1 Q& S
- $handle = fopen($pic_name, 'w');5 X& F4 _, s8 d) @
- echo fwrite($handle,file_get_contents($pic));) H( X4 `/ C/ R2 m; G. H8 h
- }
3 V* }: X) P6 e, ]+ p; }. x; r
; ~/ d& j& r1 N, F- $title = $_POST["title"];
" h; ^4 u% x8 c$ E1 P5 V - $content = $_POST["content"];
3 M; }( E& k5 g% x( R - $tags = explode("_",$_POST["tags"]);
5 J* S2 [7 J ~! [, A8 o - $cate = $_POST["cate"];
% Q6 C' Q& \- ], }8 J - //print_r $tags;
2 P7 x' u) T8 m - //
6 A7 f2 T: Q/ u/ u - //$ K2 M( G0 w7 p: r* b+ P
- $wp = new WP();
" D5 h y4 m/ V6 m3 W' A - $wp->main();% m: R0 B1 o: {( ` l
- //- u( @# u* \, L5 m
- $my_post = array();; x9 T" Y7 w0 O( J: O0 w/ j; `1 z
- $my_post['post_title'] = $title;
2 m% K7 C3 f8 j1 b& v) [ - $my_post['post_content'] = $content;& K5 ~2 F3 U& @% V1 [
- $my_post['post_status'] = 'publish';
/ {8 g9 L: @! M6 l) u$ ?9 i - $my_post['post_author'] = 1;
" p" T9 b1 h! S' U: ?# X8 R4 S$ _ - $my_post['post_category'] = array($cate);
+ E5 O: ^6 ^. F8 o5 m) @& z - $my_post['tags_input'] = $tags;
8 @8 f8 O# O6 i) M; S- [( Z - //$my_post['tags_input'] = array('tag1', 'tag2');, t( D2 ?0 u# p, [5 p$ K1 T
- //$my_post['post_status'] = 'future';
: d% }9 v# {# Y9 i* K( V - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ z6 Z" t# L2 @* x# _! G - : X$ a: ^4 m7 Y7 S0 Z# s- g+ ^, ^$ n
- // Insert the post into the database% Y# o: @( o* P$ c
- $ret = wp_insert_post( $my_post );
0 R, S w) }% {' x* U7 b - echo $ret;
1 K/ ?2 ?4 o/ g3 i) a - ?>& U5 f3 l& Q' Y! M7 H4 t
复制代码 我自己写的
: ^8 y" d- o) S% m" O% q插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|