|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 + v6 q4 E* ^$ b: o
+ G- g l* q, L% d. R) i+ t8 g
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持9 \- f6 N! e7 F* `* N
' M/ R3 M% Q: Q. ?我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了3 G7 I* W( E/ T- T* A6 \, a
$ c! V! g9 h. \4 p方便实用 简单 何乐而不用呢
# M. N! w, Y1 `& Y& H* H; y) v8 ]- <?php
2 B/ |/ @7 |& A$ a
- F" d' p! X) Q- s0 H) c- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 q: O% A; S! O; F* J: D- Z( w* k - require_once( ABSPATH . 'wp-config.php' );
( M" S* h/ b" z! \9 h, ^7 T+ [/ v - require_once( ABSPATH . 'wp-settings.php' );+ S% n# u! V0 Z; m0 F: C4 E) g
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
* `8 J% p- b" {% Z# \5 }2 }0 K: e - require_once( ABSPATH . 'wp-includes/functions.php' );/ t3 q, x# R. G* g' h
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: G% W8 ~! F! }: F, O - $title = $_POST["title"];) `$ | [8 d+ K6 k- i
- $content = $_POST["content"];
1 A A; j$ i9 i- W0 p - $tags = explode("_",$_POST["tags"]);8 P8 C! M. S! m+ G
- $cate = $_POST["cate"];, j7 O+ s+ l2 |( V+ t9 [- o+ Z2 a) N6 M
- //print_r $tags; Q+ I1 t* G4 O3 ^9 ]4 J: W
- //
/ {6 _8 O c% m: u( D6 U4 u3 U( d/ L - //
0 ?. q6 C8 Z0 b - $wp = new WP();/ N2 l" j$ G0 s& V
- $wp->main();# G# H+ {7 U# b& e) n3 C
- //
0 q$ O8 v; B8 d3 `' G - $my_post = array();$ s" a+ }) Y6 V9 u
- $my_post['post_title'] = $title;8 q% H, f$ O5 M
- $my_post['post_content'] = $content;
$ Q6 ^/ H8 c0 D& G4 b8 b - $my_post['post_status'] = 'publish';
3 g" |& `: y& ~3 l u9 e5 s0 y - $my_post['post_author'] = 1;
( A# E6 ^ I2 L! R - $my_post['post_category'] = array($cate);( l4 a: x8 q! B1 r2 M
- $my_post['tags_input'] = $tags;
1 M! W9 [/ D) W: X* [9 h$ V - //$my_post['tags_input'] = array('tag1', 'tag2');) I( o6 f+ k1 ^' E8 H! k
- //$my_post['post_status'] = 'future';
" l. Z6 v5 r4 g2 i2 d+ g - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: [( j, Z; h! O1 G/ }& v; ?% y - 1 }- O7 a: y7 b+ w
- // Insert the post into the database
. q# _. f! E" X0 ] | - $ret = wp_insert_post( $my_post );
9 K: t- a" i( f8 f' x - echo $ret;
6 D" f* X6 H$ j3 j - ?>
( w* b$ U3 e8 g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ! e8 i) |8 J7 |/ _4 |
- <?php
8 {& E6 d% p+ I$ \ t - define( 'ABSPATH', dirname(__FILE__) . '/' );/ G: [; g$ x( U6 H/ Q
- require_once( ABSPATH . 'wp-config.php' );
5 Y" D' z0 F9 m0 s0 l f8 y8 L - require_once( ABSPATH . 'wp-settings.php' );
! }; `% B8 o8 ?5 U* B - require_once( ABSPATH . 'wp-includes/class-wp.php' );5 @% G0 i+ g2 i: n" K6 u' J4 F
- require_once( ABSPATH . 'wp-includes/functions.php' );
5 i& _- x. l4 N) n: C k9 y - require_once( ABSPATH . 'wp-includes/plugin.php' );' u0 ]& o5 x/ g9 V
- $pic_name = $_POST["pic_name"];. G. N+ w y( T( `5 y+ |8 j
- $pic = $_POST["pic"];+ [( v0 ^- ^+ ^& u
- if($pic != "" && $pic_name != "")
0 J1 L3 f( Y! B: N - {
$ n! U/ u' W7 I( z8 _* u5 I, g - $path = "images/";7 ~- d+ s9 I4 N. U
- $pic_name = $path.$pic_name;$ A: G+ L2 ^) k
- echo $pic_name;
* a8 [) D% ~/ g5 M/ P - echo "||";) `( S* X2 |4 J/ a& x/ [3 y
- error_reporting(0);" Q+ I; u8 z( V5 P3 _; d: i' `2 E
- mkdir("images");
1 i! y) A) p- o: {% \5 o - $handle = fopen($pic_name, 'w');
; t% K& x- I Q1 r& ], D1 D" g - echo fwrite($handle,file_get_contents($pic));1 ?/ n* Z D1 g/ r; N( C! n$ r2 ~
- }. v9 R! c n8 O: m8 {
2 C5 ^3 M1 _; Q3 T( V" t; r- $title = $_POST["title"];
, ?7 J D# a9 A - $content = $_POST["content"];9 u% w) k3 _" \( f' A" K
- $tags = explode("_",$_POST["tags"]);
. U( ~+ c6 M+ F& A/ B - $cate = $_POST["cate"];5 [+ o0 E/ h/ c& V( f+ v
- //print_r $tags;
0 k, }" ]4 j1 F4 b- m - //" ^- y( ]. o3 f) H
- //3 p) ]- J# X! g! z' I M* m Y
- $wp = new WP(); [7 U8 F4 P) G3 x+ ]/ d
- $wp->main();" H; f4 N8 o; B! O" v1 {8 e
- //; b }. J6 u0 d6 c( y0 M) S3 |
- $my_post = array();/ ]8 L# U( G. _6 c8 L
- $my_post['post_title'] = $title;
( f* U) E! y: l! x. a. I - $my_post['post_content'] = $content;% {# B# p( P" \( j c7 Z
- $my_post['post_status'] = 'publish';% R5 E1 g [7 Q) Y4 V3 h
- $my_post['post_author'] = 1;
4 E8 P1 G$ M7 z1 q( g - $my_post['post_category'] = array($cate);% Q- B% k: P, {
- $my_post['tags_input'] = $tags;+ m) e( y: y' C9 }2 S$ b
- //$my_post['tags_input'] = array('tag1', 'tag2');! `- u8 \: U+ o1 p1 G l9 N( ]4 C' ^
- //$my_post['post_status'] = 'future';
( Q# n. O( @$ |; d8 q - ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 F4 v$ f: ?( Z- r - 2 W1 R$ a/ T9 ~) V. n1 I
- // Insert the post into the database
" i! V$ a: e8 u6 E - $ret = wp_insert_post( $my_post );( {2 Q: r2 [# T, D8 R
- echo $ret;- a) Y/ Z/ q3 v
- ?>+ M, }: `, k' `
复制代码 我自己写的0 _ O+ Y$ y# A
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|