|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 - L# c2 X: e' ^/ ~/ y6 ~
- c6 m3 G1 x G# L9 D
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 ? k5 Q$ X2 z& r; W; @6 j' W
% d/ T2 \/ X5 l. c8 G( D我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( U4 ^/ k- v8 s0 K6 \4 F4 B5 X- ^
( J0 Q7 y& {" O, |3 T. }
方便实用 简单 何乐而不用呢
+ d% R8 \' n8 i1 y+ } p8 G- <?php
4 H; V& I1 z6 @
7 s7 A% \6 S0 {+ q- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 Q5 _: a) \8 F- } e- B, o+ T - require_once( ABSPATH . 'wp-config.php' );
% H2 q" Z& W/ t8 ]# o# R* f - require_once( ABSPATH . 'wp-settings.php' );! |( x5 P5 v# j$ o( d
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 ?0 {/ Y. `! M, A0 r2 h+ J4 l - require_once( ABSPATH . 'wp-includes/functions.php' );
3 j+ J5 S3 }1 `* \8 j7 Y1 F - require_once( ABSPATH . 'wp-includes/plugin.php' );
z1 m+ [+ N/ Z6 y y" ? - $title = $_POST["title"];
+ l# O' r( f4 m0 D - $content = $_POST["content"];
1 Y' {+ N7 ^/ O' S- X - $tags = explode("_",$_POST["tags"]);4 S0 ?! Y7 F, \+ S+ c9 O$ e5 F
- $cate = $_POST["cate"];
$ i1 ]' A* u- x2 k1 @/ h. l - //print_r $tags;8 C/ d1 h" [+ k3 Q+ _
- //" {* A: W5 Z" D9 m; c. Y- p2 c
- //
0 ~' A1 t! N4 R8 e - $wp = new WP();
* \3 g M: Q' |3 u - $wp->main(); c* F$ l2 \, N& T" f
- //
) p4 d" X* y6 p4 n - $my_post = array();5 P6 E/ j$ s1 B7 S
- $my_post['post_title'] = $title;& u' B- L* ]! g8 D7 V
- $my_post['post_content'] = $content;
( f) y- L! C) {. Q7 ^& T - $my_post['post_status'] = 'publish';
2 e# s& u, S" K; q8 ]1 U7 d. v - $my_post['post_author'] = 1;9 P! F, K& |6 [: w
- $my_post['post_category'] = array($cate);( O- y6 V% ]1 T% e, G1 P" p& _
- $my_post['tags_input'] = $tags;
& T% q! {! w1 k6 K. e8 k - //$my_post['tags_input'] = array('tag1', 'tag2');+ Z! e# R% }8 z o
- //$my_post['post_status'] = 'future';, B- g6 D8 W6 {! e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
. `# g1 Z0 p' ?
% E$ q$ `# @5 { j& ]; @# @* l- // Insert the post into the database
- S7 d7 r4 p, L( Y' s" C - $ret = wp_insert_post( $my_post );* N1 e1 C6 w6 l) g6 w( Z* \# R
- echo $ret;
& Y) Q5 |6 y2 L$ K - ?>0 x+ s+ ^9 j/ K- [" t) h* F) D# s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, N0 T" |8 x, I; C4 L# `- J, v. l# z- <?php2 X: j$ [: \! K4 g; L( v& e! F
- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 u+ s4 Q3 k, C; G - require_once( ABSPATH . 'wp-config.php' );
G$ X) f( X; m7 S - require_once( ABSPATH . 'wp-settings.php' );& g* W( B; a3 R% n2 q' m+ G! S
- require_once( ABSPATH . 'wp-includes/class-wp.php' );. H' g" c2 e7 B! A F/ F
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 g# D% Y9 L. @ V - require_once( ABSPATH . 'wp-includes/plugin.php' );# ]5 `' ?, i) {- H/ t6 x+ o v
- $pic_name = $_POST["pic_name"];
; r; q% H& v9 S- c - $pic = $_POST["pic"];
/ W9 C1 X1 M* L" x8 x* p( d' O - if($pic != "" && $pic_name != "")
5 C4 d& x* c. Z( s7 W! [5 j - {
. j* k6 F* ~1 N) S+ C - $path = "images/";+ ^1 j4 {3 ~! i! h, z
- $pic_name = $path.$pic_name;5 \7 K" e9 L/ \4 M9 z
- echo $pic_name; N6 O' c: W9 p4 Y: W, ?( z0 C
- echo "||";
& ?+ o5 [+ u, p2 |3 b5 J - error_reporting(0);$ [7 H% y* P/ P& X6 D
- mkdir("images");
$ w, A w& }' T N, N/ [% y8 d: G - $handle = fopen($pic_name, 'w');; T4 k( O& m) c+ n$ a2 N
- echo fwrite($handle,file_get_contents($pic));
0 q8 p l% o) Q0 f - }
2 j8 p! V- u" L4 g - " T D% h7 ?" p
- $title = $_POST["title"]; _% E. N9 y" a" s- l p! h
- $content = $_POST["content"];
: n5 ~& i# k9 _) I8 K P3 L - $tags = explode("_",$_POST["tags"]);+ Z" z9 m0 N* ?( o7 T1 l
- $cate = $_POST["cate"];: |9 p8 \* a9 M' I. z2 k" C% Z
- //print_r $tags;& f$ V9 Z& f; V S
- //
! ^& `# z( G+ c& O0 v* x - //$ [: c( V9 M5 h `
- $wp = new WP();
1 n' q0 c% n8 _9 f0 {5 N+ L6 D - $wp->main();
1 ~: q* D2 ^% U& u7 [ - //
. O: b& [' u5 {/ A - $my_post = array();
+ ~) d% |2 e' I - $my_post['post_title'] = $title;
% h8 Q4 G' w2 a7 [, Y6 D: h% W3 n - $my_post['post_content'] = $content;
, D3 E- N/ M( V2 E* H - $my_post['post_status'] = 'publish';1 l# G& ]* Y" L: B J) m
- $my_post['post_author'] = 1;
# @( E, m. s" b, P& x - $my_post['post_category'] = array($cate);; y. ]* R* t/ W
- $my_post['tags_input'] = $tags;7 d6 ~' |; t! x2 K- s
- //$my_post['tags_input'] = array('tag1', 'tag2');
. W) f, B |+ `8 l0 U - //$my_post['post_status'] = 'future';
$ _- f3 b0 Y' e% X# j - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 X/ r( o" H$ a" i5 V P! G4 K" J
- " L% D8 R: W& y$ f i" T2 a
- // Insert the post into the database
_ C8 p( l4 C$ z$ F5 q - $ret = wp_insert_post( $my_post );' T" c/ b! l7 t, U" }3 L
- echo $ret;
0 f* B1 {3 p/ q: ~. j/ A9 _ - ?>, Q' y' h4 b* M( I9 l
复制代码 我自己写的
" h' r+ v' _# S插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|