|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " h4 I: K* T f3 G" i
3 H4 f- i) U8 W5 \, P直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
! t- B: k* v6 |. ^) w% A+ a" C' J! |
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 m* u, _1 S% L1 Y+ F
) { A" z+ p* O9 p; }% J
方便实用 简单 何乐而不用呢
* ], Z: C2 T$ Q% _7 B) i& L9 e- <?php1 a. ]7 A! `* Y9 |0 h: o% b
& z5 O& R! o0 C1 n# i* G- \* P- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ m+ Q; m+ [( R( ~3 h* M8 \ - require_once( ABSPATH . 'wp-config.php' );
* s$ N! S; h n5 V$ A9 @+ k - require_once( ABSPATH . 'wp-settings.php' );
2 j) R( @* h# k& M0 a3 H - require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 r: B4 o! M: b' x( K - require_once( ABSPATH . 'wp-includes/functions.php' );* t" U3 \ G' a% K* [' J
- require_once( ABSPATH . 'wp-includes/plugin.php' );
( t& J* f, p( ~6 X - $title = $_POST["title"];
8 C4 f9 c4 v( Z; v( \% O- x& | - $content = $_POST["content"];
# @! j8 z- d7 H. v9 ]- \ - $tags = explode("_",$_POST["tags"]);, B3 `' T4 `% f5 M
- $cate = $_POST["cate"];4 G R. g z9 j8 i: v* N* k
- //print_r $tags;, ^0 {6 S7 A$ o* ]( A0 _
- //
. b; u4 Z% n% V& p% ]) W - //4 g1 ~3 N4 W/ V- Z: w4 U6 E5 T
- $wp = new WP();
) f$ u: m3 x) f( } - $wp->main();
6 g4 S* _+ |5 n, T - //
7 O9 T( @0 F$ t' s! j - $my_post = array();& o A* U! s2 f, S
- $my_post['post_title'] = $title;; D/ n' \: T% R; Z
- $my_post['post_content'] = $content;
% B" Q- [+ ~! J+ r* E% w& Y- p - $my_post['post_status'] = 'publish';% T1 ?8 \* |3 B" v
- $my_post['post_author'] = 1;; P/ Q; {0 P: c/ n" j5 m* |& A( `
- $my_post['post_category'] = array($cate);
, H4 c+ s" Z, Z* o. _ - $my_post['tags_input'] = $tags;/ G9 c, F# O+ E* }4 {$ b/ R" E5 s
- //$my_post['tags_input'] = array('tag1', 'tag2');6 K `0 i. {# w q9 o1 j I
- //$my_post['post_status'] = 'future';+ A K Z2 r: k' ?: b/ [
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 c5 h9 ~5 D) }( _1 ]; P
6 u8 G3 p$ N: _ }. \* z* _; C- // Insert the post into the database! {+ Q% V& o& |) m, L3 @
- $ret = wp_insert_post( $my_post );
9 H5 x4 `: `- C3 g/ }3 E - echo $ret;
1 M: T' D4 s- b5 `, \ - ?>: S5 G- O/ T$ `# |* G5 i6 }, ?
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 S* X4 U" g0 Y2 L* }3 H6 @- <?php
8 f; L& Q- V3 @% I. Q, j' D5 Y - define( 'ABSPATH', dirname(__FILE__) . '/' );- S* i# l, i" `, I8 x9 `9 _" P
- require_once( ABSPATH . 'wp-config.php' );, k. U0 W% _- D4 L+ g- q
- require_once( ABSPATH . 'wp-settings.php' );: B+ t# Z8 v0 G
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
" O8 D6 s% O5 s. k: A - require_once( ABSPATH . 'wp-includes/functions.php' );$ ?% k. D$ o% O e# |
- require_once( ABSPATH . 'wp-includes/plugin.php' );
) O: B0 {& r4 t! m% `) H6 [ - $pic_name = $_POST["pic_name"];& z( a7 k# z4 R/ x _3 r
- $pic = $_POST["pic"];) S! S, l+ A, e: d8 K
- if($pic != "" && $pic_name != "")
' N! J# v( [6 _ `' f, q! j# X' B - {
" E' z! C% m: U7 j# u/ H. k& R, K - $path = "images/";
+ h5 c# t. N1 [5 J2 u3 C. Y - $pic_name = $path.$pic_name;
3 o1 y1 W( ~/ f& E5 }) q - echo $pic_name;
: Z3 t: U' ^0 J) d$ A1 Y6 o2 W - echo "||";
( ?$ j8 w4 G1 H - error_reporting(0);
( c' B! Q% a* C% a3 ?. E* b - mkdir("images");8 |5 @& M5 V6 h8 u
- $handle = fopen($pic_name, 'w');
: P6 N9 e8 L2 v8 G: p - echo fwrite($handle,file_get_contents($pic));
7 S9 [9 c% u1 }0 E/ M* h - }
" Q/ d q, X; ?$ w+ f1 J
7 Z! ~: U6 z7 q+ @: s0 M4 k- $title = $_POST["title"];% A* `0 z, {/ V. n, q, s% @" v
- $content = $_POST["content"];
- h/ \: E$ M- B& l* B8 j! H - $tags = explode("_",$_POST["tags"]);* l7 K* j: K0 ^5 I8 m$ N# A/ F0 A
- $cate = $_POST["cate"];4 u* }3 r0 Y8 W* ~1 q3 h
- //print_r $tags;4 v i8 P* `. j0 c3 y
- //
" f9 ~: P$ k1 O ?. a - //
. C$ p8 K/ ?! x' r - $wp = new WP();8 K: |. O- E& o, g- _
- $wp->main();. a% a+ `* G: d. l' u7 l
- //- q4 q2 H- `9 ?$ C1 [' t
- $my_post = array();
2 l& E t9 b0 Q$ V w4 e+ x! V - $my_post['post_title'] = $title;; ?" B, `2 A' N
- $my_post['post_content'] = $content;; i* i$ G; L2 K- m" X$ Z y
- $my_post['post_status'] = 'publish';
4 i; ~) {# k0 Z M3 [ - $my_post['post_author'] = 1;
8 n" N( Q; m7 z7 ` - $my_post['post_category'] = array($cate);; r" D; m8 W- w( y- u4 ?7 ?7 \
- $my_post['tags_input'] = $tags;$ r m( T6 l# o3 D5 F8 w
- //$my_post['tags_input'] = array('tag1', 'tag2');5 g# p+ ~% P% Q
- //$my_post['post_status'] = 'future';
3 {- r& X! |* e- H, G/ L: v - ////$my_post['post_date'] = '2010-07-04 16:20:03';; O N' L8 O! t4 I2 b
- 3 P3 G- X- I) v
- // Insert the post into the database
* O) y- Q! P, G9 F5 { - $ret = wp_insert_post( $my_post );% C7 a- U! s: B" t+ `* r( s
- echo $ret;6 l% D4 E0 [+ \6 f, [9 f. K
- ?>
9 i$ `+ g4 y# ?7 S
复制代码 我自己写的5 q9 X& n* T9 z: p4 c4 l
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|