|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
6 ^+ K9 R+ X; t2 K; G; E7 @ C d
. W# Z7 R; H& f2 R6 i( G# O( f, U直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
# J z; x- l, q" y- O8 A- h% O
6 ^7 w9 D) ^/ \7 ?4 G- v我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) N# K/ C) i; C0 U- J2 a
0 E# \6 { h" W0 Y( |/ l方便实用 简单 何乐而不用呢- * }* V$ Z |; h) A( L
- <?php
6 t) T P$ `" ^! t+ E" R7 i/ J Z& A+ g - , Q, y2 Y. y1 [1 M
- define( 'ABSPATH', dirname(__FILE__) . '/' );. @0 n% F, |+ J y
- require_once( ABSPATH . 'wp-config.php' );
% |( f# a0 Z9 z/ R% M& l! b - require_once( ABSPATH . 'wp-settings.php' );+ [! g+ k. `2 h7 s! L
- require_once( ABSPATH . 'wp-includes/class-wp.php' );+ ^, B" Y2 D+ ~/ z% k# u
- require_once( ABSPATH . 'wp-includes/functions.php' );0 h4 E& p) \- T" k
- require_once( ABSPATH . 'wp-includes/plugin.php' );% o" g$ K; U9 t* \- V9 ~; H6 R1 M
- $title = $_POST["title"];
# `! C1 s7 o8 L i7 B - $content = $_POST["content"];* w5 o6 T: b2 O: q2 J
- $tags = explode("_",$_POST["tags"]);
% |& G( m5 J4 X5 Z+ d - $cate = $_POST["cate"];# M7 P* t6 v# a( A8 O( t+ x
- //print_r $tags;6 y( i' t1 ^ Z
- //- q: y1 C" ]- v" I
- //
9 D& `/ ?8 c' w1 f! A/ H5 O - $wp = new WP();0 o6 X9 A0 y+ _' p: D
- $wp->main();
4 l& L+ N9 |( [+ a/ T! v - //9 ?% {$ g+ z8 {# N2 P- x
- $my_post = array();8 ~# h9 v( q8 q# S0 F9 t
- $my_post['post_title'] = $title;
& k( e/ Z/ J, m2 D - $my_post['post_content'] = $content;
5 p7 z2 M0 u( L7 d0 \. H( ]% ?$ M" L - $my_post['post_status'] = 'publish';6 G3 M" v9 P W _; j M0 o; b
- $my_post['post_author'] = 1;
8 Y' [6 w J+ l" l+ |8 ?- R7 E - $my_post['post_category'] = array($cate);+ U/ p* A+ X1 Z8 I& F$ i
- $my_post['tags_input'] = $tags;
- s0 M0 x. Y) _8 g1 R8 M% ` - //$my_post['tags_input'] = array('tag1', 'tag2');
' l& o& I/ }2 P1 @$ p* Q& t3 H/ w2 e- F - //$my_post['post_status'] = 'future';5 C, P$ W! p& a2 B
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ V/ P( @$ O' H/ q
& x3 A! y# d7 E* S! B5 V- // Insert the post into the database
1 d! }' ?1 q% J& D" _ - $ret = wp_insert_post( $my_post );4 Q3 R. `5 O, o5 |8 D2 h
- echo $ret;
; @9 h. n4 V9 S+ ]+ O8 ~# ?2 B+ e - ?>! B* C8 M1 H1 r1 p$ T% ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" ]7 t1 D: d: |) n- <?php) f! G' v- s8 Q/ c4 ~
- define( 'ABSPATH', dirname(__FILE__) . '/' );! g% h- }* p1 a
- require_once( ABSPATH . 'wp-config.php' );
8 p2 h. L3 D1 a* A - require_once( ABSPATH . 'wp-settings.php' );3 j3 o# ~+ A3 y! a
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 y/ i% ]# Q I2 c8 G - require_once( ABSPATH . 'wp-includes/functions.php' );
1 p, [: e- f6 x3 c& b - require_once( ABSPATH . 'wp-includes/plugin.php' );* w) f% l" x& r1 X: r) _& o
- $pic_name = $_POST["pic_name"];
. Y/ c' C8 e/ t$ t - $pic = $_POST["pic"];
0 J( m( Z7 b7 I1 g6 A/ A - if($pic != "" && $pic_name != "")' M- |* M+ X* L( @- I8 `
- {
* \9 \( f( ^3 @% k; M( B' e! O+ T - $path = "images/";
: p* j/ ]( w0 l3 l' Z0 u - $pic_name = $path.$pic_name;5 z" I, x0 E$ z* @4 w
- echo $pic_name;
7 L0 P. K' L/ J0 H" { - echo "||";; D5 \) G0 y# s- ^$ N$ p, e, r
- error_reporting(0);9 C5 O# }1 z, t8 [3 D9 i
- mkdir("images");( W2 ]; a: @: B* m
- $handle = fopen($pic_name, 'w');- i: N4 f; l6 e7 {) R; x( F Z$ i
- echo fwrite($handle,file_get_contents($pic));* |/ `7 n' j# k2 A& j6 n& J
- }
, m# C; P1 w# v D1 ^
7 H; d2 i* Y+ L1 t6 Z. t- $title = $_POST["title"];
3 E7 h, G+ P2 b - $content = $_POST["content"];- F# M4 ~7 r$ b8 i
- $tags = explode("_",$_POST["tags"]);
) Q2 Q5 v- c5 h - $cate = $_POST["cate"];8 N- l9 D7 I2 ]. Y! j( d5 T' z
- //print_r $tags;
( L( A; `& L0 B8 f, T' M - //
+ C. p3 n, _" y" K - //
" u) K, M" K) n3 D. @ - $wp = new WP();
8 ^ b& r( c' j" `& y+ k2 O - $wp->main();: S0 p$ J! s! U: o+ A" l! R
- //" F- q4 p& D: J; @( N
- $my_post = array();; l0 t1 t j# g' v4 K# T
- $my_post['post_title'] = $title;4 h2 V: a) j! M+ ]
- $my_post['post_content'] = $content;
: C9 b$ k+ h9 y1 V4 C5 y2 U - $my_post['post_status'] = 'publish';
* E! |) B0 b# k" g$ M4 p$ K- M$ q - $my_post['post_author'] = 1;! n6 ~1 G0 N$ b; b0 n5 W
- $my_post['post_category'] = array($cate);- t- J4 l* }0 I) [& C- I, p. C, C
- $my_post['tags_input'] = $tags;, M+ Z- `! {" M n0 M
- //$my_post['tags_input'] = array('tag1', 'tag2');/ v6 A" L3 ?7 V" ], s4 U* ~
- //$my_post['post_status'] = 'future';
, I) h. R" Z, Y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 L: C4 K* V- T9 N/ n. m
9 v; ?6 h2 |1 i x. r0 _) S, |/ d; B- // Insert the post into the database
" z6 V2 \" i8 }' v - $ret = wp_insert_post( $my_post );
; J! h' s! C. E1 g - echo $ret;
0 W7 o4 J& W5 a0 b: V( z - ?>4 r$ m$ r3 S0 R3 u5 V
复制代码 我自己写的
6 P# V" L+ r; K插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|