|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, j, n% I$ g, _# X" ^* y# [4 C A4 {1 r8 m) x0 L; i: u
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 P! ]3 g+ n; {( U0 a* d
b+ e U- j; o我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
% T+ y" e1 `, i. K# H2 ~! H0 E R
3 E g* t& b& ^0 B7 `* a9 ]方便实用 简单 何乐而不用呢
$ C5 V, K" G, Z6 L, G, l5 h. B- <?php# t q& J: m; y0 X# A3 s' I, i
; k" h8 ^) `2 ^4 a; z. }3 B/ y& {- define( 'ABSPATH', dirname(__FILE__) . '/' );
) ^* ~5 A! v8 r; V; n3 @: c) K - require_once( ABSPATH . 'wp-config.php' );
# m3 Q- k, c! A& N, e9 n - require_once( ABSPATH . 'wp-settings.php' );* l: d7 K. j2 E; ?9 S9 s. j9 m
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 o4 ]! u6 }4 h0 r; y6 k6 V - require_once( ABSPATH . 'wp-includes/functions.php' );
# V$ ?4 c4 {- o - require_once( ABSPATH . 'wp-includes/plugin.php' );' f$ D9 l( K- g3 X- ]
- $title = $_POST["title"];/ r+ ?5 f. G- k. Q7 x. b
- $content = $_POST["content"];3 o: q. b. J4 a% A5 q9 D K( @7 s
- $tags = explode("_",$_POST["tags"]);6 U; t4 G; A5 [# G5 v, f3 ]
- $cate = $_POST["cate"];
, `; E+ \4 q+ E3 D7 p; q - //print_r $tags;
' ~ Y7 m4 G8 }4 ?5 T - //
' b# p9 n4 V. P9 o - //' K2 x- N) `. {, V5 ~
- $wp = new WP();
$ v/ H$ N& |/ r3 m- F' X - $wp->main();
9 A, E {" _4 Y0 l, s }2 e" ^ - //6 u% ^/ w/ p$ z* f/ Q! Y6 s
- $my_post = array();# ]9 [4 o3 j1 J1 W$ @ q/ f
- $my_post['post_title'] = $title;
5 F& i8 U8 V" ^# E- A) X& C0 Q - $my_post['post_content'] = $content;
- S# w9 m' u3 T! c: n - $my_post['post_status'] = 'publish';8 n% b) O1 p: Q1 R- Y
- $my_post['post_author'] = 1;+ i9 i$ a, C) j$ t( q! z' h: ~9 o7 n
- $my_post['post_category'] = array($cate);
+ S+ \; V$ s! j$ u; E7 T1 c! f' } - $my_post['tags_input'] = $tags;4 D9 P% P2 A' K3 `* e! h! ~
- //$my_post['tags_input'] = array('tag1', 'tag2');
@! c8 X. @4 n& Q - //$my_post['post_status'] = 'future';' u! d0 t2 c' ?; a
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 O- O2 t4 R6 N% `+ F
5 m5 w; e6 K8 q9 c3 y1 w Q- // Insert the post into the database8 d9 E, q; A( p, C' }5 `. M
- $ret = wp_insert_post( $my_post );
& X: v$ }/ U i m' V - echo $ret;
( D( [3 d- K4 x! j! b; f - ?>
7 V. @2 ^- ]3 T e6 s" s ~7 W W
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 X T( {# G" q3 D1 k& M- <?php
- |0 o+ b" g! k* {: {. t - define( 'ABSPATH', dirname(__FILE__) . '/' );
3 g6 ~# l7 r' J" p# C# f - require_once( ABSPATH . 'wp-config.php' );
* U$ R) ^& a. d3 i6 h2 ` - require_once( ABSPATH . 'wp-settings.php' );
% s- m- O. v/ o' E. I - require_once( ABSPATH . 'wp-includes/class-wp.php' );2 Z! s4 u, I3 ]% u7 [
- require_once( ABSPATH . 'wp-includes/functions.php' );
' P( p2 l% R3 u% Z9 _ - require_once( ABSPATH . 'wp-includes/plugin.php' );
1 }7 C2 `! t- m0 S - $pic_name = $_POST["pic_name"];2 _$ g$ b$ C1 r! c* O1 z
- $pic = $_POST["pic"];
: g9 P/ `+ Z: N# i - if($pic != "" && $pic_name != "")8 I$ p9 J0 ~: Y1 E
- {
$ u+ ^0 Q+ F/ V - $path = "images/";9 `9 r& R) o9 [( d
- $pic_name = $path.$pic_name;0 ^, o5 @* @) q5 c: `
- echo $pic_name;! r( T! ^" w8 V1 a$ G u
- echo "||";
3 m6 d) N5 w/ z' r. S4 r6 j9 W0 _ - error_reporting(0);8 P* j2 D) `5 `+ V, W, I; Y
- mkdir("images");& X: n. b4 r6 u/ J
- $handle = fopen($pic_name, 'w');( G1 T2 l1 h' N( G
- echo fwrite($handle,file_get_contents($pic));( G# }' K# ~. w. B0 @1 A
- }
% y2 d1 P: S6 k9 H" ~, {1 j$ d
: ?. ^7 w" y( y2 ~ d' r- $title = $_POST["title"];
4 @' k4 g) z1 d3 f( w; Y - $content = $_POST["content"];* ^) m; r4 e8 A+ L: u& _( w; U
- $tags = explode("_",$_POST["tags"]);- X7 k S4 c- n" m5 g& e
- $cate = $_POST["cate"];
: t1 B4 \! R, i5 P! b4 ] - //print_r $tags;/ }! J, X6 ?* G8 l
- //
' ~* u1 ~: w9 ]5 S - //, ~) p* I. j, g$ l: r; G
- $wp = new WP();
* m7 ^% S# k+ v& I - $wp->main();
& z+ C' P( F! L - //( w. X9 p; I3 k- Q2 E
- $my_post = array();
- M! ?0 J! Z$ s; F2 V' M+ H' U - $my_post['post_title'] = $title;
7 ^. L8 W4 P9 G& N: y9 { - $my_post['post_content'] = $content;( C( r' y# V6 X- O Q
- $my_post['post_status'] = 'publish';" v7 F" \3 H0 j: Q; e/ |) j4 l2 V
- $my_post['post_author'] = 1;3 }7 E- E0 W2 @8 r/ B( i5 l
- $my_post['post_category'] = array($cate);4 \; `, U6 z5 s3 N# t
- $my_post['tags_input'] = $tags;
5 M# {, K3 C O0 }! y% f - //$my_post['tags_input'] = array('tag1', 'tag2');% g/ j) c' R- w3 w# _: W
- //$my_post['post_status'] = 'future';
4 T0 T" P+ J; b0 } - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ k% V- I z K( H ]0 m m. F
$ A9 p$ p( j2 Z) b9 l- // Insert the post into the database9 P; Y u v! |. K& i
- $ret = wp_insert_post( $my_post );
- q" ]( o- Q, Y2 | - echo $ret;1 O; q! @/ ^9 ~' ~$ W P! u( j
- ?>6 U1 ~9 @2 H$ t6 d
复制代码 我自己写的) V# c! H/ Q2 K& J$ @. O+ N& Z
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|