|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 d2 ~2 u3 T, I5 {
7 }1 T' ?7 ?) N3 O
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) _8 r, G4 U8 e& }; Z3 @; f
: y' W: T1 M) ^1 h+ C7 N我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了2 g4 `% ]9 Z0 f+ l
: |+ O$ ?& U4 ]" K方便实用 简单 何乐而不用呢- # Y$ h: ]: C7 |6 b$ U: [
- <?php- \- h+ q8 k: W, }" k' s* j. R* ]
. o& d5 m l S' A$ F# L8 j. {; d- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ H2 h8 u& b" B- u - require_once( ABSPATH . 'wp-config.php' );8 _# Q. \- ?4 v B7 H: b
- require_once( ABSPATH . 'wp-settings.php' );
4 G8 r+ ]* {& B# y4 |$ ?+ M* X# |7 h - require_once( ABSPATH . 'wp-includes/class-wp.php' );
' T% o# @2 o. @; W8 R. m - require_once( ABSPATH . 'wp-includes/functions.php' );
g( q' E8 _. j - require_once( ABSPATH . 'wp-includes/plugin.php' );' w( z4 _+ L8 Y5 u# x0 ]0 ~
- $title = $_POST["title"];
' w7 V) y, W b% L9 ?5 M! {+ \ - $content = $_POST["content"];
, Y8 {8 f M, `9 M8 g3 y# ?( @/ q - $tags = explode("_",$_POST["tags"]);# P' z u+ A B. h/ A. W
- $cate = $_POST["cate"];9 K8 s8 R" R# @ i: x4 E
- //print_r $tags;
. S2 r2 c0 l' B1 z. D9 G9 s3 C - //
3 e! F+ F" I* _8 z9 S - // F! n" Y! H$ C1 Q' F( {1 Y2 d
- $wp = new WP();1 Q. p0 R! R5 e4 H3 W* G' U7 M1 j
- $wp->main();
+ g/ V; I* O0 V. I4 g - //
! r8 d D; S y. ^& v/ j6 K. B, m* B - $my_post = array();/ [$ `' H* j- M- d% c
- $my_post['post_title'] = $title;
# T1 a: [- n" R, z& q6 D; V! u - $my_post['post_content'] = $content;
; r' [" {7 g4 n3 Q3 O - $my_post['post_status'] = 'publish';! ^ P( M [2 O" W/ S
- $my_post['post_author'] = 1;
9 e& _/ E' T4 t - $my_post['post_category'] = array($cate);$ @; v% b4 ?4 P0 v
- $my_post['tags_input'] = $tags;
6 a$ c! G' [9 j3 |5 o' T - //$my_post['tags_input'] = array('tag1', 'tag2');* S# V6 A5 x8 t! I/ b R" }
- //$my_post['post_status'] = 'future';
- a9 ^7 v. d: T. H$ N6 Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 J5 ^/ ~9 e) J% O8 F, S - $ b; h! J& a) b- O- f
- // Insert the post into the database
* Y S: k9 @! m: @) \) l0 t" x9 J - $ret = wp_insert_post( $my_post );3 S6 g; m4 ?+ T
- echo $ret;( { w$ z2 k9 M7 I
- ?>$ _" N% N# W* ^! o. t: K4 d& i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- / ~: ^- `* h+ r, [* D. E% L) `. s0 p
- <?php2 m6 y3 W2 p; S: |: x7 R% W
- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 j. n9 c. j p$ h( l - require_once( ABSPATH . 'wp-config.php' );% c! U7 @) d! y9 |. {% R/ y
- require_once( ABSPATH . 'wp-settings.php' );& @. ]4 W' Z" C5 I5 h
- require_once( ABSPATH . 'wp-includes/class-wp.php' );( A7 w1 t8 I; |% O4 Z
- require_once( ABSPATH . 'wp-includes/functions.php' );7 Z J- a4 r0 W& f7 H
- require_once( ABSPATH . 'wp-includes/plugin.php' );
8 x% w; X+ f+ g2 q4 `2 _ B1 D& t4 q - $pic_name = $_POST["pic_name"];
7 a7 n/ D+ O- r1 V - $pic = $_POST["pic"];
. G: b' R3 C5 \; T! Z2 ]% a - if($pic != "" && $pic_name != "")
8 N- L1 q4 ~6 k2 \ - {
+ [. S3 F+ N/ ]2 F }# h& U# r - $path = "images/";
- e1 G: m- F% ~1 D$ f8 F' C - $pic_name = $path.$pic_name;. o& R- w1 j j
- echo $pic_name;
# }5 l0 Y8 o0 P' U/ g' k$ d- ` - echo "||";
: I3 X) M, [# L! h - error_reporting(0);
2 u5 D) k# ^( O - mkdir("images");8 u6 k; X# C7 c# a& V+ y! m
- $handle = fopen($pic_name, 'w');4 N4 K6 x5 n5 H1 l6 h5 E
- echo fwrite($handle,file_get_contents($pic));
, ?& {# v- M- c: ` - }
% }! o8 _5 j5 H. @, }% c' @ - 4 \# ^/ f" I5 V7 w5 j# G
- $title = $_POST["title"];
, D: X; I. d; T - $content = $_POST["content"];
8 ~1 l2 @/ Q$ K' G3 A - $tags = explode("_",$_POST["tags"]);
3 {2 J' F# o% b# n+ y - $cate = $_POST["cate"];4 S( y$ _3 {/ ]. x
- //print_r $tags;% |1 P& O3 t% X2 _# U3 r
- //$ D3 A4 @% _* ~) x
- //* z7 k) _% R" P
- $wp = new WP();7 J7 k. Q( J- P0 L$ r6 ~* M
- $wp->main();5 Q1 J! [0 x$ t; q$ e
- //
% m9 H" S9 [% o$ r: v4 i( ` - $my_post = array();$ c. R9 P$ `+ P" L, q
- $my_post['post_title'] = $title;
$ q' C; Z8 n+ Z - $my_post['post_content'] = $content;
$ w4 z! d# h$ {; J& ^ - $my_post['post_status'] = 'publish';! U3 s& d" \ T5 g6 M
- $my_post['post_author'] = 1;5 C3 o4 A! P! x, c* l. }) B
- $my_post['post_category'] = array($cate);
. {- u( T X: _5 A/ m - $my_post['tags_input'] = $tags;
! J! @+ h$ s7 ~1 ^, \ @ - //$my_post['tags_input'] = array('tag1', 'tag2');8 b) U5 G4 v/ G, v2 ~ ~1 C; G7 X
- //$my_post['post_status'] = 'future';
0 Z) p/ n8 [4 p! L+ v; f& @4 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 t& X( K0 w6 k' ]) l
$ U4 Y& P- i/ H9 R, l" B( A+ p- // Insert the post into the database0 f2 o( G* {& W$ Y" t
- $ret = wp_insert_post( $my_post );$ o5 B% O4 f S. L3 @3 H" n
- echo $ret;( S( v- `. }- ^& W* [! ~4 L
- ?>
$ S! M g7 Q1 s) i+ W
复制代码 我自己写的
/ T/ ?6 t1 C" v$ P5 {1 p9 u3 k% j插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|