|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- \. N& o" n! O7 \7 L
0 J% |2 L+ F( J0 J! y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- ~5 m' Q a1 P% T9 e* t n# s5 N. G, J6 t: D
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 q! i q: _) z2 H5 {, B& n# a
, x2 \2 c+ ^/ W
方便实用 简单 何乐而不用呢- 8 B) G Y% T0 a6 H
- <?php
' I/ g L \3 J2 X, D* h
) z) s7 J2 I; q6 P6 w* I- define( 'ABSPATH', dirname(__FILE__) . '/' );
" \# L' Y7 [/ n. C) p6 E! Q: W0 } - require_once( ABSPATH . 'wp-config.php' );
8 f6 D) j! N! a% R# @1 i - require_once( ABSPATH . 'wp-settings.php' );2 H, v! ?& g+ x3 ?" \+ {
- require_once( ABSPATH . 'wp-includes/class-wp.php' );& F3 g+ y5 |, k, V
- require_once( ABSPATH . 'wp-includes/functions.php' );
0 r5 K4 s, Y7 x- d F! h; E& k - require_once( ABSPATH . 'wp-includes/plugin.php' );
0 {4 E( a, G$ \7 w0 q - $title = $_POST["title"];
1 F. @/ w5 r8 I9 ^% D+ ], f - $content = $_POST["content"];
& ]0 B2 u/ d& S, K& l - $tags = explode("_",$_POST["tags"]);
4 s5 z3 N# Y9 r- B - $cate = $_POST["cate"];; `; X, A+ X2 g' G3 B
- //print_r $tags;
- g3 s* l/ O% N k; S5 D - //! O/ q, Q9 G3 T2 F& |- ^5 H/ k' E) H
- //$ C+ K( a2 O9 H9 i% z/ l
- $wp = new WP();* o+ m/ G3 ^9 X( e
- $wp->main();5 N( l7 Z" A: E
- //
( ?+ g" q( x: j - $my_post = array();
! N: a) }6 G& D1 H1 {' \/ @2 } - $my_post['post_title'] = $title;
5 [) A3 u5 \& D! Y# o - $my_post['post_content'] = $content;
; n7 M3 n/ t9 J - $my_post['post_status'] = 'publish';
8 O2 v0 B' U1 E& x3 X& ~& k; ]) ^( Z - $my_post['post_author'] = 1;
( b$ y" ^5 q& k+ u - $my_post['post_category'] = array($cate);' R; F$ x# l) ?& y) P
- $my_post['tags_input'] = $tags;
9 N" J% T0 n) u* c) u0 @3 ^ - //$my_post['tags_input'] = array('tag1', 'tag2');
" L( z- c8 T0 e( `% a) t - //$my_post['post_status'] = 'future';4 U0 I# [" O' u4 o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ ?" H, @* e* j4 \! q4 i
$ F+ [! y* \& L4 H- // Insert the post into the database( ?4 T4 U8 q5 K3 o$ Z5 J5 l1 a
- $ret = wp_insert_post( $my_post );
2 B) b- R3 x4 f+ N0 X - echo $ret;6 T' t! V0 b: b( C
- ?>% M; V8 G6 W5 e( A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- $ b/ d* @. o% S0 S/ y
- <?php
. a/ g7 G ]) t - define( 'ABSPATH', dirname(__FILE__) . '/' );
3 u! m: e1 c5 {; D - require_once( ABSPATH . 'wp-config.php' );/ P) E G" [# B
- require_once( ABSPATH . 'wp-settings.php' );+ d( a9 w {1 D" K1 M4 \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( f) u) N/ V" `$ X - require_once( ABSPATH . 'wp-includes/functions.php' );
. a" I% s2 C: k" }% U - require_once( ABSPATH . 'wp-includes/plugin.php' );
" y" d4 D1 i, o2 z" ?+ a - $pic_name = $_POST["pic_name"];
, u5 H& H8 Q; _ - $pic = $_POST["pic"];
' J" `% `. ~. p2 l- M - if($pic != "" && $pic_name != "")
; ]# Y+ n3 X' Z+ O - {# r6 e+ {+ c, R( ^0 h
- $path = "images/";
+ x. O2 l( F5 j - $pic_name = $path.$pic_name;
: {* H8 \. r) S - echo $pic_name;
4 V( _9 h. U( m - echo "||";) c/ o0 ^) W7 t# _
- error_reporting(0);; P1 H* f6 m+ r3 c
- mkdir("images");6 r7 g6 W" N; l: p2 P. B: o
- $handle = fopen($pic_name, 'w');% W9 o6 ]$ V( Q- N
- echo fwrite($handle,file_get_contents($pic));$ n7 q: V3 A* J0 t5 f) }: c
- } ?( ?1 J! z& n1 ^
# o& u9 E1 p2 u" i* Q0 i- J- $title = $_POST["title"];, I A) l! y% V$ o k2 c7 c! ?
- $content = $_POST["content"];: C3 R' Y( _0 P% _8 _7 ?
- $tags = explode("_",$_POST["tags"]);4 T. X2 u5 q& D4 d
- $cate = $_POST["cate"];
1 }5 J) e$ z* m7 P - //print_r $tags;7 Q* m2 p8 G) S8 D
- //
% Q- l" ]# ^+ D8 j; s - //6 W4 I9 B+ w$ m( ~
- $wp = new WP(); G) k, W1 C% q/ @" B8 r7 c
- $wp->main();
, g8 p ~9 S/ q4 f& o - //0 c w( e$ `! F0 g4 P
- $my_post = array();
: s; _/ H5 N: S3 ]$ n" b! }- ?8 z - $my_post['post_title'] = $title;
& ?7 U- [7 |9 f7 t - $my_post['post_content'] = $content;
! Z8 c5 S: K2 s* J( J - $my_post['post_status'] = 'publish';
2 g- K6 n9 J. M4 I4 Q - $my_post['post_author'] = 1;6 I9 D3 d8 Z* ]3 y" w$ C
- $my_post['post_category'] = array($cate); ]8 o8 I: {/ n9 O7 @$ s2 A
- $my_post['tags_input'] = $tags;( `9 Q' O' O( g& c' a
- //$my_post['tags_input'] = array('tag1', 'tag2');' @3 N* A7 B6 {4 y
- //$my_post['post_status'] = 'future';
. @, T; z- B" O - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 S/ X, ^( A& c' x p
; Y' F* y' X- b, m! u5 M' T- // Insert the post into the database
. @% h! y8 x7 v* V# s4 @ - $ret = wp_insert_post( $my_post );8 ~, K, I* Q5 f9 ~, p( e
- echo $ret;
1 D8 [$ J3 z: K) Z$ n# u - ?>
. U4 x4 n+ ]5 V9 G6 J1 G' p9 @# N
复制代码 我自己写的 I" D4 a2 U+ O: k! {0 L
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|