|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! \+ R @& X2 r+ I
# A/ f& E0 |8 r直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
0 T/ B# f& [* }1 f
8 E D5 m' l" B( V我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
/ c, a2 C" f, q! b$ h& R
9 u$ ]% j" Z* z* i S$ O. [方便实用 简单 何乐而不用呢
& k. t6 Y* ]' ^5 P- <?php: _* e+ {& X) `
- , |8 h- _4 J" {( P' z+ z* S2 X
- define( 'ABSPATH', dirname(__FILE__) . '/' );/ n0 ]/ x& I) h% G* s6 Q. [ G
- require_once( ABSPATH . 'wp-config.php' );
* I( q% u1 o: u/ j5 L) \2 Z - require_once( ABSPATH . 'wp-settings.php' );: H0 N7 ` |6 D5 l% Z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
Y, S( f9 n% u- K& B - require_once( ABSPATH . 'wp-includes/functions.php' );
& D* ]5 e% d/ K9 j+ y; O - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 P& b' N" i+ a% j y' }) W - $title = $_POST["title"];
$ C' E: z# U1 O8 i. N2 p0 q - $content = $_POST["content"];
- N+ T; j+ \' f$ Q+ { - $tags = explode("_",$_POST["tags"]);3 y ~$ T! A/ T( S! ?: B
- $cate = $_POST["cate"];0 v. _" m) O$ F a/ O6 p
- //print_r $tags;
: V; x4 t0 D3 ]7 C& \, c - //* ]0 o) Z; s+ A/ `
- //
+ ^ ` }1 `5 T" d. m - $wp = new WP();7 @0 [5 q" Y' x5 V1 V. Y4 M+ K6 D; T
- $wp->main();0 [' J- @/ z) \' N3 R! Y" W7 \' G
- //& q; B* D/ ]4 ]$ y6 n0 I* u
- $my_post = array();
# [) F( Z8 V8 M$ s* P - $my_post['post_title'] = $title;
0 g" F& X8 a. M$ h - $my_post['post_content'] = $content;6 j* S2 f) V: \- K# l% D( `
- $my_post['post_status'] = 'publish';$ ^& _$ t) M5 O7 v
- $my_post['post_author'] = 1;1 b. A3 q5 m, K* l" K
- $my_post['post_category'] = array($cate);
, F* Y/ f* x- U" @) Y - $my_post['tags_input'] = $tags;
4 V# f% w5 S% \% Y% n' I - //$my_post['tags_input'] = array('tag1', 'tag2');5 l: \8 `, \. R" j
- //$my_post['post_status'] = 'future';
5 X' q, r9 h3 H/ n - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ E. t! `( l/ n% U2 u7 y) S: i - 7 A. p2 e o/ c# G* f) |
- // Insert the post into the database- w' d- L" h; s) v( z
- $ret = wp_insert_post( $my_post );, \$ A, z0 V c, C6 f
- echo $ret;
' V. m3 a& s- q( N6 v% ] - ?>
' J9 t# r0 t% R1 S, z( N
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
3 i4 M) w2 c$ ?- <?php& c0 c J% |* q; ]& e+ I* ^+ Q
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& T! n7 |7 m) u( R+ l9 q - require_once( ABSPATH . 'wp-config.php' );' _1 E# K( e: C6 @0 w+ H
- require_once( ABSPATH . 'wp-settings.php' );
( s2 j6 I0 {9 ~! o, g0 l, P - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: i/ p& g: n4 B8 N' l - require_once( ABSPATH . 'wp-includes/functions.php' );
* t1 K9 X9 D3 e# _; |+ S7 V2 c - require_once( ABSPATH . 'wp-includes/plugin.php' );( Z- Q6 m7 B: [
- $pic_name = $_POST["pic_name"];
( q$ }+ w) q) n - $pic = $_POST["pic"];' d: Y) q- U( d5 z& n; x
- if($pic != "" && $pic_name != "")9 n' o2 x1 h# w* ?8 T- S* m, [
- {
* r5 T7 A! k, d! a4 a0 x( k - $path = "images/";, T$ ^( z" U+ @/ Z4 m: K+ K+ F
- $pic_name = $path.$pic_name;
8 d9 {; ]' s3 ?$ V - echo $pic_name;( O7 m' b: H, w3 [
- echo "||";
8 v1 K/ Q3 p! I3 u- m) {0 @2 U6 D - error_reporting(0);1 N% p- N$ D8 b: Z/ b( M
- mkdir("images");( ?; p* }0 Z( n4 [2 S" g4 Q
- $handle = fopen($pic_name, 'w');8 t& S2 d% N8 n' t
- echo fwrite($handle,file_get_contents($pic));' s1 D r0 D* u2 [
- }
& r# g. G+ s- A& S" O - * Y" t& A" p7 ^3 T! J
- $title = $_POST["title"];8 q1 B# H( X7 V
- $content = $_POST["content"];) x7 k$ C! P7 J/ {( |) [5 Q
- $tags = explode("_",$_POST["tags"]);
; O& W+ ]. G/ Z/ M! Y# m% Z - $cate = $_POST["cate"];
; S9 ]& Z2 e2 W* R* I& ^ - //print_r $tags;$ e$ f4 k: }8 d2 c0 O4 F. {# z" ~
- //
5 m2 m7 |3 K1 E# {! g N( `+ a - //
2 q0 C% h3 k% H - $wp = new WP();
' r' U& D7 _. e P7 R2 P, C - $wp->main();: B8 L8 V( B& j! \" w2 V
- //
+ d7 l4 t% d8 A# r0 q - $my_post = array();
# c7 R' d) s: C! t: s - $my_post['post_title'] = $title;
- s2 z, B e2 `& b6 {# S - $my_post['post_content'] = $content;3 R$ k7 F5 @8 r& K( [
- $my_post['post_status'] = 'publish';
; W) B Y& S0 Y( g/ m2 Q6 I - $my_post['post_author'] = 1;: W" b; G9 y0 J) Q
- $my_post['post_category'] = array($cate);9 Y; I3 i% l+ J F' @/ \: z2 R
- $my_post['tags_input'] = $tags;/ i( L3 A7 t+ A
- //$my_post['tags_input'] = array('tag1', 'tag2');
0 {; X8 @, {6 P7 k; ?7 c6 s - //$my_post['post_status'] = 'future';- q! ] D3 |5 J, P) D0 w- [( x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';2 }/ D0 ` B6 W9 k$ M
4 C0 D* L! ~; P( K6 c# [# `- // Insert the post into the database
* E4 {% d& i' Q, M% w - $ret = wp_insert_post( $my_post );
" ?0 s' q8 R, q4 A) @4 w - echo $ret;
- S/ {. j( E* J - ?>
6 E O/ Z- ~, Q# l6 H$ K3 k5 b; i
复制代码 我自己写的
' [% [2 Q( N' M+ a5 z0 I1 g; ^插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|