|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
# j+ H) n1 |* I- ~; ^& |1 l: v/ a0 f' T- K7 Q& u% |+ C
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持! |0 [' N) r7 I" L3 |
8 _( o5 l+ M' Y0 n5 k$ l0 G( ]
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
& J9 P9 v9 }, M
]* b N, n0 l* t方便实用 简单 何乐而不用呢
9 q) r$ Q% F6 s0 W- <?php6 V3 [; N. W( O" R+ D
- \1 P4 k( _8 k) B6 r
- define( 'ABSPATH', dirname(__FILE__) . '/' );# E/ a* X; F1 G) Z9 x
- require_once( ABSPATH . 'wp-config.php' );& |2 ?" M* Y( ]5 v
- require_once( ABSPATH . 'wp-settings.php' );
, M) U) w3 \7 v- A6 J+ Z/ {+ Y$ P9 ^ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 ?) s2 c8 [, } - require_once( ABSPATH . 'wp-includes/functions.php' );' ]7 G+ p; n4 p p* r9 l8 {
- require_once( ABSPATH . 'wp-includes/plugin.php' );
, Y7 x5 p3 B6 P$ c& f5 o ~* r - $title = $_POST["title"];
% p! N" g3 C: O - $content = $_POST["content"];2 z* G) n! g7 I$ H/ y) o
- $tags = explode("_",$_POST["tags"]);
+ C7 @# Q8 z) k7 ? p- o; H - $cate = $_POST["cate"];+ f4 H7 R. O0 H5 n
- //print_r $tags;
, @/ m" y8 J& g( q - //& ^# ]9 O! O) p6 @
- //
1 O3 d. P5 j3 m% N - $wp = new WP();
2 F" @/ f* z6 z$ A/ F9 C; e - $wp->main();
/ ]; [( ^. W3 m. U5 J - //2 @0 R+ D0 P' _8 W- z
- $my_post = array(); r/ e0 v+ v6 m. S- e' j
- $my_post['post_title'] = $title;0 ]; v3 C- l' B
- $my_post['post_content'] = $content;
9 B/ {; Y* F0 d - $my_post['post_status'] = 'publish';: W, A: l. \5 c! g, N0 i$ m# W
- $my_post['post_author'] = 1;
3 l8 @ I( L7 n% M9 _ - $my_post['post_category'] = array($cate);4 K7 ^& B, b6 U1 t1 P
- $my_post['tags_input'] = $tags;
$ b( ~3 b! s: g# G) J; ~8 Z# p+ { - //$my_post['tags_input'] = array('tag1', 'tag2');
0 I* g, Y# o8 J" T% M! m6 \ - //$my_post['post_status'] = 'future';
) n1 @3 \) g0 [# `" W; k! }3 J - ////$my_post['post_date'] = '2010-07-04 16:20:03';' [7 L" ^1 m. ^( ~, [3 a7 S" I
: [. k1 M5 c6 G* d0 a# X- // Insert the post into the database
, O9 n8 s7 F2 N0 q+ Z* d. F" } - $ret = wp_insert_post( $my_post );" `/ G; V6 L: E O; h+ H
- echo $ret;8 ]$ u4 g# d1 s! b1 M0 n
- ?>' b! ~) `! j" X: G1 [
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- . }8 y9 Q- v5 c* P/ X+ Y% [; c6 {
- <?php; e# Z. Z/ B% x* b/ J0 \
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& f& | {3 w) N, U2 z+ w* z4 U - require_once( ABSPATH . 'wp-config.php' );
$ J0 b1 F* M; M9 S; D3 W. y - require_once( ABSPATH . 'wp-settings.php' );: g) P N& m |# s; D3 W
- require_once( ABSPATH . 'wp-includes/class-wp.php' );/ O2 a: d5 `+ a$ {% U& V5 T; p9 h; ~* o
- require_once( ABSPATH . 'wp-includes/functions.php' );2 m3 k( u1 M4 K/ y# W, n
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 s z9 O+ n' N: b
- $pic_name = $_POST["pic_name"];" E( K e7 ~; P: v3 ~/ |9 j
- $pic = $_POST["pic"];( I/ K. q0 C8 [6 ]( E( f m/ J# ~: t
- if($pic != "" && $pic_name != "")& c4 w& B+ s6 F4 A7 f6 E
- {$ W/ Z& Q& d1 c
- $path = "images/";
" ^& r! D6 M S* x$ E E/ t( e0 _8 u - $pic_name = $path.$pic_name;2 F- K. }( }2 `3 x# s' u
- echo $pic_name;
; @3 ^2 z! @# c" ?" o5 o - echo "||";0 [! F) ?+ U) P1 j
- error_reporting(0);/ B; L( M" S9 x5 X- T/ y7 B
- mkdir("images");
" f4 @. W6 i! F - $handle = fopen($pic_name, 'w');& w5 T% E" U! h8 w9 L# q0 F
- echo fwrite($handle,file_get_contents($pic));1 k' i% L3 a1 k" K }' h) U
- }! }9 u' M9 T q* B: x9 J3 ?9 y" Y
" A4 j6 Q! c0 K. S5 s i ~- $title = $_POST["title"];
7 ]& C9 k) E1 g4 W( O8 Q0 T - $content = $_POST["content"];7 I, W2 T- S8 L% `
- $tags = explode("_",$_POST["tags"]);
4 b( P2 B2 ?& a1 c - $cate = $_POST["cate"];& [: b h) h. A0 b# y
- //print_r $tags;
0 U# _2 i. D! p' e6 Y" ` - //
# c( N; k6 d: ~* m- B - //
1 r j& w7 q6 U) I7 H" N' I! R5 K - $wp = new WP();* L6 ?8 c% }% `8 n; T5 p" L
- $wp->main();
5 d/ X" i9 h+ O( j: e - //* S" T( X& f P* w; r
- $my_post = array();
f a' v$ [2 t, j: f# W7 r - $my_post['post_title'] = $title;$ g, l. r3 d+ F# B/ k- ~5 K, Y
- $my_post['post_content'] = $content;2 F6 |7 F' l y" a7 N
- $my_post['post_status'] = 'publish';
/ @2 I# x; E# R$ Y5 f2 [ - $my_post['post_author'] = 1;" P& P6 z' N: L" Z$ | ?( c
- $my_post['post_category'] = array($cate);; S, \# U3 L; r2 s \8 g( t# ^
- $my_post['tags_input'] = $tags;* k( ]) u x: b7 e+ q
- //$my_post['tags_input'] = array('tag1', 'tag2');5 R1 T4 {0 m- B+ N: @% {: s, ^
- //$my_post['post_status'] = 'future';
; {# R7 _ u, Y1 p) h1 _ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, Y' W6 \% n. i% V; O - - a. F: d' G" G' t. a
- // Insert the post into the database" p4 ~- N* L& K. K
- $ret = wp_insert_post( $my_post );9 X8 d4 q5 K8 p& S! `/ {$ d4 ~) v
- echo $ret;# M- n) l+ y. C! i3 p2 s
- ?>* @# \- c9 \5 V, c; e3 b3 d3 F$ N
复制代码 我自己写的# g/ Y& l0 \6 ~$ ~) j. t
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|