|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
% \$ l2 F3 Z7 b2 q( h7 y# m, F* K; ?/ v0 n* Q2 M
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
& r" r2 F5 g0 q* F$ O9 B
2 V6 Y; ?/ x2 Q( O# N F我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
1 J* t ^. s" _& S- o7 ^% Z- Y% V9 }& \7 g3 E4 p+ o
方便实用 简单 何乐而不用呢- + p1 T2 n( ]6 {& c' R/ N
- <?php5 j5 a8 E7 h- f9 n {
; Z) a. m6 r$ P7 }5 b- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 |8 W1 F7 k5 d ? - require_once( ABSPATH . 'wp-config.php' );
0 f& t4 i3 n# x8 w# p% N; G. Y' } - require_once( ABSPATH . 'wp-settings.php' );
/ M5 c' Z" g* _ o5 o - require_once( ABSPATH . 'wp-includes/class-wp.php' );6 R- y% ?' P7 j: Y, y
- require_once( ABSPATH . 'wp-includes/functions.php' );
7 C- c2 U5 f# }1 Z- x* a0 d - require_once( ABSPATH . 'wp-includes/plugin.php' );- x- J- g& D7 A/ X
- $title = $_POST["title"];) I$ o) ]& H- `4 L
- $content = $_POST["content"];5 a6 ~; U1 p! ]2 e
- $tags = explode("_",$_POST["tags"]);% u2 G5 g; j7 ~1 z
- $cate = $_POST["cate"];0 t# b0 n) g7 Y
- //print_r $tags;" y0 \8 l" `- U3 I' E4 a
- //8 O" Z1 g* W9 G/ f
- //: V( O X9 a, {) X7 _. ~
- $wp = new WP();
6 L Y" K, z* F1 l- | - $wp->main(); O* v! e% F# v/ a4 _/ P8 g
- //! s/ A# V7 {. u; N( R
- $my_post = array();
5 U4 f @3 c5 p# A# g - $my_post['post_title'] = $title;7 z& d% [& Z! G. H3 r' y" g
- $my_post['post_content'] = $content;
: q+ o: G! Y3 `1 X9 A% ` - $my_post['post_status'] = 'publish';
4 P/ P1 {% m: \( v# |+ b - $my_post['post_author'] = 1;2 W; ? {( ?0 h
- $my_post['post_category'] = array($cate);
8 x! h9 r3 r* t- u6 N& V - $my_post['tags_input'] = $tags;/ \6 t! [( J2 V$ j y/ O) g: p- o
- //$my_post['tags_input'] = array('tag1', 'tag2');
9 N$ r; T3 |+ a: \ - //$my_post['post_status'] = 'future';
/ ?/ H! L" Z9 l9 l* w1 G/ J - ////$my_post['post_date'] = '2010-07-04 16:20:03';. Y7 o' c; k* H1 ~8 {
( U8 d1 |% S6 ~( q# l$ d+ ]- // Insert the post into the database6 p* Q% L3 T( f/ g+ O9 C
- $ret = wp_insert_post( $my_post );% f6 t6 y4 c) c; q7 Y0 j
- echo $ret;
i% o0 i6 N* c; J$ H - ?>
" I" c/ o7 u: C7 z1 d
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- % _/ E- C: ^( O' S6 v
- <?php
) j6 V$ R/ J; h6 Y) q {, {' o - define( 'ABSPATH', dirname(__FILE__) . '/' );
$ n9 Z" b* @' p - require_once( ABSPATH . 'wp-config.php' );2 ?. Z3 y6 k9 }' m7 M& t% A
- require_once( ABSPATH . 'wp-settings.php' );
2 p: j2 ]$ s3 c) L. v6 I - require_once( ABSPATH . 'wp-includes/class-wp.php' );* c' q' \; x7 `9 [2 j- X$ T
- require_once( ABSPATH . 'wp-includes/functions.php' );
# O' w& x1 u8 O4 [% y; V0 F5 U - require_once( ABSPATH . 'wp-includes/plugin.php' ); Q: u# |+ `5 x. N1 F* L% q/ L
- $pic_name = $_POST["pic_name"];8 C- Z& X0 Q) p/ P, h" b! `
- $pic = $_POST["pic"];
5 e" M' K- d y - if($pic != "" && $pic_name != "")
K, u# K6 m' i! B1 H - {- z# L8 S, _4 p
- $path = "images/";: X% H' ^; t7 l$ M
- $pic_name = $path.$pic_name;/ `: A2 G" I- ^& x. m2 S5 g% C; V9 N
- echo $pic_name;+ c1 C. c% V( e- M$ X3 m
- echo "||";
8 p% p# J' b1 P/ ]+ N0 P m; w - error_reporting(0);9 _5 [% B( Q& j; L
- mkdir("images");# v4 s) p- X: u; U. _
- $handle = fopen($pic_name, 'w');, O9 g M" L4 O+ X' D, K6 a
- echo fwrite($handle,file_get_contents($pic));
1 n, t U G% ~6 y$ U - }" T# L2 j. _' I9 E! Q6 r
# c1 D6 I8 R( G* {. E" Q- $title = $_POST["title"];
4 M* n" p7 o- z6 f! T - $content = $_POST["content"];
/ \+ y( c& g+ N# A" H) R3 H$ [ - $tags = explode("_",$_POST["tags"]);& }) J; p( Y' d3 d
- $cate = $_POST["cate"];
1 f1 H6 ^' F/ Q1 M0 a - //print_r $tags;% r, y) M2 e5 o1 ?: O+ {" ~/ I
- //
6 c. H( w* X9 C8 i, O, Z& o$ i - //
% [$ F$ q, d* H9 q! ~$ N4 j" ^ - $wp = new WP();
/ @. \/ w4 m; f6 [ - $wp->main();
[5 M( L" G, N/ I ` - //
$ y5 Z6 J: A$ r$ N - $my_post = array();
+ z& y6 f1 C( y6 t4 Z - $my_post['post_title'] = $title;6 T0 K& V! I7 o
- $my_post['post_content'] = $content;/ O/ V& A9 |9 A4 s
- $my_post['post_status'] = 'publish';1 ]$ U. b: f* n- o' Z1 f- z) o$ k
- $my_post['post_author'] = 1;
6 J8 [+ U, I/ J% _2 E$ L5 A - $my_post['post_category'] = array($cate);5 v* D: k% W; |4 G
- $my_post['tags_input'] = $tags;
* |8 Y H! @5 v0 z - //$my_post['tags_input'] = array('tag1', 'tag2');0 ?8 m' U1 I1 Z; V! q% `
- //$my_post['post_status'] = 'future';& Y5 p$ {) O8 v$ O6 q5 W6 f2 S
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
- y) {* ^ y- b" t1 n0 {1 w& x
: [0 e3 ^% g6 Z- b( c$ K- // Insert the post into the database
4 `3 R3 H4 j0 e+ E. w0 N" \+ M8 }- } - $ret = wp_insert_post( $my_post );! [$ I0 g: Z# y; ?, ?' R- _* Q% o+ J- Q
- echo $ret;
* g8 E! q/ p% E% ?0 M6 M - ?>1 B; [2 J- h1 _* {( G
复制代码 我自己写的
' K' K# ]" m& F7 B% I插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|