|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
# T# Z# x# n$ J! B
; `9 {% Q4 L2 e6 R/ A N( @直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- I& }7 T8 ^/ o1 v0 c
- y- q5 C4 J- b5 |8 V$ Y- E `我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了1 N! {) N" A* V
$ w% l1 q5 d; o, B3 K9 h
方便实用 简单 何乐而不用呢
) I" S4 T+ y; P6 a+ [" O- <?php
. H8 ?' F; C: x5 I* d
- O/ y- R+ }3 B- define( 'ABSPATH', dirname(__FILE__) . '/' );8 N R) J* v% _2 J+ z: e4 L
- require_once( ABSPATH . 'wp-config.php' );3 V6 W/ l5 `! @/ d9 A% F% i
- require_once( ABSPATH . 'wp-settings.php' );+ L& r- W4 E7 y5 x* R2 S
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 C% @6 x+ Q; l! w( S& [, X9 X8 P
- require_once( ABSPATH . 'wp-includes/functions.php' );
; L( }! s; N: r: I' L - require_once( ABSPATH . 'wp-includes/plugin.php' );3 q. @$ t$ X$ I0 O* ^8 G
- $title = $_POST["title"];; [9 \! ~- k8 R+ z- T1 K. v
- $content = $_POST["content"];% E: _, q; T* V' `
- $tags = explode("_",$_POST["tags"]);
# p; S5 X2 u# n+ h - $cate = $_POST["cate"];" x0 |+ [9 Q9 f% ?
- //print_r $tags;
S1 q8 E o6 o7 w, J4 U5 a - //
R# P4 n, C9 c" C6 H - //, Z i( }+ t( q; d' f# e
- $wp = new WP();
1 f+ k3 O8 I K2 M! j/ x2 ]' @& H ~ - $wp->main();
# u, _% T7 t8 A% g7 w5 _. ~, i - //; c* \; M- T1 V) m/ R
- $my_post = array();/ M0 N7 e4 a8 a. q6 w f. e
- $my_post['post_title'] = $title;( a" ?2 ~: b" l, B- p# R
- $my_post['post_content'] = $content;8 U" {7 \0 h- a/ c5 H0 N
- $my_post['post_status'] = 'publish';
+ R. a O6 ?3 @, G4 u( u# b - $my_post['post_author'] = 1;
7 _: G/ p+ E0 y% R% n - $my_post['post_category'] = array($cate);! E" x' F4 b2 ~8 y) W
- $my_post['tags_input'] = $tags;
2 ^* z+ M/ `( f7 m b2 b - //$my_post['tags_input'] = array('tag1', 'tag2');2 j' `+ S; x2 l4 L
- //$my_post['post_status'] = 'future';
6 D0 }( b K& y9 v - ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 ?8 }# l* i+ W' U3 F5 _ - . j& F3 Z! Q+ I( K% J
- // Insert the post into the database
( p8 O. t3 R X; r1 _9 Y - $ret = wp_insert_post( $my_post );& H! G" a- v( B N7 A; @7 L$ k
- echo $ret;2 G5 T8 E: d& Q9 ^" W/ _ s6 j
- ?>
+ R$ y0 B! H/ Q! j9 X1 _
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
7 q- N1 G! y1 _1 C9 v$ x6 a- <?php
[" H9 b! W3 B: x* \ - define( 'ABSPATH', dirname(__FILE__) . '/' );
- W# \7 h# x; u+ Z" { - require_once( ABSPATH . 'wp-config.php' );
. A5 r- X8 [: s' C# a5 ]3 A1 f* v( v - require_once( ABSPATH . 'wp-settings.php' );
/ t$ n& q D7 k* i! ]3 u - require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 m6 B @$ m1 C3 \: D - require_once( ABSPATH . 'wp-includes/functions.php' );
! I! }$ U/ a# K - require_once( ABSPATH . 'wp-includes/plugin.php' );5 ^ V6 J" h# t: c: k
- $pic_name = $_POST["pic_name"];5 \" s' @# u. a3 i( E% O
- $pic = $_POST["pic"];; G$ L$ B) q) W9 |/ l
- if($pic != "" && $pic_name != ""): D+ _, O+ ~5 ^9 g4 ?
- {
# @( w$ M) V: z6 T$ Z4 ] - $path = "images/";
4 P7 _" k, T# L* {! I8 x1 ~1 D - $pic_name = $path.$pic_name;! G3 T, {0 [+ {5 N; O# g c
- echo $pic_name;
7 R# F9 i9 H# O6 u - echo "||";
/ }7 v& g3 l- r. Y5 u - error_reporting(0);
9 B5 u9 I/ N' a9 D l - mkdir("images");
" z2 U6 g, h: s$ u8 u$ z - $handle = fopen($pic_name, 'w');! }# B# o- u# h; u+ G* a5 S
- echo fwrite($handle,file_get_contents($pic));- B2 E1 q* [+ h! C, r% e
- }; H. R# F8 k: x: t" V1 @* ]+ n2 z
- 6 I% |! A' H5 C% g
- $title = $_POST["title"];: Y, c- ?7 W. l
- $content = $_POST["content"];
0 O+ g) j8 |' m8 r - $tags = explode("_",$_POST["tags"]);
1 e4 f: r) P3 i. b* V/ X - $cate = $_POST["cate"];
- G; T( J3 A4 v* G7 l5 U - //print_r $tags;
6 P# J) U0 u* N2 i/ x5 N - //
; ]3 D* k# \& F* P- ?1 q - //
0 M) L! J; U$ k a. o9 m - $wp = new WP();
% D! l+ j, H7 R5 R' f - $wp->main();
1 w% r- ~# C! m$ G. {. d- L - //
% a) v0 x8 B" z' ?4 K - $my_post = array();' g3 J; Y8 V$ m8 s6 b: u3 t; Z3 A
- $my_post['post_title'] = $title;
$ I3 |/ j) Q0 j c% n' M - $my_post['post_content'] = $content;/ I$ S, u$ [/ i9 H) \% s9 S
- $my_post['post_status'] = 'publish';4 D6 h; [' p/ P5 w7 N
- $my_post['post_author'] = 1;' f6 h4 D2 b# c
- $my_post['post_category'] = array($cate);
' j# B2 S" V5 w, U& k0 ~' C; r - $my_post['tags_input'] = $tags;2 z/ R2 T C! L
- //$my_post['tags_input'] = array('tag1', 'tag2');6 U+ b! y: k8 Q7 M! m/ a
- //$my_post['post_status'] = 'future';
; m6 ?8 S; o3 S& o - ////$my_post['post_date'] = '2010-07-04 16:20:03';9 g) ?2 I0 z! q8 x$ H4 Z: `
2 |7 U! N% C) v7 N, L9 c- // Insert the post into the database& c2 Y1 P$ f. z, D6 {
- $ret = wp_insert_post( $my_post );9 D& x% I8 L+ T4 S( }4 u+ t1 a
- echo $ret;
0 X7 J, X* I" N4 a& Y: y - ?>; n) \" I8 J6 N
复制代码 我自己写的& i7 }. |/ f) ?3 O# m
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|