|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
: V" s, N' o1 m: O- a K
, H2 b p- ^4 K4 Y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持+ ?3 ] q7 B- y. Q+ w% K
8 B' M n" f7 j/ b我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 T9 s/ s S. D
- O4 |# H1 R. y3 S0 H7 |6 ^+ C( U方便实用 简单 何乐而不用呢- ' @/ ]! I/ w- b3 c: K9 D+ ^
- <?php
/ g' x q( B# b K: l - / a0 P/ @) i( W% B9 ?" w
- define( 'ABSPATH', dirname(__FILE__) . '/' );
~ N* y3 k/ S9 Q - require_once( ABSPATH . 'wp-config.php' );
* B- }9 a( S: X' { - require_once( ABSPATH . 'wp-settings.php' );1 j" q$ k* q& A, t
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) t. f3 ~4 I% i% {* n" F - require_once( ABSPATH . 'wp-includes/functions.php' );
# V+ s7 n8 y: h" q6 l& S - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ \: L6 j# _8 G( d* c# p5 J - $title = $_POST["title"];
% m. b" W) z$ k0 D - $content = $_POST["content"];
1 |' q7 Y: h P) ^/ ?% v - $tags = explode("_",$_POST["tags"]);
$ q# x1 w1 G: P9 @9 a# t - $cate = $_POST["cate"];
+ ^: k0 T, ?! j9 P - //print_r $tags;5 O6 H( c4 M* l5 ^: [3 U5 E% W
- //
- n8 Z1 R# i& }* @& j - /// U( I, H7 \9 ~8 C6 G
- $wp = new WP();) _; g& b% _" w8 u6 }- A2 N
- $wp->main();
8 u4 N) f9 _2 I - //1 ~* }( A8 Q$ Z+ i
- $my_post = array();8 K8 Z0 A) Z4 s0 ~8 J! O- |( Y' a
- $my_post['post_title'] = $title;
4 k: y8 R) h+ x, X/ W - $my_post['post_content'] = $content;- u7 c. P$ N6 b) {0 o1 i
- $my_post['post_status'] = 'publish';
+ U1 Q9 d2 o6 P3 t8 P - $my_post['post_author'] = 1;2 [, _7 Z) i9 G+ ]) U) n5 {
- $my_post['post_category'] = array($cate);
% @: h. D& D% F3 C* H - $my_post['tags_input'] = $tags;
- ?7 c( A' P) E( ~* r. S2 I - //$my_post['tags_input'] = array('tag1', 'tag2');
: F8 a+ j" n O - //$my_post['post_status'] = 'future';
- k5 Z9 [( H5 v1 O# a - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ ]" n+ \% q1 m8 l: L
9 @3 c% z- ~1 E: o- // Insert the post into the database6 Q$ ^( s3 ^, y: T
- $ret = wp_insert_post( $my_post );
1 T9 n- i1 N: ^8 k9 v3 L - echo $ret;0 t( P& Y7 C! @* ]' X* D
- ?>
7 N! p& i$ y0 g+ |2 B9 V H) [' j7 A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 J. F! T, l& A/ p- N- <?php
' x5 i" z1 J; Y& {4 ~# q9 G - define( 'ABSPATH', dirname(__FILE__) . '/' );3 _! a; |+ Q* d6 N; D0 w6 U
- require_once( ABSPATH . 'wp-config.php' );7 [; ]/ U1 u- J( [
- require_once( ABSPATH . 'wp-settings.php' );6 S; f, g& A% L1 c. P
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! y+ O7 S/ i6 C - require_once( ABSPATH . 'wp-includes/functions.php' );
+ X1 G2 B' e5 b: A - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 L* U! B, Y+ ^( y9 P% w - $pic_name = $_POST["pic_name"];
& `+ }- N- b: O! r! w0 c7 ^ - $pic = $_POST["pic"];* f+ m" S" u% }1 U
- if($pic != "" && $pic_name != "")! X! s/ z* H$ Y5 S
- {
: f; {5 L+ ?# s - $path = "images/";) S. _$ n8 N0 q& l! ?3 x7 @$ s1 Y) Q
- $pic_name = $path.$pic_name;
) S# d. T( e Z4 {2 A7 b6 Y - echo $pic_name;' `- m2 l; q( x% w; {* I+ P
- echo "||";+ r; y, e6 E/ u8 V& v9 R
- error_reporting(0);$ F! v5 d1 J+ ^; A, D3 L& A- C
- mkdir("images"); F( l+ _! r6 j' E
- $handle = fopen($pic_name, 'w');, G0 d& `% X+ p a& K' X
- echo fwrite($handle,file_get_contents($pic));
+ R" s( H" n7 ~/ {3 o; T2 S8 Z - }) H4 x; ?+ L6 [: \4 v! y- m
9 p F# P' G1 t! H" t- $title = $_POST["title"];
8 q- V5 M3 V" J0 @ - $content = $_POST["content"];! I& O/ y. d1 w# K4 o
- $tags = explode("_",$_POST["tags"]);
/ ^1 H+ {, w% q. } - $cate = $_POST["cate"];6 M& L4 m: ~% L {) D
- //print_r $tags;
% Y- y |+ R! w# Q6 R ~0 T9 w9 }) G - //
0 V& v! C/ C; N( T - // c0 q" Z- p5 i: B, y0 b z! C6 r* n1 Z
- $wp = new WP();" p, E7 Y: C; c5 r8 U- n
- $wp->main();1 `; R2 V% u, |* D' r0 D
- //
! u/ ]7 } b }* b6 B/ W - $my_post = array();
* a9 ]5 R V. O: ]3 w7 | y - $my_post['post_title'] = $title;/ R9 q) g5 e( X" t% e
- $my_post['post_content'] = $content;
$ m7 P" D- F. u( q" X. U - $my_post['post_status'] = 'publish';0 W9 B: @" @ J4 q* r& f4 c6 ~- D' U
- $my_post['post_author'] = 1;
, D% I9 _# X" U7 q - $my_post['post_category'] = array($cate);6 u4 D' Q* K& \5 |
- $my_post['tags_input'] = $tags;4 H6 e3 I% G' F0 }1 Q
- //$my_post['tags_input'] = array('tag1', 'tag2');$ c' l- ^* z1 c. p
- //$my_post['post_status'] = 'future';
$ T6 b, X" Z; E( W3 Z4 V7 M - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 L9 n; \5 s3 Y! j0 p) h! g5 } - - |, M% `! @8 v: i! G
- // Insert the post into the database4 j$ P8 m% H! Y8 m: D' P& G; A7 B
- $ret = wp_insert_post( $my_post ); o5 o) B5 v0 [% }* W% f( n
- echo $ret;
7 d( Q/ {6 J0 {0 y+ ?0 ] - ?>- l2 N) f, b$ {7 _9 T! B2 j _* L( k
复制代码 我自己写的* F* y9 ^- l7 d8 l
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|