|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ( f9 y3 f% }$ b/ E7 \, C8 k
# S; ~6 ]8 R2 K2 R直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持4 U T" l' C6 N. @7 {2 J# ^5 x7 x
& H! g9 T& Y8 X/ s2 [我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了5 M/ h' w, [$ a# i( J2 t
2 Q2 A K0 X% w! R方便实用 简单 何乐而不用呢
% w& b4 r& o7 j. J' s- <?php d+ c# S, G) [, I' W6 W# J
- $ U, P3 G$ t4 A, F3 M
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ _; k+ `; a# L) ]' E
- require_once( ABSPATH . 'wp-config.php' );: u$ F& e- V0 t/ g% n9 i) O; \
- require_once( ABSPATH . 'wp-settings.php' );
0 \% X. y+ I% q$ l6 B - require_once( ABSPATH . 'wp-includes/class-wp.php' );- S( ?$ ^* a# U4 l
- require_once( ABSPATH . 'wp-includes/functions.php' );; q N5 F, `1 ]+ d" Z1 z0 N! ]
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% o& ]9 i( }" p' _# ^ q9 H" S7 ?9 X - $title = $_POST["title"];% {& @9 B3 `7 ?0 u s1 G
- $content = $_POST["content"];
/ X* ^ q1 R" A, [& G) u: b - $tags = explode("_",$_POST["tags"]);
% `: a$ {+ ^1 ]8 u& o- t! l \1 p - $cate = $_POST["cate"];* F2 d. m( |1 f" B2 Y9 t
- //print_r $tags;! B) U+ j6 u8 n
- //. Z: p/ c t! Q* _2 w {. F7 A
- //
: h2 i, i, K! F - $wp = new WP();
, f; M/ `+ T; X$ l - $wp->main();
# n* r% Y2 f. j6 g1 y - //% ^- d2 ]; i. M6 p4 q1 v; A2 x; H
- $my_post = array();
2 n6 l( c( K$ ?; | - $my_post['post_title'] = $title;5 E% q/ v# t4 V( S
- $my_post['post_content'] = $content;1 n2 s" n6 [% s
- $my_post['post_status'] = 'publish';9 O6 ~3 o! z, z9 e, N
- $my_post['post_author'] = 1;
3 P' E- d2 v9 W* m6 E( U" }$ z - $my_post['post_category'] = array($cate);
' l" R. F% u& e M* x# c& Z5 F - $my_post['tags_input'] = $tags;. @( s1 G6 s, J; q/ O X
- //$my_post['tags_input'] = array('tag1', 'tag2');# T% g- u! z1 \+ v7 V
- //$my_post['post_status'] = 'future';" Y& H: U' _( K) A* K$ v7 i& n0 S
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
* K+ T" y+ u$ P: L. |$ l
5 I+ G# X$ @! i. z7 w# U6 D x- // Insert the post into the database4 n7 n9 M W0 m
- $ret = wp_insert_post( $my_post );+ k# e1 ^6 D; X; O& d; F! _8 e* ]; f
- echo $ret;
) a2 |: h2 Q; i9 E% ?& q - ?>
! }* |% h2 ^2 T+ C: ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( `. g# X, s* F6 U: Q
- <?php
. H& N8 w% m) Q N! P2 j- { - define( 'ABSPATH', dirname(__FILE__) . '/' );
1 y4 o1 O/ N& p7 { - require_once( ABSPATH . 'wp-config.php' );2 H5 K, s" ~: u. ?7 T# |9 K) p
- require_once( ABSPATH . 'wp-settings.php' );# V: H0 H& U$ ]0 C) j G
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 J; a) N0 K/ L' y/ a- c& |& ~
- require_once( ABSPATH . 'wp-includes/functions.php' );7 W& B* F9 K ^5 o! Y% T$ E6 o3 `
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" A7 }( N$ P }. q0 E - $pic_name = $_POST["pic_name"];* h4 G* [1 p. o. a# b: X
- $pic = $_POST["pic"];
6 U" \' v2 l% }8 M - if($pic != "" && $pic_name != "")
x. F; Y& J& m! m( T7 D$ s - {
( k s% I2 `# }+ W+ a. \ - $path = "images/";, U+ c; B" t% I* l" w9 O
- $pic_name = $path.$pic_name;
1 j! n9 |& Z7 z1 D; Z7 w7 G - echo $pic_name;
4 P! k* P7 y1 b0 m+ _6 t6 _ - echo "||";
6 B: z! a1 @4 g3 {8 x, H+ {7 k - error_reporting(0);& G6 V% k; a7 B
- mkdir("images");
# w. [0 X( z# G. @, V - $handle = fopen($pic_name, 'w');- a& t ~ l5 |/ |2 u7 g4 S+ m
- echo fwrite($handle,file_get_contents($pic));
! H; t; J! S3 \. n3 G7 ]- Y - }
3 R, M; ], F" R0 `- a- o
9 i' k, e. K8 z" @: f4 ?- $title = $_POST["title"];0 n) j( ~* c1 n$ G) Z
- $content = $_POST["content"];
1 F8 {* r, r2 C- w& @! H - $tags = explode("_",$_POST["tags"]);5 W# T% E7 `1 u
- $cate = $_POST["cate"];% p- a- W2 o5 l6 C
- //print_r $tags;
2 M1 d" h' A2 A. ^/ o8 n f, P, v - //
. C) D6 s( r1 e0 e% K B; r - //
# i- U3 W+ T6 m% @/ Y! Y0 v - $wp = new WP();& A/ O3 Z1 J" m+ z% J7 O! n/ x9 {% N
- $wp->main();8 e4 B; V/ k c( x3 i. S* J
- //, q i# \. _4 j. [% g' f: Z% L' n
- $my_post = array();8 E! {8 X; M" |" a
- $my_post['post_title'] = $title;
8 ^' `3 n0 ` o/ I - $my_post['post_content'] = $content;
- v0 w- }" l/ G3 q5 H7 W - $my_post['post_status'] = 'publish';' E; f/ |2 G" z0 r
- $my_post['post_author'] = 1;
# }8 U3 ]; h. a U) l4 l4 G+ O - $my_post['post_category'] = array($cate);
3 o- ?+ D1 P3 c2 V' H& X - $my_post['tags_input'] = $tags;- M7 Z7 o5 C# Z$ `; X+ ?
- //$my_post['tags_input'] = array('tag1', 'tag2');4 v8 K3 r2 \ |4 s; f- Q
- //$my_post['post_status'] = 'future';0 ?. R2 \6 N9 [0 K
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
c% ~4 b1 a$ l- A/ K9 M3 L - / M T8 @- `& a& B; R
- // Insert the post into the database
$ _: f, G. o0 |2 R$ a; k - $ret = wp_insert_post( $my_post );% n6 r) u, |% }) p
- echo $ret;
`3 C& [/ g7 U# v" c9 ^: V1 f& a - ?>9 {. g u; U1 E# `7 M4 N
复制代码 我自己写的4 S) J# P$ s ?# V
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|