|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. y- w+ _& e, K% }; C6 b$ H: r
- R# G/ r% m7 c* R/ B# s" j" }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
! t( L! c$ O& U, m& y; Z n( Z1 a: [( _2 C$ S, L! K8 P: |
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% W, {8 m' G' p3 Q: V: \2 {
" b! B* c9 f S方便实用 简单 何乐而不用呢
1 L, b4 [' ]* s) [+ C, m6 n. R- <?php) L% @% q3 j& `: w
: M% B& f* m9 _- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 y1 Z V W& |" ?+ \ - require_once( ABSPATH . 'wp-config.php' );
1 X4 ^3 e5 v: M( S6 p' ~ - require_once( ABSPATH . 'wp-settings.php' );" E, d/ Q5 i7 A, E" g, T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
# k) D+ |1 S, Z% J - require_once( ABSPATH . 'wp-includes/functions.php' );
, v- z+ {& C8 u1 I- q0 O' c - require_once( ABSPATH . 'wp-includes/plugin.php' );4 x; U/ q& d& U; ^+ R
- $title = $_POST["title"];0 g" R+ o! p) v7 W3 Q& @
- $content = $_POST["content"];
8 u+ _7 X4 R1 ~8 o3 q9 E; m - $tags = explode("_",$_POST["tags"]);
. |' q4 Q+ o. a. V* n - $cate = $_POST["cate"];
) X# p+ K( I7 x9 c' O - //print_r $tags;3 V) C0 r7 n2 r% z& C" K9 U
- //
- e! A# X; K" }, \ - //
% H& j5 Y+ F5 e( o - $wp = new WP();7 ~% k& T4 J+ J% h% I @ d( i6 J
- $wp->main();7 J8 H/ E K1 D5 e
- /// i e- l+ L$ m: \- G
- $my_post = array();+ P! X& x' o; p# i }, r9 s
- $my_post['post_title'] = $title;
2 o0 ?4 h& }# T5 X: o6 E - $my_post['post_content'] = $content;: l% P- s3 @4 r/ Y" k
- $my_post['post_status'] = 'publish';
( h1 p7 j) f9 _4 w4 P - $my_post['post_author'] = 1;# u) Y- U, q8 N1 V" a
- $my_post['post_category'] = array($cate);6 w& Y# M9 y/ s+ h
- $my_post['tags_input'] = $tags;: E+ ?4 M( j2 D2 H ~4 d1 o4 E
- //$my_post['tags_input'] = array('tag1', 'tag2');5 a/ [7 L: o1 j3 j7 w% D( c# `
- //$my_post['post_status'] = 'future';2 g/ T9 ?/ E! k$ J9 x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ w& r5 n' y8 Z( M Y5 U$ T6 @ - 2 H, N( P4 z+ i6 ^; ~
- // Insert the post into the database
9 }# {; Z9 S+ K& k* e - $ret = wp_insert_post( $my_post );' o% L6 I# r2 |
- echo $ret;
1 C8 Y8 W9 W# u. L) E$ [9 j8 R$ C - ?>6 Y5 l- [" P2 m2 p8 D! P
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
7 P9 n2 e7 _$ e8 b3 }, ?7 ^9 O- <?php
, ?0 ?# T8 R& m: `( u7 N l - define( 'ABSPATH', dirname(__FILE__) . '/' );
- S! r; E7 s" v( B4 r4 C. c - require_once( ABSPATH . 'wp-config.php' );
8 v, J1 G. O2 C* {, z - require_once( ABSPATH . 'wp-settings.php' );
! H+ K; e& w4 S9 b" x3 X0 m - require_once( ABSPATH . 'wp-includes/class-wp.php' );1 F! V- i0 v# X# F' I* X t2 y
- require_once( ABSPATH . 'wp-includes/functions.php' );, j k6 v- i7 I5 L
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 o1 R; x% {2 @
- $pic_name = $_POST["pic_name"];
5 H0 E2 A Y% J( t" ? - $pic = $_POST["pic"];
6 M% Z; f6 J8 x) {7 o4 x& B" f - if($pic != "" && $pic_name != "")9 E6 x% X, `3 C7 n" Q& N* f) [1 Q
- {
, R2 d' J3 s! F( o f - $path = "images/";# E P/ |( O1 `6 S% v
- $pic_name = $path.$pic_name;8 U( }* c9 j6 L- C7 ` a' o
- echo $pic_name; E! b2 L+ ]9 `; W
- echo "||";
5 o$ p, E k6 l5 I4 j - error_reporting(0);
+ D7 V- e: a8 w" |' v/ q - mkdir("images");
8 u2 T; E: K+ f$ D% `2 _' M - $handle = fopen($pic_name, 'w');
8 S4 U- D; t3 P+ g - echo fwrite($handle,file_get_contents($pic));4 o. N* G3 I7 C- B2 @, E
- }- D. Y0 [% O/ I1 Y. M7 p0 D0 z0 S
- - N4 [3 P8 y6 d+ U2 q' H- a$ r$ X
- $title = $_POST["title"];
, T# a+ C t5 U+ \9 i; o7 b - $content = $_POST["content"];7 g$ {. }9 N: v8 ?: t5 P
- $tags = explode("_",$_POST["tags"]);
D( r- R" A N4 w6 c - $cate = $_POST["cate"];
* w) {; N; g6 n5 n1 o' r - //print_r $tags;
1 X1 }2 m8 A5 g) ` - //
! s8 S# N4 g/ }4 V - //' o0 ?- g" e5 i* p! H- _; Z- T' R. M9 d
- $wp = new WP();
- q& N+ b6 d* G; _/ U9 P; s8 | - $wp->main();
3 P0 ]( B5 }; o! z; M/ X4 ~& T - //
7 w6 L" D5 e. l F3 T - $my_post = array();% C: l: Q3 u: y$ r
- $my_post['post_title'] = $title;
( E) h# L; u4 ~) |& X$ B; H - $my_post['post_content'] = $content;
0 Z* B! K+ c8 m0 n3 Z/ g1 n - $my_post['post_status'] = 'publish';5 ?. d5 c: |% `5 X! v7 g) U' K
- $my_post['post_author'] = 1;2 V$ f) v% T& I- }. p
- $my_post['post_category'] = array($cate);
7 L2 w: S! y1 Z/ M+ k - $my_post['tags_input'] = $tags;
) B5 v, ], |2 P' \, B( W - //$my_post['tags_input'] = array('tag1', 'tag2');
$ }$ J, L( _9 @ - //$my_post['post_status'] = 'future';
* G' i7 Q+ a5 [ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ ^1 H2 I3 u( P3 k& o - 4 r( l O I. w+ v. w" p
- // Insert the post into the database" Y* {- D4 n0 Y1 _
- $ret = wp_insert_post( $my_post );. j W3 d2 R: t, u4 n, s# ~" d0 c
- echo $ret;
; r8 h6 L; | M7 F5 R4 w - ?>
* s. x3 @8 W5 w$ }
复制代码 我自己写的
$ n/ ^ R, [) f9 @0 Y3 E插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|