|
本帖最后由 finder 于 2014-12-28 15:13 编辑
v7 |. }9 M4 }
- j1 @2 z# d0 Q直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持# x# l$ i1 ?" Y: |* C+ Y
: D: s; U: O; V% B8 w0 D% d- E
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; F( E8 _* J1 A# n( S4 Z* h9 y4 p: ?3 M. p
方便实用 简单 何乐而不用呢
1 k4 O) l/ [" j2 F; T- <?php7 e: F7 g' k) J: O/ J6 k( |/ W- ~' O
- / f! W% |5 s9 k8 ?$ h: J
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 `" Q$ w4 P6 F% z
- require_once( ABSPATH . 'wp-config.php' );
- [& @& ~: `1 z- v; h - require_once( ABSPATH . 'wp-settings.php' );; a& `" V9 {! o, ~- a" [4 o
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
- l4 }: Q5 r* z0 I - require_once( ABSPATH . 'wp-includes/functions.php' );8 ^0 N1 F( z5 A! D6 `1 P6 u
- require_once( ABSPATH . 'wp-includes/plugin.php' );0 S) F, `$ r" t( d1 H9 A! Z! s
- $title = $_POST["title"];
8 X7 _1 e" c- F+ m1 ~$ ? - $content = $_POST["content"];, X: ~; C: C: z0 T# T& J q- ?6 o
- $tags = explode("_",$_POST["tags"]);
5 v. p+ B3 S/ b - $cate = $_POST["cate"];# ~& _( L& P/ F: m
- //print_r $tags;: o4 q( P+ X% ?" O8 g
- //! C N9 g& \, o+ F, Z
- //
w3 j, y' U0 j- O0 X) G - $wp = new WP();
# O2 M/ F7 ?4 U8 Z, F+ h - $wp->main();
/ _- ?* P$ g" b) @ - //
# b( v1 {* L. A3 g a - $my_post = array();
- v ]5 A7 S% t( n - $my_post['post_title'] = $title;- x0 X$ o2 v/ w3 |
- $my_post['post_content'] = $content; k+ R' |( T' O
- $my_post['post_status'] = 'publish';
7 f% Q2 e) W: \+ x. M* I - $my_post['post_author'] = 1;
6 e5 W) A9 I/ n; c6 V - $my_post['post_category'] = array($cate);
) m3 |- X6 i. Y7 d- w - $my_post['tags_input'] = $tags;! }* ^: I* @; \" k& M N
- //$my_post['tags_input'] = array('tag1', 'tag2');
# ?) R+ _) Q9 U, ~3 a - //$my_post['post_status'] = 'future';
2 e7 T6 w$ S& E2 a3 } - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ E7 l$ {/ G' Y! P
: J$ M* P8 W. p2 ?6 x$ b& F, L0 } Z- // Insert the post into the database
: j: F5 Z- _# M6 b. d - $ret = wp_insert_post( $my_post );
" F) q7 B4 ` |% O - echo $ret;4 S2 ?7 _ z$ X `! _
- ?>
* R+ |/ K! v R) Q, F- b6 T
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 K* }- m1 ]+ i7 ?: o7 \' ?$ O3 _- <?php1 T* t4 b2 I# p3 G' A5 j/ J0 V
- define( 'ABSPATH', dirname(__FILE__) . '/' );
! o o! r7 ?1 @: n& |; U - require_once( ABSPATH . 'wp-config.php' );
+ h9 f$ o! Q( _. m4 i# E/ j8 N - require_once( ABSPATH . 'wp-settings.php' );+ p1 ?- F$ Z# t
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! T. t* W, H, O7 z - require_once( ABSPATH . 'wp-includes/functions.php' );
/ }8 ^5 @7 N( z& O" _ - require_once( ABSPATH . 'wp-includes/plugin.php' );
! n& C- X- I' ]) B' i* f - $pic_name = $_POST["pic_name"];' P5 e4 e3 i- ?! W: w
- $pic = $_POST["pic"];
9 N6 n5 T+ C4 y) a; E" P - if($pic != "" && $pic_name != "")
- C9 W7 I1 N: Y+ d- O - {" v7 o% S8 |5 i
- $path = "images/";
, h' J% `9 k3 _+ b+ e9 O) ^ - $pic_name = $path.$pic_name;
: w9 n# Z0 B F: C5 h! v& t( j - echo $pic_name;
7 T2 y/ o* M7 t% o7 g/ g - echo "||";
5 W5 z$ X4 s9 `1 i - error_reporting(0);9 Q6 B$ d9 Q+ K5 L5 z& ~4 H4 M
- mkdir("images");* L2 k; G" _8 f
- $handle = fopen($pic_name, 'w');
6 m& |: l. ? h" n - echo fwrite($handle,file_get_contents($pic));" E$ y" W1 T: k# A3 R; L
- }7 e4 b3 c4 ^+ ?6 _8 |" j
2 @# k9 E; W3 q; f- $title = $_POST["title"];: N- t7 f2 ]; c8 @- }2 ]
- $content = $_POST["content"];- w/ N3 E9 p, p" w& \1 J
- $tags = explode("_",$_POST["tags"]);/ t: d: Z7 s, ~7 v" p
- $cate = $_POST["cate"];
3 ]- a. v. w- @$ s3 n - //print_r $tags;
6 p# T5 d J3 C - //0 D) \: r* W' e6 j( N
- //
( ^, m1 M3 Z. J+ ~: j9 O - $wp = new WP();
. s; K v0 q+ P E5 m: J3 {6 k8 F - $wp->main();
" k, s$ j) d3 K9 D3 E7 |) d) E - //+ V3 ~# |8 W* H! {' f* V
- $my_post = array();, g7 t0 s) w( _. U
- $my_post['post_title'] = $title;: d) D! W% |! f" \7 a e
- $my_post['post_content'] = $content;$ ?! \ M" n0 P# [. H+ q8 A
- $my_post['post_status'] = 'publish';
' \+ b1 ^& |3 J2 j - $my_post['post_author'] = 1;, x' }: o! V& R
- $my_post['post_category'] = array($cate);
8 V. F3 |* R3 N! j% K - $my_post['tags_input'] = $tags;1 f1 ^$ E1 Y, j4 c( h
- //$my_post['tags_input'] = array('tag1', 'tag2');$ k6 p& j2 t- o8 d
- //$my_post['post_status'] = 'future';
$ l) y* F. [, s0 {! _3 n7 F - ////$my_post['post_date'] = '2010-07-04 16:20:03';, C7 r _1 z) W* q5 V8 C
- ; i3 J4 o1 T; N% m
- // Insert the post into the database. g) p. Y4 W: `$ Z
- $ret = wp_insert_post( $my_post );/ v; U2 }3 J8 v. V+ m' c
- echo $ret;* h9 j2 l% }' O+ u8 [/ g
- ?>
$ H- S1 x. C. n2 Y% g# N
复制代码 我自己写的+ u8 R0 Z: m( I% A8 k
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|