|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ; U! S& d' s- G$ O2 V1 v
* u: d4 X5 s1 _5 n0 ~
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
' s$ g/ U9 c: h/ V
( x }6 t" ^, m+ x4 P2 t: z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了8 c/ M6 D+ t2 ?2 b
: X: M9 V2 t4 s9 u+ D5 @3 P& J
方便实用 简单 何乐而不用呢
; y7 a: t1 l* s' j- P" M' N4 }- <?php
8 S4 a! p7 C/ m# g - * ^7 a# R6 v7 `7 K$ p9 \& {
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: X0 T8 a3 r0 y - require_once( ABSPATH . 'wp-config.php' );* L/ F+ m9 ~( Z0 [3 }5 r5 ]$ O
- require_once( ABSPATH . 'wp-settings.php' );* D5 E* u8 D6 U8 C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );# p0 u2 Y J$ a6 K" k1 O6 Y$ ^
- require_once( ABSPATH . 'wp-includes/functions.php' );
C, o0 Z$ K+ r; v y! A2 k1 a - require_once( ABSPATH . 'wp-includes/plugin.php' );
8 u: y! P3 V/ T( J# s1 M - $title = $_POST["title"];
' f: o$ M# Z9 W8 N, h" y - $content = $_POST["content"];; H7 Z7 H9 z/ s% P
- $tags = explode("_",$_POST["tags"]);
+ s2 C) a# H/ ]8 l# [ O) V% f: N - $cate = $_POST["cate"];0 L. a) k; `8 V9 I; c- Q( U; y5 g
- //print_r $tags;
0 F, |0 e2 Y" `/ Z# u! O - //% K$ Z2 Y" f6 d: S: ?+ ]
- //
) J( W2 i5 @4 x5 j3 L+ x$ A - $wp = new WP();
$ o/ E4 _; d7 T3 M - $wp->main();6 \, c ]9 w( l! V9 a3 j
- //
' t1 W. e$ ^/ U3 c3 }* b - $my_post = array();5 o& w8 c5 u! U, N8 s
- $my_post['post_title'] = $title;: T( U' B4 I8 f; E3 O9 k. @1 S
- $my_post['post_content'] = $content;/ A; r' c8 d4 L6 |& J. ^
- $my_post['post_status'] = 'publish';
/ [0 a9 p/ B* [+ H% C9 f - $my_post['post_author'] = 1;
: c+ e' v, ~. A* q - $my_post['post_category'] = array($cate);
. X3 E7 B* w7 e( C - $my_post['tags_input'] = $tags;2 h) y" h( T0 G2 g0 o9 m, c
- //$my_post['tags_input'] = array('tag1', 'tag2');
( Y9 [- G+ m6 ~ - //$my_post['post_status'] = 'future';0 A% S. f( f$ w0 o! d, o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# K" @) F% V) G2 H; \# ]: y0 r
# w! ^0 J# \7 _" X' X N- // Insert the post into the database% W6 ^, x) s. A$ [0 B/ i& v) s
- $ret = wp_insert_post( $my_post );
3 D0 }' D) J/ p4 i0 } - echo $ret;
" ~ n8 C5 R$ A2 f! x" u& e7 _ - ?>
7 D9 p! K& o0 x' |# Y& Z; ^
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 [1 t) {" k/ V" l/ N- <?php
* F( |1 G( _5 _$ ]$ u7 [8 \. h - define( 'ABSPATH', dirname(__FILE__) . '/' );8 c% U/ ^) A! l9 m6 j* Y
- require_once( ABSPATH . 'wp-config.php' );# J+ T s2 k1 q( ^1 D
- require_once( ABSPATH . 'wp-settings.php' );" \; X4 d; k- ^, Q! w4 V
- require_once( ABSPATH . 'wp-includes/class-wp.php' );8 \; {( r3 _7 X) K9 t
- require_once( ABSPATH . 'wp-includes/functions.php' );
7 w% }) r' J# R+ U- t7 d - require_once( ABSPATH . 'wp-includes/plugin.php' );
& k( j+ K2 }1 T X - $pic_name = $_POST["pic_name"];
. N+ G% V8 b; g7 K0 |; D - $pic = $_POST["pic"];5 ^! X# j) P% i* J
- if($pic != "" && $pic_name != ""). C/ [1 I/ Q" f6 J+ S' j1 _; b- j& B
- {
0 [- g5 S5 X% R% B$ q - $path = "images/";( ^' w7 R9 \* Q7 u+ {! K% `
- $pic_name = $path.$pic_name;+ b' \3 t5 H6 e. s9 a$ O
- echo $pic_name;
4 @: E: L. f( @$ f4 A4 |/ P. ~: m - echo "||";
; X9 c8 `3 E% v5 @% }8 G - error_reporting(0);7 {9 `3 f& C3 s I9 I
- mkdir("images");* D9 t8 q( |$ u" |( A
- $handle = fopen($pic_name, 'w');
4 d! E) i- W O0 U. `2 G - echo fwrite($handle,file_get_contents($pic));4 a/ x+ J* O# \; p+ j
- } D! W& e1 p: c) g) K: r) K8 O6 w
0 F% G% \. W9 o: q' ?5 E+ D$ G- $title = $_POST["title"];
- M+ _ |1 c$ J - $content = $_POST["content"];
) c$ D9 a& a" J - $tags = explode("_",$_POST["tags"]);2 Z3 A* X8 H5 J& v, M K( j; Y! R
- $cate = $_POST["cate"];
8 l- p4 O& ~9 b0 m - //print_r $tags;
7 w4 b! N- m5 V* f! L - //4 L' T' W0 K2 |% L4 j2 e8 w
- //
2 P1 M* R$ P. T - $wp = new WP();! ~9 T1 V% A8 @( W/ O6 C0 `; q
- $wp->main();
- \! r/ d5 @" V2 f* G - //
) T# p) k f4 Z+ M - $my_post = array();
" b- e, ~. j* H" W0 Z: l - $my_post['post_title'] = $title;( C `7 e5 h0 A; G
- $my_post['post_content'] = $content;
6 u1 ?) c0 u& ~ - $my_post['post_status'] = 'publish';
0 j n8 R5 m" n - $my_post['post_author'] = 1;# D0 @) P' B+ P6 N: n3 G0 G! V: J6 A
- $my_post['post_category'] = array($cate);* P( ~& _, |0 I" A0 m; p" M
- $my_post['tags_input'] = $tags;0 V/ v. A$ H: v( D) m
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ }' _0 D2 u9 e/ A. @( c8 T - //$my_post['post_status'] = 'future';
# X e' ]# x! u% I* x - ////$my_post['post_date'] = '2010-07-04 16:20:03';9 D( `; B" F, y" L9 m
% f& |+ P! s) N- c- // Insert the post into the database
) K2 J3 b; e/ u3 ~+ {1 v0 ` - $ret = wp_insert_post( $my_post );
; n( ^2 e4 f6 z/ H5 d& n* x0 S - echo $ret;
0 w2 o. c5 _: k' [6 d: {5 b5 ? I - ?>
6 v7 \, K. y$ x
复制代码 我自己写的( {, l: x) Z+ A0 {
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|