|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ( m8 z: S7 z* |) H
3 s4 A# i& ~) x
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持& e4 O+ G) d4 |! p7 Z# Y
2 ^% T) q9 Z, p- n我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
4 d- L6 t7 s4 ^* g0 `! ?4 S
2 Z/ r. Z* k( g7 y方便实用 简单 何乐而不用呢
4 g$ u, f8 I3 o1 s- E$ z, F- <?php
: K9 |; i$ [6 V; C) p, S) q: I1 {
4 {! l3 X" c8 H/ S# Y' _- define( 'ABSPATH', dirname(__FILE__) . '/' );
' s- E2 e6 \1 N" h Y" s# q { - require_once( ABSPATH . 'wp-config.php' );
% g5 e3 B4 `8 g4 O8 { - require_once( ABSPATH . 'wp-settings.php' );9 [9 S8 U7 C9 b& P5 V
- require_once( ABSPATH . 'wp-includes/class-wp.php' );1 k% |) y+ g7 O- y: S3 D' K, V0 H
- require_once( ABSPATH . 'wp-includes/functions.php' );
. g9 x( N& s/ g1 E o: n - require_once( ABSPATH . 'wp-includes/plugin.php' );
' t1 W0 Y( O/ R+ H' T - $title = $_POST["title"];9 O q% a1 G0 j* j" L% c v
- $content = $_POST["content"];
4 X1 R! \1 A& H1 } - $tags = explode("_",$_POST["tags"]);
# r# l+ W/ Q# p0 j2 h- n - $cate = $_POST["cate"];
6 m9 m/ s# j0 Q3 P8 @ - //print_r $tags;
. _1 Y+ O8 R: f0 [) p - //6 P) S/ g2 [& Q/ C3 p* s
- //
8 n4 r1 }8 P3 r6 p. U - $wp = new WP();3 G4 I; X) A3 r
- $wp->main();8 N) t+ S7 x, c4 `( F( y2 Y+ D7 ]
- //% d a( d* P: |, \: o5 I5 r. V4 W/ ?
- $my_post = array();( H$ R! D! L4 B7 | F3 H
- $my_post['post_title'] = $title;/ }% X2 z8 r' U8 J' b% o$ @
- $my_post['post_content'] = $content;
, a- d8 \! h9 y( C - $my_post['post_status'] = 'publish';
3 F: v0 {6 R4 ?- ]( Z - $my_post['post_author'] = 1;
* O- I3 _, _* P8 G, V - $my_post['post_category'] = array($cate);) g( K( J) \! p
- $my_post['tags_input'] = $tags;
% I$ {+ B0 K+ o9 Q - //$my_post['tags_input'] = array('tag1', 'tag2');( T R6 O, I' E2 a
- //$my_post['post_status'] = 'future';
! _& X& M- Z3 `4 `4 x! w! B - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. y8 W" a6 S2 y2 D8 F J
# X, Y6 r- A! i4 O- // Insert the post into the database
& T( o1 [/ A A5 G3 Y$ \, Y& c( ]9 | - $ret = wp_insert_post( $my_post );
4 Y3 O1 Q" z) I$ B - echo $ret;' _7 r# P! K* e) V9 C( W
- ?>
7 S' |* T( \6 ]; V6 x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ) S3 ]( m U( Y5 E* B
- <?php
* S/ s; F6 ^) `) e/ G - define( 'ABSPATH', dirname(__FILE__) . '/' );2 K. y1 H9 E6 L0 |2 [6 G1 {3 _1 v9 J
- require_once( ABSPATH . 'wp-config.php' );
/ N1 f2 b- M3 I; i R - require_once( ABSPATH . 'wp-settings.php' );
& ~$ q+ D' M$ B9 A - require_once( ABSPATH . 'wp-includes/class-wp.php' );" Q7 i. d8 p# _1 l8 s$ I
- require_once( ABSPATH . 'wp-includes/functions.php' );
9 G W( e; W% ?: P5 ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );! Z/ M& [. k: u0 B3 W; O. ]
- $pic_name = $_POST["pic_name"];
# L- ~6 D$ k0 A: w - $pic = $_POST["pic"];
& W0 R# e" T9 v3 B, p3 M% O" I - if($pic != "" && $pic_name != "")
, ~7 R3 Q% n O6 a) ?; g - {
% w8 G" V: F+ L- v# W1 B% C - $path = "images/";- B% _/ `) B' q6 B
- $pic_name = $path.$pic_name;
2 k" w; `! g- E - echo $pic_name;
5 ~. |# O! h3 k& [; Z - echo "||";
7 R( [3 I) {& X' H$ T" J5 e- Z - error_reporting(0);
$ m$ u8 y; y6 @5 t' C$ r( I - mkdir("images");% U* W2 v& ^9 i; I
- $handle = fopen($pic_name, 'w');3 L; L# A7 ]% @, T8 m- z* P
- echo fwrite($handle,file_get_contents($pic));6 e; V# a/ T+ C3 p( K
- }, V! s" D7 ^) Z! {# c/ d
- # c/ M/ `$ c$ g* @$ D
- $title = $_POST["title"];
5 K; U, y! k, F. r - $content = $_POST["content"];% i1 P8 X7 G* ?' b4 l
- $tags = explode("_",$_POST["tags"]);% \9 w, ?+ m) Q( T% F7 W: v2 @! ^7 |
- $cate = $_POST["cate"];
" d8 _* J) U% K0 D' X1 q) S2 W - //print_r $tags;
) x& ^8 E2 t/ j9 P0 H; L1 d - //
/ V4 Z6 K" o8 n - //
' x0 V% Z0 K1 Y6 ]$ f - $wp = new WP();
2 y3 j+ o2 \2 x; B* { - $wp->main();
% D& o$ d+ M7 n# O r( W - //
5 Q( N, V! v6 }( @- \) I) \ - $my_post = array();
8 r8 {- \" R! {( C/ G - $my_post['post_title'] = $title;
( _# N$ M+ p8 Y3 |' o4 F/ b$ R - $my_post['post_content'] = $content;7 t/ |6 A2 a& w" p4 m: s1 x
- $my_post['post_status'] = 'publish';
5 L% Y ^1 D. g: s/ c5 P+ e - $my_post['post_author'] = 1;
' L- ~! F3 Y5 C2 }$ Y - $my_post['post_category'] = array($cate);
. R# l1 U8 L, u/ o. k - $my_post['tags_input'] = $tags;
# \# R6 K' t# ]$ }. p+ y8 ^ - //$my_post['tags_input'] = array('tag1', 'tag2');8 J( z, v% E. E2 c, F" H
- //$my_post['post_status'] = 'future';* m# G& E4 h$ m6 `) L, b+ k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 H! H1 Y7 Z8 K2 \
$ G k, M5 F. M+ X( g" I, ~4 q- // Insert the post into the database
3 P. E0 c) Q. ~ - $ret = wp_insert_post( $my_post );
1 \- ?' V' ]/ e - echo $ret;
4 q3 P% }' p X0 E0 U3 T - ?>( P' U ^2 W% m" Y6 L( C# u, M, A0 E
复制代码 我自己写的) i& N% P! J5 V# ?$ g
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|