|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 X9 U6 ?- S3 x$ c( _$ a; l6 b5 y
: R) Q; l/ @9 u% U1 F
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. |; k, ]/ N8 o. T, i
$ F9 @- t7 B7 E" ]/ g2 o' i我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了/ K6 T- s1 b `" {% i+ I" {7 \
3 i5 O, b- M8 |方便实用 简单 何乐而不用呢
6 `) I2 i' ^4 U3 d- <?php
& _$ ~, I9 }1 G- ?2 T
& H+ u' r/ ]) |- p( [* @- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 T" p; b7 ]' W9 u& G9 ] Z* ` - require_once( ABSPATH . 'wp-config.php' );* m; g+ a9 H6 b9 Z
- require_once( ABSPATH . 'wp-settings.php' );7 Y/ ~0 e1 I2 N2 K$ r+ Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ @/ c6 ]: F4 B7 c4 j' j2 h - require_once( ABSPATH . 'wp-includes/functions.php' );3 [! M# X6 D- X* k6 t* f1 \
- require_once( ABSPATH . 'wp-includes/plugin.php' );( q: H3 e5 ]! q0 b6 y
- $title = $_POST["title"];0 G7 y) Q f; u; y: X' F
- $content = $_POST["content"];
! a0 c C1 v" u# k - $tags = explode("_",$_POST["tags"]);% `! w7 h, `& s) Q$ a8 Q
- $cate = $_POST["cate"];
* D1 z6 W ~0 K K& [+ c - //print_r $tags;
; _9 _$ \% C" C7 v9 q" x - //# k4 _; x9 N) n/ T, Z
- //" @5 j: [2 y, n" J
- $wp = new WP();
u+ Q: E( _+ i) V1 N- u" F- [# c - $wp->main();7 b( a6 I- v4 A) j7 p4 _
- //( @2 n% [- ~" x2 @+ _6 q# ~- Z
- $my_post = array();2 X% h: O& ~" Y- s1 {3 l: Z; X
- $my_post['post_title'] = $title;
$ [# P% M7 O) K! h - $my_post['post_content'] = $content;
4 ^# x" z$ P0 I0 j - $my_post['post_status'] = 'publish';
: Z+ U- v& D% B+ V% t - $my_post['post_author'] = 1;8 A- G) k/ o5 W1 @, o! e
- $my_post['post_category'] = array($cate);
7 l3 C7 \( P! y) [ - $my_post['tags_input'] = $tags;
2 L4 `; \& b& P - //$my_post['tags_input'] = array('tag1', 'tag2');
! M, @9 G( w/ `2 s) `0 G - //$my_post['post_status'] = 'future';
2 f7 H% @8 g6 {% @ Z: a" W - ////$my_post['post_date'] = '2010-07-04 16:20:03';& L3 j0 o9 B4 j( @
% W( A( L4 O+ @0 P+ o- // Insert the post into the database. U( v$ Y1 Y3 q1 ~% U% G5 r
- $ret = wp_insert_post( $my_post );$ O2 D( R S5 f4 H
- echo $ret;3 U/ U: v/ f% W# B* [6 C
- ?>% o& E. H; b1 Q" a4 I: o
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
: W- }, a* d4 M( {) A$ }: C- <?php
2 r1 ?$ p4 K) V: j$ s4 c& }; L - define( 'ABSPATH', dirname(__FILE__) . '/' );( z4 g& d0 w. `; {1 L1 A& R
- require_once( ABSPATH . 'wp-config.php' );$ g4 S5 ^2 S$ S% j/ l4 O
- require_once( ABSPATH . 'wp-settings.php' );' `: I, q8 `- G- E, s4 i2 g
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) [4 x' E* m$ ?/ _6 U8 i# i - require_once( ABSPATH . 'wp-includes/functions.php' );# |1 }1 F* N5 f- v Q) Q- c* a0 ^
- require_once( ABSPATH . 'wp-includes/plugin.php' );' C0 \; x" Y/ m& |2 n2 Q9 _2 u
- $pic_name = $_POST["pic_name"];- P6 b( @0 s; V p( k
- $pic = $_POST["pic"];
% O( S+ s9 R& d9 Y - if($pic != "" && $pic_name != "")
2 F6 S/ j* d: L% D% X: ` - {* T. |7 a- A o, z" Z+ T/ y% J
- $path = "images/";
) N: w- \# i$ R0 n0 n - $pic_name = $path.$pic_name;3 u& E) e* o* J7 L3 r, a' T
- echo $pic_name;
5 U0 K: Z, J9 ^' U - echo "||";
! _) T, X7 X p/ _! F) X - error_reporting(0);
3 j1 @" n* T% u5 ~: |* O - mkdir("images");" x2 a7 T4 J( W
- $handle = fopen($pic_name, 'w');/ s4 o7 ~& ~& x/ ^7 v5 J
- echo fwrite($handle,file_get_contents($pic));
3 Z1 Q, z( ]* e4 @0 d - }; f4 {$ [" J/ C: p* a: C3 E
) p5 L$ A4 u* S) a- G- $title = $_POST["title"];. z% s, e( h2 J {8 X+ c0 @+ E
- $content = $_POST["content"];% G! X9 ~7 W& F0 ~9 D
- $tags = explode("_",$_POST["tags"]);
y+ ?' U& G0 R9 k2 S/ C4 R - $cate = $_POST["cate"];
, h9 J" V6 ]" m8 p' m6 ~9 Q - //print_r $tags;
5 O/ M3 m1 O1 j2 m - //
, c, Q' J5 t0 l$ I+ R - //; v* M) D! ]1 s4 V$ c
- $wp = new WP();
" r3 T/ H V9 S8 T8 p u; o - $wp->main();
, _+ q, s* [! z- [- A# f+ P& o - //
! U% v9 V, ^2 |( V. d( x6 ^ - $my_post = array();/ O1 U4 _5 l; H1 p( Y
- $my_post['post_title'] = $title;( g* z3 O# X' m6 P5 Y
- $my_post['post_content'] = $content;
% P" T9 T& i# d9 P( H - $my_post['post_status'] = 'publish';
9 }: @, C! ~, L$ M% T; I - $my_post['post_author'] = 1;1 X: X0 r; x' U
- $my_post['post_category'] = array($cate);
) S5 j# o' @8 b2 K - $my_post['tags_input'] = $tags;
. _; X( Z3 ~% B4 `, S6 k3 M - //$my_post['tags_input'] = array('tag1', 'tag2');
! c' \- T! h9 g' I j- j - //$my_post['post_status'] = 'future';
3 ], b; D' c. c% p+ d - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 r9 Y# u# e, J f1 B6 b
# j9 z6 I- C9 }4 {- // Insert the post into the database6 h4 Z* v! d& R' ]
- $ret = wp_insert_post( $my_post );* y q7 V! x9 ~6 v3 R! G
- echo $ret;( S( r9 X! g V7 R
- ?>' T) s$ L0 q. N% @# n* J
复制代码 我自己写的
4 o1 x: c9 V( |$ \% v7 a插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|