|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
6 r' x1 q$ K0 R, P/ \2 G, `/ }- P' u6 x* F. n
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) O% O+ L1 P2 ?& D. ]9 N( V% ~2 J4 Q* \
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; }9 M$ \% o* _& W% x+ k
' |7 l: S% X4 |& d方便实用 简单 何乐而不用呢- ! v2 H; Z; Z7 b6 C1 I9 n* g
- <?php
* K* q' S1 Q4 ?/ S& l. R' t2 ~$ x1 @4 z
9 N: y7 Z! i5 s# D; ]! z$ t" u$ j- define( 'ABSPATH', dirname(__FILE__) . '/' );
- q' r; o9 \5 Z% [ _ - require_once( ABSPATH . 'wp-config.php' ); N6 `' d( w$ t7 r5 f6 ]
- require_once( ABSPATH . 'wp-settings.php' );/ N: x. g }' o% N1 y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );8 B* i% i2 I! o/ T$ u' Q+ D' i
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ @; [9 b' n' h" n - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 \& j% e: g- d* N; P! t b - $title = $_POST["title"];
" c; `. X! m9 ?7 ^% Y - $content = $_POST["content"];
. J6 e% I$ A! I( M$ o - $tags = explode("_",$_POST["tags"]);
7 x8 f) M6 K- f; T, T0 G4 g - $cate = $_POST["cate"];
0 y u! V4 D8 u - //print_r $tags;
7 r3 v! l9 v3 F- r5 ~0 } - //
! E9 J" O" r% W/ A+ p# W - // L. D0 ~$ W8 g! ]4 K9 E
- $wp = new WP();: R+ w: ^1 l8 g( ^
- $wp->main();
1 b# d8 ?2 A6 N& g - //
2 |" Z5 u* ]: T# R/ I; z, `; A - $my_post = array();
& k; l2 }8 M x5 {1 d# z9 { - $my_post['post_title'] = $title;
! C2 v7 z D$ H - $my_post['post_content'] = $content;/ B% q( r( o! W6 b" C H5 I/ L
- $my_post['post_status'] = 'publish';
: v2 D/ K( ~5 R - $my_post['post_author'] = 1;
$ v3 ]2 \3 M& t% K& E - $my_post['post_category'] = array($cate);) ~$ E$ r9 X% Z* \9 |" D8 ]+ N
- $my_post['tags_input'] = $tags;. g7 o- o. @9 L$ P' d% N! w
- //$my_post['tags_input'] = array('tag1', 'tag2');
# C* a$ H6 e4 ^7 Q6 i - //$my_post['post_status'] = 'future';' d* z& b4 h3 D. A7 @1 }$ p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 Z! X# k$ H; `! J! A# R/ S
1 F, v! O3 I1 ?% g1 V- // Insert the post into the database
" ]# @/ V ` i, P8 O) @* I - $ret = wp_insert_post( $my_post );
! p2 r; j% c5 ^4 y t% X - echo $ret; }5 q/ J, _, m% W6 e8 g, O
- ?>
: P/ F3 o8 @+ N+ f; k
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
; h. N6 E' ^/ f- <?php* O+ n K; }; `2 Y8 T
- define( 'ABSPATH', dirname(__FILE__) . '/' );0 s8 G& ^' W% K$ U7 v- U: x
- require_once( ABSPATH . 'wp-config.php' );
% T' ]+ ^4 V$ R3 m" G- M, _ - require_once( ABSPATH . 'wp-settings.php' );
+ y$ B1 [/ A! X" T, D - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 @2 s7 @8 N* m3 q, D6 G
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ M" d4 k4 o- V! _, y6 n# l0 Q - require_once( ABSPATH . 'wp-includes/plugin.php' );' V& p0 t: H$ ~* P, y3 q! a
- $pic_name = $_POST["pic_name"];
1 z; u1 i& n6 S3 @9 g - $pic = $_POST["pic"];0 b$ C$ m. {- ^/ G0 }2 D- b
- if($pic != "" && $pic_name != "")
- x" h# k: O7 ^4 h - {9 S- Q. m `4 }9 H
- $path = "images/";. L, s0 E! i; R% R- t
- $pic_name = $path.$pic_name;7 F) e8 i0 T2 |& U" F/ S. F$ R( Y
- echo $pic_name;
B5 M: O! u4 u. z* G - echo "||";1 w& y5 F( ^, R+ F9 M
- error_reporting(0);! @! m# q* U) V/ g1 q i
- mkdir("images");
/ `. ~# M+ b6 u! Z/ E - $handle = fopen($pic_name, 'w');
$ @. {$ Z# h3 {3 J6 J% u# E2 h - echo fwrite($handle,file_get_contents($pic));% z( }+ k- k. `, z8 p' V* E
- }+ H; q" u# x. }) t" }
. d+ v3 S$ M8 G; [! b* Q- $title = $_POST["title"];; S1 A9 \" ^7 G3 @5 [0 k5 t
- $content = $_POST["content"];
) F" F1 L' a% \, A - $tags = explode("_",$_POST["tags"]); _. K. t( @% D3 ?. l1 M: A4 J
- $cate = $_POST["cate"];, x" L6 y2 V0 v- L+ s+ @2 o1 |& \
- //print_r $tags;4 O4 d* m1 f0 G$ }
- //3 `) z9 Y& ], ?
- //5 v' O9 i) k' ]& T: `
- $wp = new WP();. ^0 q6 y; G# |+ |* w
- $wp->main();- E& T" _5 h" r, T* w1 T
- //
2 s1 t+ |9 t: z/ t7 C' T+ E - $my_post = array();
" n* ?; W) Z; ~" y - $my_post['post_title'] = $title;
7 ]' f/ {# G4 M# j3 l - $my_post['post_content'] = $content;* F0 m: L. S' w$ l
- $my_post['post_status'] = 'publish';0 x3 V" J( o8 i j# E
- $my_post['post_author'] = 1;, ^, g2 W" f5 \, K
- $my_post['post_category'] = array($cate);
& l& ?7 u5 {$ S3 { - $my_post['tags_input'] = $tags;
' u/ o) ?4 g: B% n {8 e - //$my_post['tags_input'] = array('tag1', 'tag2');
2 X h% R) ~; t, f% T, {) Y6 w5 [2 B - //$my_post['post_status'] = 'future';
! K" c: }. B5 B1 W - ////$my_post['post_date'] = '2010-07-04 16:20:03';
; K" q; k% T% O( a1 X5 b - + P6 N& f: k' e$ t% Z
- // Insert the post into the database5 u$ A0 j! y' g0 m6 h9 z& A
- $ret = wp_insert_post( $my_post );
# j% R, d6 l7 t - echo $ret;
1 K* O% w7 L! z: {3 v' B - ?>
$ ^% {3 J, O0 B% _+ O
复制代码 我自己写的 a, i, A% G6 j; n( c/ J
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|