|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- I% O- |$ n* L! s. o/ {/ I2 W7 i1 \8 s
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 ^% o; l0 M W' j2 Z+ M6 _: I
+ ?0 S) S9 W' o4 x. L/ T5 a
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了2 @4 s3 R, R \* \
$ }7 i" p' {& y& R, S
方便实用 简单 何乐而不用呢- 4 ^- x) n$ w& d+ o
- <?php
2 C8 H- u* J. l
; c4 \% n# M/ X ?# d# l6 _- define( 'ABSPATH', dirname(__FILE__) . '/' );: R$ v2 T& j3 b0 H
- require_once( ABSPATH . 'wp-config.php' );) _" D% X2 _: C+ R$ u' ~' W
- require_once( ABSPATH . 'wp-settings.php' );
7 X* B7 |1 r. l; [) m6 Z @* S - require_once( ABSPATH . 'wp-includes/class-wp.php' );" V5 X5 V- l4 \$ Y: o* [
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 I& S9 L! y' Z: b- n5 c) i - require_once( ABSPATH . 'wp-includes/plugin.php' );
$ P+ v2 G4 Z! R) U - $title = $_POST["title"];4 L# s {1 @2 x5 o- o s3 r
- $content = $_POST["content"];
( E4 ]9 Q8 S, i/ S+ Q1 N4 m - $tags = explode("_",$_POST["tags"]);
1 U) F! {1 q! W1 J - $cate = $_POST["cate"];6 ~" Y I& K# [/ T
- //print_r $tags;
0 y$ F5 G( K. ?. D$ a - //
4 h1 a. s- p* y2 L1 a1 m - //
+ R% _$ a2 q! W! O8 G; T - $wp = new WP();
7 P$ Y3 i. g1 W* Y s2 I# M/ j/ d - $wp->main();
# i5 i/ L6 ]: D" I1 x7 \3 K - //
+ I" \3 _) G& L$ B4 Z+ M - $my_post = array();! B, V8 P9 G' _# a/ O
- $my_post['post_title'] = $title;
5 K5 M2 {% Z5 i& q; k - $my_post['post_content'] = $content;- k& |3 t6 g0 |5 ]+ x" n
- $my_post['post_status'] = 'publish';" V" H& O. [ {; B3 l/ H. b
- $my_post['post_author'] = 1;0 Z+ L B( j# I8 D8 @, ~3 N, `* _
- $my_post['post_category'] = array($cate);
9 {- G. X; R# e; i; o) z+ l - $my_post['tags_input'] = $tags;
1 \: m. f( F$ d7 Q2 u; e - //$my_post['tags_input'] = array('tag1', 'tag2');2 J7 h$ o; L1 y+ O% W
- //$my_post['post_status'] = 'future';
6 \. R0 H# ^+ ?! y7 n: C3 s - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 i- _! L# v, R- P' w7 c5 d4 p - : E. _* D; N# |( H
- // Insert the post into the database8 @3 u# f0 ~9 E. E0 P
- $ret = wp_insert_post( $my_post );
2 ]& k& W: ^5 r* U) ] - echo $ret;
( a% J+ q' J& J) X7 d/ s3 o3 M - ?>! n/ s0 n l" ~# N5 }
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
& V4 L2 F; a. V3 Q; \" u; Q- W& Z. h- <?php
4 k% C( b/ n) [. m$ U/ d. ? - define( 'ABSPATH', dirname(__FILE__) . '/' );, K# q# h% W/ U X4 r
- require_once( ABSPATH . 'wp-config.php' );
3 I2 ^/ o0 q9 d# K6 L1 _. f- q/ _# C3 o - require_once( ABSPATH . 'wp-settings.php' );& S0 w8 [2 K0 R) _5 Y: Q6 u1 _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ y2 ^- K" o6 ^4 W: }4 Q( W) S. q - require_once( ABSPATH . 'wp-includes/functions.php' );
~- _- g4 k! M0 L - require_once( ABSPATH . 'wp-includes/plugin.php' );" U- m8 A! }. Z& b" x& W
- $pic_name = $_POST["pic_name"];
2 W( k E5 D# [ - $pic = $_POST["pic"];
c7 t6 z8 h: ~0 r - if($pic != "" && $pic_name != "")* N. R* Z6 A; q, c. ^
- {
+ n% q6 E4 @1 q* F2 F4 X) x% [ - $path = "images/";( T$ ?9 k4 r o, n( f7 c" G% v" E
- $pic_name = $path.$pic_name;4 E% M+ q9 y9 B6 K J8 a7 @( d* q
- echo $pic_name;
2 J1 m* \9 V, ?, Z - echo "||";( _; V+ T) o8 J8 q7 v
- error_reporting(0);: \0 q5 x2 w- o' z. H1 M
- mkdir("images");5 ?0 B) i: w$ W+ ?
- $handle = fopen($pic_name, 'w');
; G' r1 R% B# k: b) s- z0 Y; G - echo fwrite($handle,file_get_contents($pic));0 B' |- v& \2 ^/ G4 T& {
- }
% }) ]5 N# n6 A. S, p
+ E" @' d* {6 B+ M7 |% g; [- $title = $_POST["title"];
+ X/ z! f' l& o) G& a: X d - $content = $_POST["content"];6 \( `9 N7 u5 r! {
- $tags = explode("_",$_POST["tags"]);
5 _7 ^% A1 p0 y+ g: _% }$ F - $cate = $_POST["cate"];1 Y, C7 }. | p* Q
- //print_r $tags;1 n1 w6 ~' u' _# a$ `
- //! Z7 N& B2 {( V, n' g
- //3 J! h: M5 F* D W! K/ l
- $wp = new WP();
4 C6 h5 D5 Y1 O5 ]% o - $wp->main();5 B6 f% `- P* G: D' W6 L
- //0 {/ S; Y X. m- S, @
- $my_post = array();
$ K! X% C! K# [& ]+ e - $my_post['post_title'] = $title;/ \, d3 q9 |& g! e% K/ S
- $my_post['post_content'] = $content;
2 P0 t- ?2 w* x* Q - $my_post['post_status'] = 'publish';* j8 H0 N9 @. W
- $my_post['post_author'] = 1;+ A0 {5 b; i7 b2 U+ `
- $my_post['post_category'] = array($cate);
! K9 p% G; B- z, B! o - $my_post['tags_input'] = $tags;( `* C/ ^5 N( u# Z- H1 s
- //$my_post['tags_input'] = array('tag1', 'tag2');! e/ v2 N9 ]; u1 @' ]( }% V
- //$my_post['post_status'] = 'future';2 I. c8 r. }5 v. h& Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';/ N) Z; K8 W) ~5 u, ^
8 W2 H2 b, ]; H3 @* S9 r- // Insert the post into the database
X1 q M, ~1 @& d - $ret = wp_insert_post( $my_post );3 c" V6 X3 V2 P: o6 p( U
- echo $ret;
! X9 _, J# U: R: r i - ?>6 {( S6 }5 w* Y; Q( X: Z7 [1 S+ x
复制代码 我自己写的
" J, Q- v- F3 R+ \6 f7 ^" w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|