|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
: t. ]- |, N% k# s% N M& P1 ]+ P1 c' ~. K. l
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
K' o" w/ q7 C+ X/ _: q+ r& N& | |5 b! M8 a7 h, \. c
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
G9 F2 V4 B% Z1 s& q; F
9 L; E! @' I# r" N方便实用 简单 何乐而不用呢- 6 F& s, D7 i* _5 C% v9 _% S
- <?php6 g' n9 O3 z! N1 _) s" f
! b' d4 |& A) [' v- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 ~; \) n8 c) @* Y" Q, M - require_once( ABSPATH . 'wp-config.php' );
* Q1 X6 V% H2 ^# z1 a" w - require_once( ABSPATH . 'wp-settings.php' );
8 b( r. [8 }# M - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 g6 N3 U7 b) K$ U7 z8 q
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ N! h* Y! o7 X* A) H' u - require_once( ABSPATH . 'wp-includes/plugin.php' );
6 }0 X7 z! I/ y4 `& l - $title = $_POST["title"];
) O. [/ x7 s" r" C" t9 \7 {" h - $content = $_POST["content"];1 a; L+ x5 ~/ ?$ \& V! @) b
- $tags = explode("_",$_POST["tags"]);" k) e. Z5 w. i- i% ~- H
- $cate = $_POST["cate"];- o8 V: ] d5 |' y# }6 p/ S- Z2 `
- //print_r $tags;
6 ^* B, k0 [9 M4 q5 u3 L8 }9 P - // F z3 Q% R \
- //
- H+ E0 O Z, \ g, i - $wp = new WP();9 s7 |) s8 s* ~+ @# n
- $wp->main();
0 y D. J1 h, o+ g' ?; R$ x' o - //
9 S2 N4 {0 y8 c+ I3 k+ s - $my_post = array();
4 Q: A6 d* f( ~' ~0 S, C7 N" ~ - $my_post['post_title'] = $title;% N3 [( @# C g. [0 f+ @' L; z* C2 p
- $my_post['post_content'] = $content;' _- a4 W* ?0 ]1 M! u% P& D2 @
- $my_post['post_status'] = 'publish';' y; W1 ]+ ]' R+ @4 E. s P# a
- $my_post['post_author'] = 1;6 Z- m2 {( J5 T" Q
- $my_post['post_category'] = array($cate);5 Y4 m0 V0 ~2 {# G4 \7 `
- $my_post['tags_input'] = $tags;
J8 k: O; V1 H" T4 o7 r - //$my_post['tags_input'] = array('tag1', 'tag2');8 }, W7 ^3 h, \
- //$my_post['post_status'] = 'future';
; ~! t1 E8 u9 k" u7 d6 B - ////$my_post['post_date'] = '2010-07-04 16:20:03';* t8 ^; H2 V1 Y2 y4 H4 ^
- 1 [/ i0 @7 M4 i9 ?/ q
- // Insert the post into the database
$ N0 s; j3 k1 w* V8 D$ j: F - $ret = wp_insert_post( $my_post );+ a, N3 n9 m8 Q5 [% H# x8 b% \& o) S
- echo $ret;3 _! x9 X' a2 o% ^ m% Z
- ?>
" b6 i# T0 V9 K5 y* q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & v2 \$ G" _' p* u6 |3 f
- <?php) \3 h" J! o) ]# ]/ o
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ A5 W! r3 a# C2 u) B$ V - require_once( ABSPATH . 'wp-config.php' );" W/ J( K4 P: J3 `! b
- require_once( ABSPATH . 'wp-settings.php' );- c$ F4 R; C" J
- require_once( ABSPATH . 'wp-includes/class-wp.php' );5 V4 J, q, S( J! e" a1 |+ ^: ?3 n
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ ]+ s. o8 p4 w: Y - require_once( ABSPATH . 'wp-includes/plugin.php' );
; r' g4 y, W: H% e: ] - $pic_name = $_POST["pic_name"];) i) W( O; X7 ?* p9 i; F
- $pic = $_POST["pic"];7 k, L4 W! X' k" K4 t1 R" A
- if($pic != "" && $pic_name != "")
# \0 a/ U1 j W- `5 J s& {7 ` - {
9 h9 B; @2 U. p, `1 i% J - $path = "images/";% O9 I$ i$ K; Z" r$ V
- $pic_name = $path.$pic_name;9 ]/ U; p8 q1 q
- echo $pic_name;
( e h b. g5 q0 T' O0 I - echo "||";9 u. p% U8 T8 j+ I3 M) s9 M
- error_reporting(0);9 P( r. q! R J5 X: w! n4 @* M/ j/ J
- mkdir("images");& B1 b+ n# q9 E. [
- $handle = fopen($pic_name, 'w');
! d( f3 e- ]+ k3 u$ ] - echo fwrite($handle,file_get_contents($pic));" z7 }' L: w5 {& j! F, I) c) u
- }
) D* W$ x+ z( Z7 P# S# W - $ c$ j& V: V: i( g5 q' O, m2 D
- $title = $_POST["title"];
a. n7 k+ a: |2 v3 k! T4 x - $content = $_POST["content"];
( R7 J$ I2 p* ~. X+ c - $tags = explode("_",$_POST["tags"]);
3 p9 `( V5 J3 T6 M - $cate = $_POST["cate"];* @. c/ n% v$ K; N" h
- //print_r $tags; Z& }/ m- _& Q) O. K' ]' n8 s
- //- ~7 c" f9 A# `: V$ l: ]) [
- //6 t! k$ ]1 i* G/ j
- $wp = new WP();. @- V2 H3 Z: L+ I+ Q
- $wp->main();+ f/ G3 n0 f5 J8 ?8 P
- //
- z( k( e! q7 o; g4 |+ o' B% {4 j- P- c - $my_post = array();& U9 T2 M5 f" }2 I3 h8 D
- $my_post['post_title'] = $title;" q. s3 C6 Q* h" b: @5 L! b8 R
- $my_post['post_content'] = $content;
( z x+ p( F G2 v5 Q2 b& \8 ~. t - $my_post['post_status'] = 'publish';
( i+ j: z. }1 l7 ^' W6 j - $my_post['post_author'] = 1; [ N6 a8 i8 {- d! ?
- $my_post['post_category'] = array($cate);
$ H7 a B# D0 P( g; ~$ n1 ~ - $my_post['tags_input'] = $tags;. a1 g) [) \1 |7 e( E% b
- //$my_post['tags_input'] = array('tag1', 'tag2');* \- i; n4 u4 f& v
- //$my_post['post_status'] = 'future';2 v8 ?0 y9 }; ^) f+ m# n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 T# D/ F+ @: P# @0 T) c' q - 7 n! \* L# l$ Q7 R# g! ~7 m$ @
- // Insert the post into the database
" X% f& J% m3 ]( K3 k; X! ^# ~ - $ret = wp_insert_post( $my_post );
% T, J( \0 s |# |" f - echo $ret;
# I5 A* B* _1 Z - ?>
! J+ @; g! t6 p$ H% {
复制代码 我自己写的
0 b" V: L3 _$ p- ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|