|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
d7 j- u$ W2 a6 j+ \
: Q' F x7 e) ~6 t! g( x/ g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持$ x. h7 l/ _0 y8 |: P( P6 L
" n4 o# s6 f( r& ~7 n我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了- O5 t9 E; y5 N5 B8 u
, @! k3 G0 Q6 M* P/ P! \方便实用 简单 何乐而不用呢
- P6 W: D' \/ d/ ^0 A8 g- <?php
0 M7 R+ b& v/ K3 _: P$ D2 L& f - # V" [: X6 r6 y& k% R4 {. h- P
- define( 'ABSPATH', dirname(__FILE__) . '/' );+ e. w! v' K; L2 U O* H, H* U
- require_once( ABSPATH . 'wp-config.php' );2 g" t" l7 B1 U7 {6 w
- require_once( ABSPATH . 'wp-settings.php' );
$ c& E* e0 J& q - require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ q1 i) z) y/ ^ - require_once( ABSPATH . 'wp-includes/functions.php' );; O' h7 o$ H6 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );; B# d+ t2 B, {+ b! H
- $title = $_POST["title"];6 Y7 v& T- ^# @' K9 c. V
- $content = $_POST["content"];
$ I a( x4 |& o! z - $tags = explode("_",$_POST["tags"]);
' j6 M7 n- k9 f - $cate = $_POST["cate"];
, \% y& n& X0 K. o8 A y4 M/ J - //print_r $tags;* c6 C& {. L3 Q: _$ ]8 |. _" F0 J
- //
* y* h/ O6 ~( V4 Q: E. R) Q# ` - //: c1 G1 V5 b) r \- Z
- $wp = new WP();
- y6 u0 e7 o, N. O4 B: P" u - $wp->main();0 H3 C; k5 G4 o7 K- p9 b0 j5 R0 w
- /// d* _5 d( L# @( C9 z8 l
- $my_post = array();
% M6 y1 w+ ] g - $my_post['post_title'] = $title;3 ]( X, z8 K5 Z' P
- $my_post['post_content'] = $content;( i! l$ [9 {$ k! r
- $my_post['post_status'] = 'publish';- ]& g- T0 d& P# C
- $my_post['post_author'] = 1;% t4 y2 O1 r' r/ E8 d6 P. S6 {2 i' p
- $my_post['post_category'] = array($cate); L" |* `' N) a3 ?0 Y+ L" x; J2 N2 w# t9 ]
- $my_post['tags_input'] = $tags;( O3 m2 e* P9 p
- //$my_post['tags_input'] = array('tag1', 'tag2');
& s( U0 l+ O) ]/ d/ \! ]; D - //$my_post['post_status'] = 'future';; d: K/ s! w( u) p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';5 D( D6 u- a5 V, `5 }+ W
- ) x/ s8 a# H% O; {6 d
- // Insert the post into the database
5 B" B$ O2 q; m7 A; g* p - $ret = wp_insert_post( $my_post );
( @/ V- M& B. B- j/ j - echo $ret;
1 b' h, X0 }; o" S2 l - ?>
9 ~. m: q5 n2 V+ G0 ?2 V6 D6 G! y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , o, [4 q- F+ Q/ A4 v D
- <?php5 ~. Q+ T& \1 e% v- ?, J" W8 G
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: v9 i: G; E/ c% e+ _, d3 E, m - require_once( ABSPATH . 'wp-config.php' );% G5 F8 |) \+ D7 [
- require_once( ABSPATH . 'wp-settings.php' );- Y1 Z& D1 ^1 W F: L% z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
& c# L$ g# p% i2 k) N2 d: o$ I - require_once( ABSPATH . 'wp-includes/functions.php' );. @- f. { V: K: l+ R; K
- require_once( ABSPATH . 'wp-includes/plugin.php' );, A5 V4 U; g/ S* w6 m+ b) ~% @5 p
- $pic_name = $_POST["pic_name"];5 w* E, S1 K3 F) _
- $pic = $_POST["pic"];
. m2 D- J6 U5 `3 ?. P* r! k- N - if($pic != "" && $pic_name != "")
* |, P, z" K8 ^. x( }6 Z. v - {# b3 Q, t$ {0 s! L) L/ f
- $path = "images/";& t2 \) |+ ]$ F
- $pic_name = $path.$pic_name;) O; D# B4 |* a& |0 j f" M
- echo $pic_name;
$ B( s, B: O6 ?4 L# q# O - echo "||"; V2 ^+ t. |/ T4 R- J0 l
- error_reporting(0);
; T: [' q0 D9 p6 x [1 c; S - mkdir("images");
. W6 E; t, T ~. a* U - $handle = fopen($pic_name, 'w');
# P: s( q6 v4 [) S4 P0 T - echo fwrite($handle,file_get_contents($pic));( D2 ~; |0 C9 i3 {
- }
+ }1 b+ M0 _5 ~6 A! M# T - 9 `9 @: s2 Q; y1 e& }$ {8 D
- $title = $_POST["title"];" a' [9 w0 [9 d0 t4 t% I
- $content = $_POST["content"];1 h6 H0 w) A! z7 T+ ?" L" z2 k
- $tags = explode("_",$_POST["tags"]);
$ }0 w0 \( b* v8 ] - $cate = $_POST["cate"];
) |* F$ x: x- Y- B& i* V$ D - //print_r $tags;- @5 j! b9 L, q5 }$ R7 J0 k; n
- //
* f; J' p8 U [/ m3 o2 n - //% k8 Q. T) I4 k9 I* s8 z9 M) z2 k
- $wp = new WP();" I) ?2 u, ]/ I1 D! W- A
- $wp->main();
7 E% f1 g, }, @6 m - //
5 p/ x& |3 l; e5 d3 b - $my_post = array();' H. C' e4 Q/ R) G$ d! A
- $my_post['post_title'] = $title;+ N- Q* u, b$ [8 v+ o" x
- $my_post['post_content'] = $content;; m. L5 X& C$ X1 D
- $my_post['post_status'] = 'publish';
; l. H& Y9 W4 @* f9 ~) m - $my_post['post_author'] = 1;; t+ @% k9 [$ H
- $my_post['post_category'] = array($cate);
, [& j; z3 y: V6 [# \ T% V" m7 F - $my_post['tags_input'] = $tags;* w8 l, o+ m* u2 X Z* W/ Q: P- z
- //$my_post['tags_input'] = array('tag1', 'tag2');
& u; R4 w. M) I c& W* H, ? - //$my_post['post_status'] = 'future';! P+ P- o9 K) M- H" ~) x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';4 ]% E/ i" b3 v5 R3 y
- A7 B& y! A% }: d! X: _- // Insert the post into the database8 @* O* E: F. x4 N+ B1 |3 ?( T. x
- $ret = wp_insert_post( $my_post );
- K- U2 o2 G U" L: d - echo $ret;
; C# m3 t2 z# G. E# Y - ?>' R7 i8 n+ a3 ^! \
复制代码 我自己写的
# M: ^$ f# `- n9 @5 q; p插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|