|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
3 J1 G6 g6 J% y( T' G6 K7 D+ F& f6 _; E3 A$ F) C- h" T
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持' T* j$ f4 `- {0 S% ]
, U! M1 i; g; B% e
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
3 c7 T$ ~) l) ~& ]3 b
4 z/ n' Y$ b0 O. A2 g方便实用 简单 何乐而不用呢
2 @* a3 @) y: I* A) n! k- <?php; f2 D8 h% ~9 v* m
- 8 Q* h) i* t( K* G+ D
- define( 'ABSPATH', dirname(__FILE__) . '/' );
" v1 G; I8 s W+ P0 j2 j - require_once( ABSPATH . 'wp-config.php' );- d+ o5 ~4 P0 c- X% @' \8 }& d& T9 S! |
- require_once( ABSPATH . 'wp-settings.php' );
* y( l& M. G7 R5 C - require_once( ABSPATH . 'wp-includes/class-wp.php' );: |( Z# t a5 H( [
- require_once( ABSPATH . 'wp-includes/functions.php' );
M8 R d$ W* c3 `$ A5 h( P: t- F - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ ^6 @& S( V) }7 Z# ^8 b - $title = $_POST["title"];, A1 N3 f$ U i
- $content = $_POST["content"];
" |# `! K9 v: \, m& j. _1 ~8 { - $tags = explode("_",$_POST["tags"]);# w W5 B9 D6 U# f8 T7 x
- $cate = $_POST["cate"];
4 d; f/ T, Y- X" Q7 O8 y! L6 L - //print_r $tags;
Y' \' W- u/ H% X8 W, O3 V - //
7 G( v/ J" k5 N; p; h- G @; a - //
7 Q/ Z4 n! |7 N - $wp = new WP();1 C6 m5 p) c* e$ b4 P+ B1 g& D
- $wp->main();
' F, Z2 ]8 m) o( }% Q - //
! V* D9 F ?' t3 t9 } o$ x - $my_post = array();
6 \( E" |5 s8 g# X) W6 p9 Z3 |& P - $my_post['post_title'] = $title;
+ z4 V a8 V: E6 O" k! s; \ - $my_post['post_content'] = $content;
' d! F3 o* B$ j4 X" y - $my_post['post_status'] = 'publish';2 y n/ [4 x; @. ^# O: }: y
- $my_post['post_author'] = 1;
* H" y1 O- o& x; }6 [) K/ }2 @ v. B - $my_post['post_category'] = array($cate);
3 C' d9 g5 a" r9 b4 y$ s - $my_post['tags_input'] = $tags;
. j( \# J3 o4 G, ~8 [% y - //$my_post['tags_input'] = array('tag1', 'tag2');- `; V+ o/ `* _6 i- U
- //$my_post['post_status'] = 'future';* k% Y, f2 L" {* B! F
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
\1 P5 g7 b2 o& { - & G" r! Y7 i: m% R1 m
- // Insert the post into the database1 u! c3 v0 M+ e* `4 A3 e
- $ret = wp_insert_post( $my_post );
. G* m0 N% e6 X5 s% Z" G - echo $ret;
& N( w0 C; s; Z - ?>& ?2 l) v. G/ S* }5 u2 j
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
7 a2 Q# O9 t- j2 K0 z- <?php
& R$ W6 j! J. E; b* W; X - define( 'ABSPATH', dirname(__FILE__) . '/' );8 \8 `! y% ^, L: ^% ]' c
- require_once( ABSPATH . 'wp-config.php' );
2 ^3 F A/ H: U, G3 [( K F* \/ G; ?" c - require_once( ABSPATH . 'wp-settings.php' );
' y e# a' s+ K$ s - require_once( ABSPATH . 'wp-includes/class-wp.php' );
! _, F% p* y* Q7 g) @ - require_once( ABSPATH . 'wp-includes/functions.php' );
) }# r# W h8 `0 ^$ ~! \ J - require_once( ABSPATH . 'wp-includes/plugin.php' );
; Z H1 W( b9 A H - $pic_name = $_POST["pic_name"];
+ N! p, t& r# g; { J$ | - $pic = $_POST["pic"];) t# E) s& z7 d* j
- if($pic != "" && $pic_name != "")$ ~2 K' F: j# C
- {
2 c0 r! N( v/ w: L+ \, D - $path = "images/";
- I, Q y# p* [ - $pic_name = $path.$pic_name;
1 P6 i8 y& j0 L; n/ L. O - echo $pic_name;
v! K$ k. x+ ]/ Z6 ? - echo "||";% {, X! m* B. D3 I5 V
- error_reporting(0);
1 n, ~! X g' u - mkdir("images");
* j) k) ?" d* q" k1 ^ - $handle = fopen($pic_name, 'w');6 h6 D& @, C, R% h. }
- echo fwrite($handle,file_get_contents($pic));: v' m$ t+ ~) j2 V0 a- G8 O- c( L
- }
- ~. z0 w; w6 I6 r, N3 K: X
7 A& w n7 ~& j, j$ U. K8 W- $title = $_POST["title"];
: i$ O3 {- Q) L$ ~, Y' O, u - $content = $_POST["content"];
0 }: N& R! P) y! u9 C9 C - $tags = explode("_",$_POST["tags"]);
9 ?8 H# c& H. o6 t+ u8 e: n) h - $cate = $_POST["cate"];7 f" Q- S3 ?" _; }
- //print_r $tags;
8 l5 ?( t7 w8 J8 ^! B - //+ w& E5 o# k3 a, H/ I+ O9 W
- //: ~, a( ?1 F1 Z* y1 J+ J$ }
- $wp = new WP();0 j3 h M, o. ~) R5 L0 @! |: v
- $wp->main();* |: ?. g9 A# X" ]( x4 Y
- //
1 a. t5 L. B4 Z0 ] - $my_post = array();
$ y8 p. }* _. Z4 g4 x - $my_post['post_title'] = $title;! \8 T- m8 `0 t* ]& a) Y
- $my_post['post_content'] = $content;
/ [6 w3 p- O: @* `) T4 Y5 Y - $my_post['post_status'] = 'publish';
0 t$ y7 N/ N1 V - $my_post['post_author'] = 1;' D% J, \& ^" X; V. M
- $my_post['post_category'] = array($cate);0 P0 p, v+ P+ b' P$ c9 W5 Y
- $my_post['tags_input'] = $tags;2 T6 a4 P4 H9 ]
- //$my_post['tags_input'] = array('tag1', 'tag2');
\! Z2 |6 b: D# v+ ?. l1 @ - //$my_post['post_status'] = 'future';1 {7 M% c6 J8 \, Q
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
" K, [ Q2 v! U8 I7 Y# l - 1 a3 C s6 {# c
- // Insert the post into the database
* W: t8 ~5 m: Y1 E+ t - $ret = wp_insert_post( $my_post );" E$ b/ Z" h7 l9 R3 }$ }
- echo $ret;1 k$ h) C9 h2 ]
- ?>+ a, A% a) F8 w
复制代码 我自己写的
4 Z& [, {* _2 K! ?( b# s9 T插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|