|
本帖最后由 finder 于 2014-12-28 15:13 编辑 : M+ O8 G9 G8 o4 ?: \
& r2 [+ ?4 V4 t9 |& i9 D1 f直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持: _& d# f) n: b/ |! w) d( G
5 F3 ^9 r. C8 I( [我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( }8 M Z j" G( A' ?0 L3 ^ o1 I2 T
5 }6 T2 L! p7 I) w' c# {
方便实用 简单 何乐而不用呢- / Y$ l8 [5 V$ X+ g& F9 D
- <?php5 P3 l" }9 @8 x% f
- z: m2 }0 ?4 H+ k6 |2 ]- define( 'ABSPATH', dirname(__FILE__) . '/' );
% R$ T; X; W! P5 c5 c - require_once( ABSPATH . 'wp-config.php' );; }& Q4 V1 y% V6 ?
- require_once( ABSPATH . 'wp-settings.php' );: P" G! a" \) t
- require_once( ABSPATH . 'wp-includes/class-wp.php' );: {# K2 l: t) s3 l1 q* P
- require_once( ABSPATH . 'wp-includes/functions.php' );
: L3 W/ p4 Y/ n! n1 c, b - require_once( ABSPATH . 'wp-includes/plugin.php' );
! ~$ t) S% G s4 N1 F+ v7 d9 M a - $title = $_POST["title"];
: {, N8 \& p) _5 Z: } - $content = $_POST["content"];8 h- Z6 E& h' Z5 r; @4 @2 z
- $tags = explode("_",$_POST["tags"]);
5 e5 w/ F5 y# W' B4 U" W6 c - $cate = $_POST["cate"];. ]- U# E9 |) S& g# H
- //print_r $tags;6 L) Z4 _4 q0 h+ r
- //
9 D7 \+ T4 e5 ~8 ~ - //" ^9 h9 X. B, \7 u- F8 O/ _& e
- $wp = new WP();5 ~+ @, j3 A( z+ i: ~
- $wp->main();: g/ t% c% ?- @) }9 J
- //
E# A# p. E- N# h% ?3 |! N - $my_post = array();' |7 Z0 z' @( ?) M0 F& _2 A" |
- $my_post['post_title'] = $title;- ~0 c$ h: S5 e# `3 U) L
- $my_post['post_content'] = $content;
3 z$ p1 `$ W. Z% V7 W - $my_post['post_status'] = 'publish';, f }2 n. i7 O6 y& Y5 n5 F
- $my_post['post_author'] = 1;
+ u( s7 ^7 ]. R! V - $my_post['post_category'] = array($cate);
8 r/ J# k# B$ b2 p - $my_post['tags_input'] = $tags;; a$ T' X0 {( w$ z1 f
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ T1 ~0 {' D2 | P - //$my_post['post_status'] = 'future';% b1 u4 Q; s+ j3 V( a
- ////$my_post['post_date'] = '2010-07-04 16:20:03';4 T# [1 U7 J1 H9 e
- # e; d! r* a# V- z f+ z1 q
- // Insert the post into the database
4 R. F2 r( m0 W+ R; m0 |6 T - $ret = wp_insert_post( $my_post );
9 f* _* R, C1 p1 q5 q2 m. _ - echo $ret;0 {# I5 }5 W9 \$ [4 o+ Y
- ?>: D$ ~5 Z8 t/ }4 Z) m$ `' f" m, ~5 F4 f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 9 V: X3 k+ c7 t' D
- <?php/ y. }: ^4 A6 g
- define( 'ABSPATH', dirname(__FILE__) . '/' );& d0 ^) w6 n |& z" M8 e
- require_once( ABSPATH . 'wp-config.php' );3 {5 T* C& e( A7 f$ Z( H
- require_once( ABSPATH . 'wp-settings.php' );+ f' X4 b% P1 a- q+ G* i' g: Q0 [
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 p1 I# Q5 D! w, Y8 b# K - require_once( ABSPATH . 'wp-includes/functions.php' );
?/ r. X* s4 E: D/ k* o/ y ]0 ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );4 X+ o' L/ Y* o/ H/ M1 E
- $pic_name = $_POST["pic_name"];
; a3 k1 {+ o/ U$ h. U - $pic = $_POST["pic"];$ Y# h9 S+ C! z4 A9 n
- if($pic != "" && $pic_name != "")
* [$ \1 m$ U8 C - {8 ]% l0 _2 b0 y. Z0 [0 D# A( _$ L
- $path = "images/";
' c& B4 G- z! W$ h - $pic_name = $path.$pic_name;
- r* M0 Q# P8 y8 D+ X/ G$ d - echo $pic_name;
2 U) J3 X+ j9 z- ]% y - echo "||";
$ m- @6 x0 V# u0 f - error_reporting(0);+ C" ?5 v! [. K% c) t" l- ^. B5 D) C
- mkdir("images");
/ f- H8 C3 I* d5 K) S4 @5 H6 C& I - $handle = fopen($pic_name, 'w');
' d$ [# U& M8 c( f% v9 B8 T - echo fwrite($handle,file_get_contents($pic));
* [5 a+ F7 ^: }) [ - }" x) v* g4 Y, a% d+ Z
5 i1 z( A& a( b) i- $title = $_POST["title"];
3 U* v f, c' L2 l - $content = $_POST["content"];; i, O ^/ j7 X' X0 r
- $tags = explode("_",$_POST["tags"]);3 x5 N9 K: X; [8 s8 o% {6 u
- $cate = $_POST["cate"];
; Q0 z6 D' j* M% b0 E/ n) _$ } - //print_r $tags;
1 S1 P9 {; ?# ` - /// q$ I3 w: u) I7 p7 f
- //4 u; P$ `" C$ I- F5 m5 F! `9 q
- $wp = new WP();
~" R- c. Z, _1 M1 j - $wp->main();- F& V7 b; a$ k
- //
+ G/ P" R6 ?6 z& q, z2 ~! M - $my_post = array();
8 F2 } O' g% w) F - $my_post['post_title'] = $title;" O C2 l3 J& A6 G' T1 q0 p) ]: [( V
- $my_post['post_content'] = $content;
/ L5 d- h E! K0 j5 r0 e - $my_post['post_status'] = 'publish';2 r) r; Q$ L2 K( _" V
- $my_post['post_author'] = 1;: t$ d7 C/ E% p$ C( z2 J* v: s
- $my_post['post_category'] = array($cate);- m0 T4 ~9 S8 B7 K6 |: r+ b
- $my_post['tags_input'] = $tags;, L, s5 f) F+ R6 D5 [; K
- //$my_post['tags_input'] = array('tag1', 'tag2');9 f+ i; c4 v6 R! e
- //$my_post['post_status'] = 'future';9 v1 |8 C0 w4 {9 W/ _0 A
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 T5 Z( i3 M' l# \( ^# H C: O
- o( f: m# g8 s; y0 }" M5 u$ A- // Insert the post into the database6 d& I0 n3 h5 B
- $ret = wp_insert_post( $my_post );
% L$ F5 q. `, k. M2 I- |# j" V3 C* w0 c - echo $ret;
+ z: @* w2 B7 P& h5 f/ W7 L - ?>" v* T/ j' Q! E/ z5 g* r
复制代码 我自己写的
( V% q# I; M/ j( G8 z$ ]2 j7 `插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|