|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
# W% e+ Y( `: z3 ^1 k9 [ p# k& p9 N$ d1 w E
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持" _% t6 g5 v9 c$ i
$ c; J- i/ k* u$ S* q我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
# Y8 Z! a# A9 M& ?0 ~, k4 i! w, [6 s* ~" d- S
方便实用 简单 何乐而不用呢
! Y9 }5 { c8 |2 q h- ?- <?php
. c) @0 H0 x; h5 f - " C1 M9 i9 m& _4 Q: T9 S7 B- h- |& H# D
- define( 'ABSPATH', dirname(__FILE__) . '/' );( n8 ]3 G% C; A' b
- require_once( ABSPATH . 'wp-config.php' );1 d: a- S4 v2 h; y) X0 O
- require_once( ABSPATH . 'wp-settings.php' );5 p3 d2 {. Y- K! k* U+ j6 C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
& @- x% H3 y9 t5 B, ]2 s% |$ w - require_once( ABSPATH . 'wp-includes/functions.php' );/ N/ `) y: p% S& q" V' e
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% ^: O+ b$ U1 [6 [! W6 l7 | - $title = $_POST["title"];
* e) G( v. k( d+ o+ G. [ - $content = $_POST["content"];! k( `2 s" _! c! N1 E& Z& n
- $tags = explode("_",$_POST["tags"]);
4 ^. }- v0 v/ a: u ]( F - $cate = $_POST["cate"];
6 u0 S& D; l) X4 U" _ - //print_r $tags;
$ ~1 E t* k# D- I$ J% H1 s5 G - //0 z2 g1 K; @% V6 \( }0 a
- //
6 T0 K4 |3 s$ K+ P4 n8 C1 t - $wp = new WP();( K4 H: r( q/ z: [7 c8 m
- $wp->main();8 a0 x% i1 ~- ~
- //. _6 ?6 I. i. k1 U
- $my_post = array();: m; O; b& a4 x
- $my_post['post_title'] = $title;# b4 I& E' M+ b+ a& y+ t
- $my_post['post_content'] = $content;5 y3 R) _& e7 n( z
- $my_post['post_status'] = 'publish';' y* E6 _2 i- F0 b( j- Q
- $my_post['post_author'] = 1;! q4 v. f) z/ U1 w8 W7 Z
- $my_post['post_category'] = array($cate);
! w6 H+ ?) u) d. n+ C R2 j - $my_post['tags_input'] = $tags;
2 z2 a, A4 I, V8 r7 z - //$my_post['tags_input'] = array('tag1', 'tag2');
- p9 L, Y2 ~& a8 S% N8 o - //$my_post['post_status'] = 'future';1 `5 z. b- \+ j) U& K' t, h. a& q' e; V
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 E# u1 L; [7 o# {+ w& @ - 3 ? ?! T' x# f/ S
- // Insert the post into the database; C3 y# |7 B9 o& G" G# u* ^6 y: R' ~
- $ret = wp_insert_post( $my_post );4 x# C; j: Y$ t# R4 y
- echo $ret;( }- x+ Y: |6 }- I' M; `
- ?>( u- J5 g' }& f2 {7 w. t
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 i; G, S" V9 l: Q/ j" S- <?php
) B) z3 O( j. V - define( 'ABSPATH', dirname(__FILE__) . '/' );3 [$ q" n$ l+ v: b* `" X* b
- require_once( ABSPATH . 'wp-config.php' );
& z" _$ u f# l" X( ^% P - require_once( ABSPATH . 'wp-settings.php' );
$ f) s- d6 \! [, P% s+ u - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 Y2 k( R% i+ m3 _ t: T; | - require_once( ABSPATH . 'wp-includes/functions.php' );6 c m) `) s+ U5 w7 Z1 [
- require_once( ABSPATH . 'wp-includes/plugin.php' );
2 G3 {, O% K* U8 }. g1 \ - $pic_name = $_POST["pic_name"];! i: n: ^" f3 }, G
- $pic = $_POST["pic"];
4 ~" z# d8 F) y5 ] - if($pic != "" && $pic_name != "")# r- H* s. l, ]; W$ U
- {
! A9 b: V1 o9 i8 H9 H+ O - $path = "images/";
# g/ i& I E8 [ - $pic_name = $path.$pic_name;, ~% G+ j1 t: i; S$ M) f: w0 v
- echo $pic_name;6 s) X3 c* _$ Q4 e
- echo "||";
8 h+ F3 K: v. R8 i" S - error_reporting(0);
; s' A" c$ |+ t - mkdir("images");
, j2 l v* w8 M$ ?) N - $handle = fopen($pic_name, 'w');
# x( q% _8 a. q' G- L3 p3 x( e+ D - echo fwrite($handle,file_get_contents($pic));. N: Q; S4 D7 j2 T% t# ]2 _
- }
! G6 m, ~% E1 k4 x r N - : M0 Y& }5 J, h8 E! p5 t
- $title = $_POST["title"];) F+ V) `+ B% i% ^
- $content = $_POST["content"];7 B0 z- I9 e, ?/ k) d
- $tags = explode("_",$_POST["tags"]);
" U: p# S9 n+ ^; k- {+ i. Y; W - $cate = $_POST["cate"];
! _' @% U6 b, P9 ] - //print_r $tags;$ c# S% {6 p2 U* p o( t }* P
- //
- A- F( R7 M* D, |2 P - //
Q. }& p, w; s3 q4 V - $wp = new WP();
/ n7 q( K! @7 d, y - $wp->main();
: p& x$ G3 A, G# L' }' b* E - //$ Y: L, }$ d5 J: r7 F& y) @$ m4 J
- $my_post = array();
7 v0 B$ M5 R0 p! I0 w - $my_post['post_title'] = $title;
3 U& l1 \; f; l: u - $my_post['post_content'] = $content;5 y+ y) T% F' k7 q' \; }& z
- $my_post['post_status'] = 'publish';
) L: }+ Q3 F( Z8 |) Y; q7 e( q9 j4 O, i - $my_post['post_author'] = 1;, D: {- B4 l- o2 W4 d6 P
- $my_post['post_category'] = array($cate);
" d; N" Z4 L6 \! Z! X - $my_post['tags_input'] = $tags;
* b7 c+ Y' j9 J9 l( X1 p( K - //$my_post['tags_input'] = array('tag1', 'tag2');* ~# B: [ l9 t
- //$my_post['post_status'] = 'future';
% z9 r% r- N% T& y - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 u" h% G- Y/ M' j
4 [9 ]- C2 ?; L- // Insert the post into the database
7 s% |! Z+ X! C8 B - $ret = wp_insert_post( $my_post );
. D; k6 @& j/ G8 z; c - echo $ret;
3 \% Z5 {. Z8 b& T! r - ?>
8 r6 ~( Q1 s4 y* U* s& r8 J* r, Y
复制代码 我自己写的
; r8 h8 r/ Z7 r4 S! B插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|