|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
$ f6 d% q |. h5 r Q" o+ k+ U% c" ^" |8 i5 [
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) ^8 O1 w+ a- w" s# a6 L) A6 L+ f/ a! Y! w" o! P
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了+ e. Y8 S0 ~3 X4 ?5 ?3 N% g; p' I' X# {
8 j9 b7 h, @! V9 D' _2 B! @
方便实用 简单 何乐而不用呢
4 g7 z5 d1 s1 X. V2 L# a4 p- <?php
& @. Q- H# c. V5 z
7 [; \6 o4 ?) W- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 k! t7 g4 f' o% S n& G; J - require_once( ABSPATH . 'wp-config.php' );
- s. w) k. i4 ~4 `6 G/ b; f& L - require_once( ABSPATH . 'wp-settings.php' );; j6 e/ w2 s9 ]) R. A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 |/ r: q) C. u7 S) h/ n - require_once( ABSPATH . 'wp-includes/functions.php' ); o% g; k5 O- h; Z9 o# T
- require_once( ABSPATH . 'wp-includes/plugin.php' );2 f; W6 i" X+ f
- $title = $_POST["title"];5 F1 d. L4 h9 I, X: B, @6 ~
- $content = $_POST["content"];
[' o5 ` n1 P- ?) p0 \( i5 O - $tags = explode("_",$_POST["tags"]);" h3 v8 C8 c5 f+ l( s9 h2 O
- $cate = $_POST["cate"];3 N0 b# b$ f0 [ y
- //print_r $tags;$ |6 H( n+ [5 ~. a
- //
9 w1 E; T) L K8 K. e) {5 N - /// N1 M; G- \: b/ ~8 b: U% c5 N8 U* M4 t
- $wp = new WP();+ }7 {2 m" b- t- ^' i0 d1 U/ a* n
- $wp->main();
6 I5 k! ^7 [4 _* |! E/ I - //
! I5 ^6 y; e& L8 U - $my_post = array();$ r# X) T( L4 [# i' K
- $my_post['post_title'] = $title;
. @* _; S! I" ^9 s* ~0 y- H9 X - $my_post['post_content'] = $content;
; I' T& u& ^5 ]' v - $my_post['post_status'] = 'publish';
+ r1 C/ O, a7 T - $my_post['post_author'] = 1;
+ o$ i& \. Z- L- [. A - $my_post['post_category'] = array($cate);
- J6 `' l7 s& Y5 x+ c, E3 m& N - $my_post['tags_input'] = $tags;
) Q. W; y6 n7 [/ v$ b - //$my_post['tags_input'] = array('tag1', 'tag2');+ q( a; ^5 X8 a! i# y! W# x
- //$my_post['post_status'] = 'future';: c2 `; j2 D3 {4 P! B/ t
- ////$my_post['post_date'] = '2010-07-04 16:20:03';/ l Q- {$ P# K6 B s/ F: J4 n
+ c; G4 x& Q* ~& |3 \- // Insert the post into the database
) f# U3 h2 @1 F0 Z$ F - $ret = wp_insert_post( $my_post );. z7 N( A7 B: I8 b+ o# x
- echo $ret;
' ^2 ^. j' h; v/ d - ?>
6 h" b6 o" F8 I7 o9 M1 I: m0 U$ S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; k: o, `- i/ C2 \( j2 S4 Y
- <?php& f2 m: W% c1 [/ o
- define( 'ABSPATH', dirname(__FILE__) . '/' );5 B& u. Z2 b2 Y, i! i
- require_once( ABSPATH . 'wp-config.php' );' |2 N) C* x) s' r
- require_once( ABSPATH . 'wp-settings.php' );, p$ m) \- b. W
- require_once( ABSPATH . 'wp-includes/class-wp.php' );: t6 D% M* T, a$ g: ^/ B
- require_once( ABSPATH . 'wp-includes/functions.php' );- u" v" M4 ~5 O5 }- f( p8 u; P) A/ D
- require_once( ABSPATH . 'wp-includes/plugin.php' );
3 \0 \9 T+ }) m0 M' E Q6 K - $pic_name = $_POST["pic_name"];1 S1 K4 P, h6 M) [% n# j; I, f$ O
- $pic = $_POST["pic"];$ E0 N6 ^2 J3 ~ X& i
- if($pic != "" && $pic_name != "")- P, U4 i; }+ \) D
- {2 S& ^0 o7 q6 v0 Q: K
- $path = "images/";
+ d5 B9 Q2 M/ F% @7 t9 {3 X - $pic_name = $path.$pic_name;( q7 q6 Q1 u. G) ~3 C. ~
- echo $pic_name;; h9 q/ e* V0 p3 C0 ~
- echo "||";
# G5 K1 J* F3 f7 T, o0 M - error_reporting(0);
5 ^, A+ t( p' }; D* @1 m" ^$ F - mkdir("images");
{6 J; j. q1 t6 g* M7 S3 F - $handle = fopen($pic_name, 'w');' T4 b8 |( W3 A) ^
- echo fwrite($handle,file_get_contents($pic));8 |# \" T/ v! V" j2 d0 p O, ]
- }
( G8 e0 i* f+ e& S" P/ [ - . T/ s1 I" k& N& y7 q6 U5 ?
- $title = $_POST["title"];- H/ r6 f1 g3 h* _& o' y1 E2 a
- $content = $_POST["content"];
' `4 A4 G9 h$ z% n - $tags = explode("_",$_POST["tags"]);: c+ x6 T) g; [3 |5 s- _
- $cate = $_POST["cate"];$ f: c1 J* ^) r2 m6 E
- //print_r $tags;% m8 @; `) \! O5 k3 j _7 e) h
- //+ m: R; Z( i0 Q2 m
- //
+ ?% x+ \* t" S9 \ - $wp = new WP();$ _- f! U0 G- R$ J& I# h
- $wp->main();
% @) b$ r" B% {' { s - //; j% g( W4 G: @: d
- $my_post = array();" W% G4 u {6 ]0 x" Z
- $my_post['post_title'] = $title;
3 \2 x4 N2 H3 G# m/ f9 ]) S - $my_post['post_content'] = $content;
/ r! h: S/ G2 ?) A/ V; s - $my_post['post_status'] = 'publish';# n O8 V2 |5 |6 n. g0 d
- $my_post['post_author'] = 1;
( c- m- ]; A1 r8 J$ r s% p- j - $my_post['post_category'] = array($cate);- x$ h$ N! z; b
- $my_post['tags_input'] = $tags;8 z5 F: d& m8 Y" |$ ^. r, K1 H: B
- //$my_post['tags_input'] = array('tag1', 'tag2');6 J$ @/ Z* Q# z: F3 g
- //$my_post['post_status'] = 'future';
. C# J. B0 u! ]) ~ - ////$my_post['post_date'] = '2010-07-04 16:20:03';# V" r: ~# }& x
2 r& g; q7 w. S- I) y- // Insert the post into the database
% l( k" o e$ V+ H1 o5 U - $ret = wp_insert_post( $my_post );2 C; n4 s% {9 d, `
- echo $ret;
1 Z4 Z4 x1 Q+ g - ?>. ?6 r3 { \/ X3 `7 f1 {
复制代码 我自己写的
+ f4 W& c7 T; ~! _2 V8 u' w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|