|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 j8 c( w7 l1 m9 w6 }% e$ n5 A
4 ~% b L4 x3 }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
" F2 k0 T, B7 Y
8 R& s0 p5 }; l) g我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了0 ]) F" S: }& ^' C
" N4 a4 _( W0 _; c1 A方便实用 简单 何乐而不用呢
" G5 T% [8 M0 {+ F, A- <?php' n* v0 |8 Z9 k& [2 U
& I) Y* K3 u# s+ ~! ^# S0 K7 X- define( 'ABSPATH', dirname(__FILE__) . '/' );8 `: |2 r0 G, ~
- require_once( ABSPATH . 'wp-config.php' );/ G3 |, M, l! L3 b
- require_once( ABSPATH . 'wp-settings.php' );
" {3 f1 i+ m- g5 o0 s; ~9 R - require_once( ABSPATH . 'wp-includes/class-wp.php' ); Q% A2 x1 |, p7 r5 P) E; Y: V
- require_once( ABSPATH . 'wp-includes/functions.php' );+ ^& M: M" W3 W; e3 ^5 R& X7 S
- require_once( ABSPATH . 'wp-includes/plugin.php' );
8 |5 R$ F5 E! j - $title = $_POST["title"];
) K6 L4 ^( _% `& v2 i6 ~ s* _: K# X: S - $content = $_POST["content"];
; G' A& g( w. o% G - $tags = explode("_",$_POST["tags"]);
) J& s$ @& ~+ d0 O9 s+ { - $cate = $_POST["cate"];7 W1 G* A. Q7 m# b
- //print_r $tags;
9 c3 H& \# ~) D - //* o! B, ^, [( h$ G6 P5 u; z
- //* }2 x) J: `+ v. O* c
- $wp = new WP();
" W+ z; x0 a# }/ I) O8 h) } - $wp->main();5 k# I* P$ z8 ]( m! l f
- //
: ~. |& C F4 L8 X4 v& k' M - $my_post = array();
! C2 n) }0 f1 C# h - $my_post['post_title'] = $title;. }& S4 F. D" R0 _! x: y
- $my_post['post_content'] = $content;
7 Z1 \8 g0 `4 |. c" y - $my_post['post_status'] = 'publish';! x: {% @8 Z. h
- $my_post['post_author'] = 1;4 n. ~+ V! [! s* r% {# T9 u! a* u
- $my_post['post_category'] = array($cate);
+ Z2 O3 Q+ ]9 G; ^ - $my_post['tags_input'] = $tags;
: z7 ~! G+ h$ U( b5 V - //$my_post['tags_input'] = array('tag1', 'tag2');+ k, n+ Y1 o$ F* w4 r) e
- //$my_post['post_status'] = 'future';
4 j, ~. h- |0 j; t8 a! W- r - ////$my_post['post_date'] = '2010-07-04 16:20:03';
& s# R0 V! v$ E1 ?
% y0 w3 x3 b2 S- // Insert the post into the database3 }( M. c' I# S1 k& G
- $ret = wp_insert_post( $my_post );
9 Z/ C2 }* r5 d* A- V& |; e - echo $ret;1 F1 L8 A3 l7 s" I/ E2 L6 }$ E+ D
- ?>* f; f$ C7 t) n5 w* [( ?
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + V0 l% X% }% K
- <?php
/ M5 q6 _4 |8 N2 Y - define( 'ABSPATH', dirname(__FILE__) . '/' );5 _' S+ h* S" y* E
- require_once( ABSPATH . 'wp-config.php' );% }+ F) _* w6 `* O! \
- require_once( ABSPATH . 'wp-settings.php' );
- f$ \- Z* n/ ^8 ? - require_once( ABSPATH . 'wp-includes/class-wp.php' ); s9 y, Z" [& K! E/ h$ F! G
- require_once( ABSPATH . 'wp-includes/functions.php' );& B4 L! G; r0 j
- require_once( ABSPATH . 'wp-includes/plugin.php' );
8 m' p" p5 L! X; h. C - $pic_name = $_POST["pic_name"];+ ?' ~; t& ?+ Q. Y6 {! U* E
- $pic = $_POST["pic"];
$ Q! e1 d7 x- z0 Q - if($pic != "" && $pic_name != "")
8 c8 S7 B+ a' f' n - {6 ]* ^4 B2 I: T
- $path = "images/"; K" g' B2 W! g) \2 T2 n
- $pic_name = $path.$pic_name;% @6 b! Z# _' @; `% u& r+ c4 A
- echo $pic_name;4 V; T6 U/ d2 W& a3 X2 k* Q- q
- echo "||";
3 s7 S# V0 E( H' h) S& D. V - error_reporting(0);
5 B, w9 Z& ]& }7 A6 N0 | - mkdir("images");
& ^% q: e! O& Z. a) ? - $handle = fopen($pic_name, 'w');% [. Y( {, ~! c: \% k
- echo fwrite($handle,file_get_contents($pic));
9 W; C1 N$ s/ @0 F. d/ f - }
! M& f, j8 ?! }) q! u# D
3 K A, s) } J5 `' Y; ^- $title = $_POST["title"];
2 T5 Y3 v/ F2 O" X6 x/ l - $content = $_POST["content"];2 _. @. @6 E% p* \4 X2 ]; J) f8 m; |
- $tags = explode("_",$_POST["tags"]);$ U6 x2 [- b5 p' X. _& m
- $cate = $_POST["cate"];. s# o5 H& Q% s P$ I
- //print_r $tags;/ X/ A0 d2 P2 ]/ {) V r
- //
% ~6 J, }* }- f - //
3 b( f' s8 q) R# B6 L' B - $wp = new WP();
6 B% f7 U3 G. O5 T4 N. `+ M - $wp->main();
0 ?: a8 n- f7 B$ X# ^3 c# v - //
3 A6 O* J, S; P; K - $my_post = array();
% T: E7 c3 Q& v& U4 R& @: M* v - $my_post['post_title'] = $title;$ U- y2 m( t3 W) m- I" E
- $my_post['post_content'] = $content;3 A' g2 H i8 E/ v* D$ W! ^
- $my_post['post_status'] = 'publish';
) I T3 z" z- y4 P/ \" j$ N - $my_post['post_author'] = 1;
. O/ |& y6 z5 k, s/ [ - $my_post['post_category'] = array($cate);9 y' r2 r4 ~+ q+ D7 u, }
- $my_post['tags_input'] = $tags;
- i5 `4 c7 x. l. o0 d, i - //$my_post['tags_input'] = array('tag1', 'tag2');
4 i5 @+ r. A. }" W - //$my_post['post_status'] = 'future';
- Y, l X: F+ _9 E* G# h - ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 t y" K2 ^/ h% G. |' j - * n. G0 V' c4 B: D/ I) X3 J' k# Q6 }
- // Insert the post into the database
X; q, V% c) b h% \2 N - $ret = wp_insert_post( $my_post );
% Z. L4 U% V9 F' ^5 P9 v0 u" P - echo $ret;
/ Z7 j/ {' C# h0 Q1 l* E - ?>9 w* O) M2 O6 ]$ S$ y
复制代码 我自己写的
) Z5 K. Q+ S0 Z* p* k- }插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|