|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
5 S6 l7 [; e: @/ C
; F7 z" W7 f+ v, g) \* e4 |直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
& m) L& u/ V0 ~* L4 i m
# a1 h2 i# M) Y$ i2 P6 w3 g# {! o我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% M( z( E; w) ~, U* m5 g( s* A
1 e; H! l6 ] ~$ V: B方便实用 简单 何乐而不用呢
; k2 L7 |, @6 T( x" p$ C5 t6 o# ^- <?php
\; z! v- F" L8 S* b
. S5 d' |, w, L- define( 'ABSPATH', dirname(__FILE__) . '/' );
, ^- {& P1 E; F* i7 h" Q* [ - require_once( ABSPATH . 'wp-config.php' ); D9 c$ o9 O- j1 c. M
- require_once( ABSPATH . 'wp-settings.php' );( F: L' z) ^0 G
- require_once( ABSPATH . 'wp-includes/class-wp.php' );3 |% \, v, B u) Z8 Z8 a
- require_once( ABSPATH . 'wp-includes/functions.php' );) X o9 h3 H; P( L m
- require_once( ABSPATH . 'wp-includes/plugin.php' ); h* Q' m8 P- B8 P P# M8 M. [
- $title = $_POST["title"];
0 x5 N8 ?1 ?/ a( J' |) V - $content = $_POST["content"];: }; @# f5 \% N
- $tags = explode("_",$_POST["tags"]);
0 B% l7 K& O6 A3 k& E - $cate = $_POST["cate"];
( D8 X% B9 G9 ?1 T - //print_r $tags;( F9 I+ x& W) s) I+ w
- //3 n1 o, O+ o( T: X) H8 W
- //& E! t, b0 o0 X/ b- [
- $wp = new WP();/ w, J/ W' j9 e
- $wp->main();
9 I9 ~- E5 `, i% h+ S - //* {! E5 f# ^8 r* b+ |: z
- $my_post = array();
! ^1 A/ w. J0 r - $my_post['post_title'] = $title;
; i3 i' {3 [9 ~; |9 A - $my_post['post_content'] = $content;3 X( V0 e e9 M% w! @* I5 F$ p
- $my_post['post_status'] = 'publish';7 M+ A4 @- m) Z& N: o
- $my_post['post_author'] = 1;& A9 C' i- f( T' |+ ?
- $my_post['post_category'] = array($cate);
7 ?/ A& w p7 X: x$ l" t - $my_post['tags_input'] = $tags;8 ]0 R. E1 O9 O5 {+ T* i
- //$my_post['tags_input'] = array('tag1', 'tag2');# a$ a; ~* f) A5 E
- //$my_post['post_status'] = 'future';) Z7 D1 P2 q0 p; O6 `$ C, x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ K; p8 V6 s4 }0 a/ g' L
8 P$ n p: Z3 I# m$ l- // Insert the post into the database1 `5 @1 K o2 R6 p3 E* a7 E
- $ret = wp_insert_post( $my_post );( B; s |2 c$ L2 U
- echo $ret;
' I/ _( }" q8 W. ~0 x - ?>
; w8 ]" U) M8 J+ z# }/ L
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
% q# [! h8 B( A+ o" d- <?php
7 ~9 Q+ r+ K1 J, ~" k - define( 'ABSPATH', dirname(__FILE__) . '/' );
4 k3 Y1 }! a! b/ R6 b - require_once( ABSPATH . 'wp-config.php' );4 v) F3 I k2 z# Z! J
- require_once( ABSPATH . 'wp-settings.php' );: {! h/ \# G+ k& c. s" l4 V% Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );9 c; n: g2 `' a2 m$ G: F
- require_once( ABSPATH . 'wp-includes/functions.php' );
# U( Q! B2 f# j& f& q - require_once( ABSPATH . 'wp-includes/plugin.php' );/ p( ^2 x" y- G/ v$ w
- $pic_name = $_POST["pic_name"];
, Y, u P" B$ G; u - $pic = $_POST["pic"];# E- E: Y1 l. P8 t
- if($pic != "" && $pic_name != "")% N! l/ K9 g* _4 M# x" o |
- {% Y" g: z; {; @+ U
- $path = "images/";' x4 E" e9 S6 c% r! U3 V6 Z
- $pic_name = $path.$pic_name;
5 g6 y" l2 ]$ n( A - echo $pic_name;
. R* k# f! Y' e" | - echo "||";% K9 i/ |( J* W* H2 v4 {3 P
- error_reporting(0);
. H& W7 f" p2 `' C$ G6 ^; G - mkdir("images");
$ ]9 b3 j/ _: V9 i* C$ I0 A - $handle = fopen($pic_name, 'w');' T% {4 b) \) z) ~' a
- echo fwrite($handle,file_get_contents($pic));
4 W1 e$ O$ T3 d7 n - }9 R/ U9 \( U/ r- i6 M; J
- ?5 F* D9 }; [+ q
- $title = $_POST["title"];
) w. x% F1 L8 j1 | - $content = $_POST["content"];. T+ m! u- g2 k8 t9 L5 F( ~
- $tags = explode("_",$_POST["tags"]);2 v3 {1 w, I: p1 d
- $cate = $_POST["cate"]; W3 ?' ?' \, ?- C0 u$ J
- //print_r $tags;# b# U- l C) D6 N( t# W$ m9 ?* R
- //
7 V* _! c9 N* j( A/ ^ - //: Q0 F( ^5 M t' x j: x
- $wp = new WP();7 c; f/ z0 p; V7 C: E5 s
- $wp->main();$ b" Q# u# {: e* Z: n* {% @' n
- //
$ B' T2 |, B" i( L" D# [ - $my_post = array();1 x& B: m, D: G
- $my_post['post_title'] = $title;; h1 n3 q& |! I. r7 e7 [. Z+ \
- $my_post['post_content'] = $content;. O; ] J3 `% `* r
- $my_post['post_status'] = 'publish';
1 O$ S! C: ~; O* o: C - $my_post['post_author'] = 1;% L5 R1 Q* i& ?" i" m* p
- $my_post['post_category'] = array($cate);5 ]! D! Z$ s! d# B u/ V/ ]: o
- $my_post['tags_input'] = $tags;
- m( B" y) [1 J9 b( B+ T - //$my_post['tags_input'] = array('tag1', 'tag2');/ g- E5 [! B$ g' L1 l7 E# z
- //$my_post['post_status'] = 'future';
" h, T6 f9 a; {4 _" r ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';
* I9 d( i- }* A: U6 W - , Z: t: K$ ]$ l$ _- `( o
- // Insert the post into the database% R$ e+ M; i+ `' w g
- $ret = wp_insert_post( $my_post );
r- ^, Q2 h4 Y. n8 v - echo $ret;
( N% c1 Z O2 |3 `) x+ L" q/ I - ?>! i: E( k' k7 b/ a( l
复制代码 我自己写的
% ? Y1 D" b1 f, Y% ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|