|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- k, h) g# H q4 r1 o6 g3 B& K5 `+ p' L8 L' k" a
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
& U( n- {" E/ B7 f! c, Z% \: j% X$ F% d2 ^" C6 b; s( R
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了5 B4 X- o, M( G5 l% X; ]+ S
) q$ w" r' }, p: r& D- P方便实用 简单 何乐而不用呢
* h* x+ u B6 L! C- t) ~' Q, X, {5 Z a }- <?php
7 o2 b6 N6 r# q8 Q1 k( G# ^# q - . ~) Q0 e; e0 X+ F9 I* C; I
- define( 'ABSPATH', dirname(__FILE__) . '/' );
% D @5 ?) _" Y7 t4 k3 z3 i - require_once( ABSPATH . 'wp-config.php' );7 H! [6 C1 r; r
- require_once( ABSPATH . 'wp-settings.php' );2 [8 }1 ~4 |" F# A9 o
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 m) b; h9 F. w4 M, a; W - require_once( ABSPATH . 'wp-includes/functions.php' );7 J+ P3 f ?- O0 a7 y" y6 ]6 q
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 t2 W [6 i, V1 G$ l" m) ? - $title = $_POST["title"];: e2 [3 `( B9 x" j( n. S
- $content = $_POST["content"];
! N: L. x9 O* y* a" [6 | - $tags = explode("_",$_POST["tags"]);; Y8 ^# K" V7 J( l- J; a
- $cate = $_POST["cate"];
0 h1 {% ~' a' R+ I - //print_r $tags;( [! t; A+ e: E, G
- //
! W( q% |" ]" R - //5 z, P* }5 Y* R2 A0 k* {8 f
- $wp = new WP();
9 G$ T/ L, j/ V0 [ - $wp->main();' N7 ?+ {0 m1 t( Z9 O, p+ Z& W
- //6 c! h- ?/ g! L3 `
- $my_post = array();+ s% m( K4 X4 E$ M d2 K3 Z1 L
- $my_post['post_title'] = $title;
' m* D0 T; [% R - $my_post['post_content'] = $content;
y b+ c, C2 h9 l0 i4 p - $my_post['post_status'] = 'publish';, J7 x" g% \) I% `4 F
- $my_post['post_author'] = 1;" v0 W$ o b* @$ ^! n
- $my_post['post_category'] = array($cate);, E. m4 f! M8 r6 N
- $my_post['tags_input'] = $tags;
' |3 s! V$ E- ~$ H) \ - //$my_post['tags_input'] = array('tag1', 'tag2');
/ a+ a9 l& A5 D$ w: x3 [ - //$my_post['post_status'] = 'future';
/ g1 \0 W" `! J% U ~ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
* \7 G% K5 I/ ~; l6 L o - 2 M5 N( `# G3 g' Z
- // Insert the post into the database" A1 Y5 {. d# P6 p& \* m, y( F$ k
- $ret = wp_insert_post( $my_post );) T) ?. z# T# H1 S* }
- echo $ret;
+ A, k9 l: [6 i. O - ?>
# G, R4 q4 ?2 R8 L/ j
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 9 N- u' G$ r# h' C4 o9 y# w
- <?php
9 f5 h( X* f5 N2 g6 L6 i - define( 'ABSPATH', dirname(__FILE__) . '/' ); `! F, ~4 }- c5 _" J4 w
- require_once( ABSPATH . 'wp-config.php' );
3 n1 \! C. U( w4 T9 o6 O7 m - require_once( ABSPATH . 'wp-settings.php' );! @; |9 N/ b# t' b4 z' }
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 u9 w( r# \6 ^# V
- require_once( ABSPATH . 'wp-includes/functions.php' );
) s: F t; r$ W- g9 L5 ~5 [# J( } - require_once( ABSPATH . 'wp-includes/plugin.php' );
0 q, K0 q2 I7 T - $pic_name = $_POST["pic_name"];
: n9 z+ {+ V, h - $pic = $_POST["pic"];
. X# L* a& V/ c/ z - if($pic != "" && $pic_name != ""), J$ n& U& O- k1 D1 |" V0 F- E
- {
; Z6 J( B0 V4 a# J0 s - $path = "images/";5 h& m0 z2 d( L; @0 x9 a" P
- $pic_name = $path.$pic_name;
' n, e4 e% l$ a2 l ]" i9 G - echo $pic_name;+ i% M5 |2 }6 i9 S* W8 Q
- echo "||";
6 J2 C: W' i0 x/ i: L+ | - error_reporting(0);1 ^# S. E# @# n, _' h0 d! c% K
- mkdir("images");3 h& E: ~4 e/ S* y0 s
- $handle = fopen($pic_name, 'w');
/ ^4 g/ X; O% o# a [& E - echo fwrite($handle,file_get_contents($pic));
; M; |6 O) e9 V& f' m/ D - }3 p+ \4 F1 j; T$ x3 [
- ' H( X n4 z) I6 V) V# B( G2 X( P& [
- $title = $_POST["title"];
5 L0 ]% ?1 z! I1 o# ?9 j - $content = $_POST["content"];
& A5 {8 c1 v6 X" Y' T - $tags = explode("_",$_POST["tags"]);6 ~4 p4 Z0 M8 C7 K( u
- $cate = $_POST["cate"];
, z0 `) B- G5 {6 [1 H" ?; @+ I - //print_r $tags;
( D/ f+ R. H+ d/ G, T" o" d9 X - //
& m. o; G' I0 Y5 \1 i: A) U - //
8 D# I$ Q7 R0 k( y$ d - $wp = new WP();
9 d4 p- t5 P' U: A7 R X3 ?2 Y - $wp->main();' C' v! U+ {7 U |
- //
8 \8 q- M$ N9 r1 w1 N - $my_post = array();
" y$ j' Z: m3 G/ f, N - $my_post['post_title'] = $title;& u0 y# B5 V# d
- $my_post['post_content'] = $content;" \/ o9 |" T$ _# | n5 Z7 m
- $my_post['post_status'] = 'publish';
2 Y2 p- d* [" x { - $my_post['post_author'] = 1;% k! Q& J! ~$ e8 N% k: K' g- B' o
- $my_post['post_category'] = array($cate);( s H# _6 a1 k7 ?" J
- $my_post['tags_input'] = $tags;: _, b1 Q* G& w4 {0 B; F7 a! p
- //$my_post['tags_input'] = array('tag1', 'tag2');
+ j) G' A+ A2 r3 k* L$ R5 H - //$my_post['post_status'] = 'future';
% [9 B2 T$ t) U: e7 [ T - ////$my_post['post_date'] = '2010-07-04 16:20:03';
a' q. ^: a2 @+ o - n7 s- |- I( ^3 H+ r" p+ K3 X
- // Insert the post into the database. o& y3 e- F/ c2 q7 e3 @/ e
- $ret = wp_insert_post( $my_post );+ Q4 N. f% W" r9 f% e, p4 A
- echo $ret;
/ O9 N$ w* q4 U; K* D - ?>
- w0 r) {1 ^" _$ ^6 v
复制代码 我自己写的
! J9 w* p$ [9 G8 s插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|