|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, H% x4 i2 o) t f B1 \1 ? p2 p( e8 E* N
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. ~: a9 Q l: U: n3 c4 r6 f
3 n5 @( _; x: C6 k# y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 G' g7 T5 a; K! Q7 R& W! b! ?8 F9 q. m# [. q0 Y; g- ~
方便实用 简单 何乐而不用呢- 0 U. U; q% s, l5 [+ F k9 a
- <?php
1 k, [2 d3 q1 \! @! p - * K& N- Z$ [; {* p6 [8 c
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 ^$ |% e( ^$ F- P, X4 k# d* f
- require_once( ABSPATH . 'wp-config.php' );
6 K9 s* Y/ ^& V4 s+ v% O - require_once( ABSPATH . 'wp-settings.php' );1 y7 s1 M; X' c8 \3 y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 X: p9 s7 o f2 l: ]4 \4 P - require_once( ABSPATH . 'wp-includes/functions.php' );( s! e) {1 W. k9 U
- require_once( ABSPATH . 'wp-includes/plugin.php' );
0 A0 h. u; W5 y9 k - $title = $_POST["title"];
|: U9 t- y" s( y+ b - $content = $_POST["content"];, [, _* o0 O4 C( M, t/ G
- $tags = explode("_",$_POST["tags"]);
1 |7 t, t4 j: d( K: P1 l - $cate = $_POST["cate"];
. U, w3 w4 Z/ v. z5 c; J - //print_r $tags;/ G9 v& h) A3 s
- //
# z) {$ W; {8 i. q - //
9 O: K* @( p5 \ - $wp = new WP();( ~+ L( E" H) L7 ~7 @9 [3 r" x, i6 H% i
- $wp->main();2 Q( Y, g! j6 |
- //3 d2 H; D; k- R" ]! T1 T* Y$ y
- $my_post = array();
% m s0 z# W, j: \- x) A - $my_post['post_title'] = $title;. G$ N2 H7 W/ l. f( b3 S$ E
- $my_post['post_content'] = $content;
: v v; ]/ N+ a, \6 k2 K$ I" A - $my_post['post_status'] = 'publish';
% r# f t1 L8 v7 J5 ] - $my_post['post_author'] = 1;
) L% T* U7 i; R; O+ [: z4 o - $my_post['post_category'] = array($cate);2 i( F- c q1 i6 [# {7 @
- $my_post['tags_input'] = $tags;
' I7 M+ X+ t2 L6 P: D5 ]5 Z - //$my_post['tags_input'] = array('tag1', 'tag2');, r' X% I$ a/ A& E: @
- //$my_post['post_status'] = 'future';
( H0 r2 h4 ]- \4 x7 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, L- l$ d) b* k2 K
" q$ y8 X9 l5 B; Y g# m V% G: z' M- // Insert the post into the database
) ]% v( d5 \6 W" x4 ? - $ret = wp_insert_post( $my_post ); X9 ~% ^1 d3 |1 ~0 Y0 L
- echo $ret;7 m* Z! Q: m4 g- c# m7 o
- ?>
* a9 B& B9 b+ f" t* r6 k4 \
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
) _9 z; ~, g, F/ D- <?php# ~0 V, ?1 j6 o
- define( 'ABSPATH', dirname(__FILE__) . '/' );9 s9 W" D& |, E+ c0 R
- require_once( ABSPATH . 'wp-config.php' );0 z- T5 d5 h$ g7 I/ x
- require_once( ABSPATH . 'wp-settings.php' );: U7 J' \( I6 E7 k" l1 d( U
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; Q, W" b/ P3 _ - require_once( ABSPATH . 'wp-includes/functions.php' );
* }( v3 f5 i5 I2 f8 [ - require_once( ABSPATH . 'wp-includes/plugin.php' );5 ^& ]) w$ `# W
- $pic_name = $_POST["pic_name"];' A5 O8 c K7 u& o5 C
- $pic = $_POST["pic"];" i4 s7 b) O- s# y* V h2 ~2 r1 C, U! u9 `
- if($pic != "" && $pic_name != "")
s; t4 Z$ h: |2 t- Q - {! K* m; ~ x+ g5 m
- $path = "images/";
$ Z) P1 F [* h0 T% \! O - $pic_name = $path.$pic_name;# T# S0 L+ s, L
- echo $pic_name;
! v; b8 P# N) l9 V' ]9 T - echo "||";
/ y8 q, `. \* J, q - error_reporting(0);
$ m* z& S0 [5 _% x6 K+ n - mkdir("images");
, P. k, V9 `! a: C - $handle = fopen($pic_name, 'w');
0 K. n3 K w5 ^ - echo fwrite($handle,file_get_contents($pic));5 y) w: h- c' u4 ]; m6 x5 c! [
- }
& d, O6 [& a [: ^: C& {+ q - + a! f! U. ~0 N
- $title = $_POST["title"];
* h) S4 T8 P8 T7 t7 r3 o - $content = $_POST["content"];. w5 f7 g' j5 h) L5 h9 N d
- $tags = explode("_",$_POST["tags"]);
- ^1 k+ ?5 M& q; z5 w% i - $cate = $_POST["cate"];
7 p6 ]" e& ?* \+ L0 E5 M; d8 g - //print_r $tags;
i6 M1 X3 t! E2 [) _" ^# i - //
0 E, R1 U; r4 R: Z) u! n) T - //
' F2 d5 k% @2 ~ - $wp = new WP();
+ ~4 w$ n6 d# b) Y - $wp->main();
" d2 O7 M0 {' Y$ L2 x - //( ?! ~ {+ O3 U- v2 r2 g& T" k, a
- $my_post = array();1 ^$ o/ D7 l) y! b# a
- $my_post['post_title'] = $title;* X) s5 o, i+ V( x7 g! r- |
- $my_post['post_content'] = $content;
7 h$ T+ R3 `, q - $my_post['post_status'] = 'publish';
: f/ @' X: k1 @2 e* \0 u - $my_post['post_author'] = 1;
* p3 c6 {$ E1 x5 W1 ]2 m - $my_post['post_category'] = array($cate);
* C3 N4 P6 u, V8 V4 G, ` - $my_post['tags_input'] = $tags;2 E! e0 K6 F- M+ v2 Q8 |
- //$my_post['tags_input'] = array('tag1', 'tag2');4 _9 v7 K `. Z
- //$my_post['post_status'] = 'future';
! A8 N. G' [# d+ \# W. U - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ S) d( K- {* Z6 o8 G
- 9 e" Z) j( {" ^
- // Insert the post into the database
- W" r" g b, p, k& W! j& { - $ret = wp_insert_post( $my_post );
2 I% E! y+ i2 v - echo $ret;
: l) {, f: d5 S6 c) F0 s& a4 H - ?>
) X- b3 H1 F. h5 X7 }: {, [
复制代码 我自己写的 L/ q# X, a. P, [' }" U
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|