|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 H+ z2 {: b' c$ P9 d, y( v9 h, ~2 O) c, W# {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 K2 r* k9 \1 I
3 x+ H/ q. [1 F# R我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了! M/ F7 y0 H2 ?; ^: h% }. R3 C
# J; `# R8 L+ \' ]- n( J+ @! e0 k方便实用 简单 何乐而不用呢
4 c1 w4 s* C8 c3 n- <?php
% F' v5 K2 }( L6 N - U; [, P9 M) M+ a0 T, U; c
- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 c: ^9 Z3 I' z( |* t; s - require_once( ABSPATH . 'wp-config.php' );& |+ }2 H) g, v# Y1 ^1 @
- require_once( ABSPATH . 'wp-settings.php' );$ ]$ M$ f. R+ Z2 C5 y2 o
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 V& i- [' h8 r; G - require_once( ABSPATH . 'wp-includes/functions.php' );) |+ r7 I- d' y: |
- require_once( ABSPATH . 'wp-includes/plugin.php' );! d0 J, B/ ^. j( X
- $title = $_POST["title"];
5 R* @5 z8 J0 B - $content = $_POST["content"];
7 }+ b* q1 c: X/ [/ w% z+ ~' B - $tags = explode("_",$_POST["tags"]);
, d+ C" o& |' S* T7 M - $cate = $_POST["cate"];" W' l n9 {: F5 {% ]
- //print_r $tags;% ~+ g4 _' m. c0 {
- //! r n: w# n. E, a% U
- //" q" g# H: C) c- ~0 Z, M
- $wp = new WP();3 R# I! X% I1 M4 h$ I0 [
- $wp->main();& g( n {: v+ k! D
- //
/ ]6 W; D5 X0 a - $my_post = array();
6 \) u6 S6 ]" ] - $my_post['post_title'] = $title;. q, o2 c- L/ O, b/ H, S+ J' Q" w
- $my_post['post_content'] = $content;
. d, {9 C4 j, k B. i2 v5 [, y - $my_post['post_status'] = 'publish';7 ~4 R, M& h7 T
- $my_post['post_author'] = 1;. P. g, s1 ~: u+ q) `- x
- $my_post['post_category'] = array($cate);
! e: X: @; Z* f) g3 y - $my_post['tags_input'] = $tags;
( c$ H% p3 N; C9 _ E6 T: N - //$my_post['tags_input'] = array('tag1', 'tag2'); x3 E) H1 I8 i( q# q, H( s
- //$my_post['post_status'] = 'future';
$ Q- f( }+ T3 I. F - ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 v& m- Y5 `7 Q) B - 0 b1 p% Q8 e1 U6 G" w( a, _# V
- // Insert the post into the database
+ [" I. n' D' _ - $ret = wp_insert_post( $my_post );
0 ~6 {; e. X3 M- }# N, } - echo $ret;0 B' R$ o8 q) v
- ?>
5 m, |! r+ \3 j2 F, q) W
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- t0 S0 ` ^0 @) w1 e4 X: |- <?php3 t; T. V/ O2 L) u/ B# m7 k
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 F' [ ?. H$ b, U; C6 g. m. p* G9 O - require_once( ABSPATH . 'wp-config.php' );- b+ z9 _% i l! ^
- require_once( ABSPATH . 'wp-settings.php' );
6 @ O y' v; c2 z3 [8 V - require_once( ABSPATH . 'wp-includes/class-wp.php' );, Q. z6 B- `, l3 {( g4 g: v/ I
- require_once( ABSPATH . 'wp-includes/functions.php' );
" s% l7 }: A4 ^$ J' N" K) _1 A$ U - require_once( ABSPATH . 'wp-includes/plugin.php' );
; b2 j$ R3 F6 K% t* \- O - $pic_name = $_POST["pic_name"];3 `1 ^+ |! ~+ W5 G2 o8 L A5 ?
- $pic = $_POST["pic"];
( k& h5 [2 }: Z [) o. M7 B, D - if($pic != "" && $pic_name != "")" F1 @8 @+ M+ P6 F, v
- {8 b6 ^: _6 D, \) X/ L
- $path = "images/";, u6 ? u! t/ A# J5 D7 y: u- ~
- $pic_name = $path.$pic_name;) j3 L) N4 w) d- I
- echo $pic_name;7 H- @1 P0 X) H( @! B6 V3 M' B
- echo "||";
% @7 p6 |5 }% K0 T - error_reporting(0);
/ S) z' C! w s. ^" u - mkdir("images");
$ v4 P6 Q% R1 h) W - $handle = fopen($pic_name, 'w');6 ~( j( n% q& Z% c3 c
- echo fwrite($handle,file_get_contents($pic));
3 ^0 {! T& P( Q8 k" R2 J6 [2 n1 ^ - }
2 l, @$ x: U% U" F) B2 R8 x
, V9 m- @4 E, f6 t8 N9 S" z9 B- $title = $_POST["title"];
0 H3 {. L. V) l' y( V - $content = $_POST["content"];
3 v" S; _: G* n+ `4 Q6 d - $tags = explode("_",$_POST["tags"]);' l ^# }5 X- {' C6 q7 a4 P
- $cate = $_POST["cate"];) J+ ~7 Q4 n0 a" y
- //print_r $tags;2 z& `" a, E. |2 h% ]
- //
" m/ }: {; I* J- T; R - //
/ \6 t+ A C7 u* c& s - $wp = new WP();
% H E! ?2 \! S* p - $wp->main();, z. @& Z7 \# G5 L0 k: V m1 H
- //
: ^$ V8 s& C3 J" o+ Q; f% W - $my_post = array();1 _- B! k3 u! \
- $my_post['post_title'] = $title;
" P4 n- V/ @6 X0 r+ q4 w: w( D - $my_post['post_content'] = $content;* H0 O g3 B1 @; X- l* |
- $my_post['post_status'] = 'publish';8 ^% q" s( t7 r9 z5 N; H9 A0 b) G
- $my_post['post_author'] = 1;
! b$ R3 c; J& W" R7 P" j. f - $my_post['post_category'] = array($cate);
4 ~/ v3 V% K# J: _7 p( N7 x6 I5 b - $my_post['tags_input'] = $tags;: Y2 D8 t1 }4 F: A% p1 }; D
- //$my_post['tags_input'] = array('tag1', 'tag2');
) n4 I( h4 k- m7 r; D( N* @ - //$my_post['post_status'] = 'future';
& O; @9 S6 j( F. U7 h- L n - ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 G# G8 h0 m$ C/ r' j0 G6 f$ z" A - + }. o- h6 [% }. S8 w ^
- // Insert the post into the database
/ ^/ x, r; r% |+ R+ D8 f4 x9 @: [- E - $ret = wp_insert_post( $my_post );3 W$ Q, @8 y( p( @1 C$ d
- echo $ret;
5 ~! b: R! E0 N5 ] - ?>2 }8 D/ W( k, p; i d& ~0 H
复制代码 我自己写的; u4 Z% b- i2 J+ H5 Q8 M
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|