|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
+ @6 E0 n- K3 `6 ^
' {# v- ^+ n8 D+ \ s8 E4 `0 f直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
7 Q. D5 ?+ w/ c" W3 r: c/ p
2 ^1 @1 n4 u# K* ^ r! n' w我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了. H K, I3 o" b9 ?" d
) ~2 s" h2 N+ J4 d9 X
方便实用 简单 何乐而不用呢- . g% F6 m3 Y7 x1 ^
- <?php$ o \: @ U: h6 Y
% _ k. `5 |9 d5 Y2 d- define( 'ABSPATH', dirname(__FILE__) . '/' );6 m8 g9 k$ Q: }; y% E
- require_once( ABSPATH . 'wp-config.php' );- v1 @6 m; G% f9 c2 S- v; h
- require_once( ABSPATH . 'wp-settings.php' );
! z4 T0 g9 ]8 V7 B; f v5 j/ O' C - require_once( ABSPATH . 'wp-includes/class-wp.php' );
# S5 s, Q- {8 Y - require_once( ABSPATH . 'wp-includes/functions.php' );7 l% e9 L' M& g2 d! v& a
- require_once( ABSPATH . 'wp-includes/plugin.php' );6 t1 w, z, W8 S( R% y
- $title = $_POST["title"];
3 j, |7 K1 G& g. @& h - $content = $_POST["content"];
- q+ N- |1 |. a5 W- a, ?, k" u - $tags = explode("_",$_POST["tags"]);
+ g& l w8 W: f: w# K7 U - $cate = $_POST["cate"];
q" M, y3 B# ]/ B; z% `2 W1 e - //print_r $tags;$ X4 e" s( u+ D O1 f4 }. O
- //
' O* S, y2 d: k* E - //
A( ^2 K( d; d% C - $wp = new WP();
$ H( B% g+ X, B5 s- J+ h% ^ - $wp->main();- F* {. K2 o1 W/ G1 y9 |
- //4 [3 C( I( E/ {: G- x
- $my_post = array();: T4 I' b2 ^* d8 b
- $my_post['post_title'] = $title;1 G5 T g# T# g( T' H
- $my_post['post_content'] = $content;2 O; D: Z' q7 k! b1 x. ?" x
- $my_post['post_status'] = 'publish';5 L+ K- }5 Q9 V$ r
- $my_post['post_author'] = 1;
% k, b9 W2 n3 P4 B& t7 U - $my_post['post_category'] = array($cate);- y* y9 Q5 I1 y
- $my_post['tags_input'] = $tags;# Z0 Q+ t# h% O3 U6 N
- //$my_post['tags_input'] = array('tag1', 'tag2');
1 U( i; S% e2 x2 n - //$my_post['post_status'] = 'future';2 g4 p% Q. o Z- D3 m
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
. P# I" h( f$ u - ) Z, Y, b, T* L% E: K# I; `0 R$ B
- // Insert the post into the database
# P! o- Z- Y& x( [/ h' ^ - $ret = wp_insert_post( $my_post );/ A6 a2 U I' S1 H- F
- echo $ret;# E& U3 U7 s+ w
- ?>6 g' a2 m$ x- X! Y' i! ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
# W; L; U. N8 l$ a# C% Y' j- <?php* d( [+ @7 q5 X% D7 R
- define( 'ABSPATH', dirname(__FILE__) . '/' );# ]6 C C) n$ ^0 L
- require_once( ABSPATH . 'wp-config.php' );( X2 A2 Q/ f' b# I' R
- require_once( ABSPATH . 'wp-settings.php' );
+ t5 M) `1 a* d" I: ~3 Z. F - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ ~1 |5 K2 Q( z1 T! d2 [ - require_once( ABSPATH . 'wp-includes/functions.php' );
0 }& M) ~6 P9 n( k6 f - require_once( ABSPATH . 'wp-includes/plugin.php' );
; |: x5 ~+ J, F& A6 q - $pic_name = $_POST["pic_name"];
' Q5 c# ?) ?% x' r$ L - $pic = $_POST["pic"];
5 o0 K' G/ J7 Z' |7 [ - if($pic != "" && $pic_name != "")" j# ]' N& P! u, m# `6 P5 N3 h
- {/ R! r. x: ~1 E6 r; r
- $path = "images/";
6 f! T! v$ N. G9 w1 U. Q - $pic_name = $path.$pic_name;1 F- f) J+ X( R
- echo $pic_name;
) c# o; F+ x8 K- J$ }1 n. P - echo "||";5 N' z+ S3 F+ v) M) o3 \. }; B
- error_reporting(0);
! S5 _ U9 {5 L# ?# I4 N - mkdir("images");9 Z3 n; E8 F5 j# }4 d+ j
- $handle = fopen($pic_name, 'w');
; s. U; m/ u0 w) e; s; `# ` - echo fwrite($handle,file_get_contents($pic));0 l3 T- K" k1 ~7 z
- }
; N+ `+ x4 v. Z* o8 t - : T5 E' `8 n" R, B
- $title = $_POST["title"];
; M$ A& t% B8 F& L2 k2 j* G0 ^( h - $content = $_POST["content"];
4 m0 d/ p, t9 ?& l: c$ O - $tags = explode("_",$_POST["tags"]);
3 m9 ^5 M* h" V1 V, l - $cate = $_POST["cate"];8 w% N% t: F& \ F
- //print_r $tags;/ ~+ p' k/ B1 t7 C: Q6 A7 T9 B
- //
/ `; i4 [3 U2 a9 V' Q: r - //
6 K/ e( \* M$ p; P - $wp = new WP();1 j$ W6 N6 R2 _6 K$ A
- $wp->main();
$ N$ ^% O& o3 X' Q - //
! i. F6 F O" _6 m/ U. O - $my_post = array();& ?9 Q- e5 N8 Y, v/ i
- $my_post['post_title'] = $title;# I% u7 C* D) R: r! x- s c
- $my_post['post_content'] = $content;
% ]$ T- E, R- r7 e" K R - $my_post['post_status'] = 'publish';: j# Q' \! L/ H
- $my_post['post_author'] = 1;4 M: P" h3 U* f, `. x3 D& W
- $my_post['post_category'] = array($cate);
8 k% i0 j/ J+ N( b0 h, L - $my_post['tags_input'] = $tags;
% b' J- i: d( {- n - //$my_post['tags_input'] = array('tag1', 'tag2');
2 P- a" L1 g( v9 N) o3 z - //$my_post['post_status'] = 'future';. s- K8 \2 y8 z( [. s/ d% f3 Y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ I% U- g; R: ?1 _( w# \" j7 @
- , p! k( p1 u; f! _$ j) t! I3 @0 S$ I
- // Insert the post into the database
+ P' B* z* @7 u4 @+ V! M - $ret = wp_insert_post( $my_post );
2 o0 M6 r8 c. \' r - echo $ret;
0 r a. ?9 v: i+ k/ K - ?>! p' V8 S7 }# K! \" `; g$ \+ }9 g
复制代码 我自己写的( Y c% Q+ j! K3 ^
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|