|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 }% o+ {# L W5 k8 s5 `- B
! Y# k; E! J9 s) s8 }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
$ [3 f/ q+ x9 z* K3 A! R/ {% A" x+ K, b$ z0 N
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: r$ Y" u3 o; \# K
3 g; C* ~) a1 j. ~& K' G方便实用 简单 何乐而不用呢
9 k4 {4 B8 m+ N6 u' ~" @* f' w7 f) [- <?php
, G5 G1 h' g6 z0 w
, c3 I+ P9 l( `! j- define( 'ABSPATH', dirname(__FILE__) . '/' );( w/ Z& ~/ Q# q4 g2 ?5 |
- require_once( ABSPATH . 'wp-config.php' );- G5 n# I0 x3 L/ S1 O
- require_once( ABSPATH . 'wp-settings.php' );
' c3 R: {* X% L8 F) P' f& D - require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 c! i f/ Z6 U2 e5 k% n% Z - require_once( ABSPATH . 'wp-includes/functions.php' );
+ B3 M4 t' C4 b5 R2 [& S - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ Z- P, U9 ?3 ?; F9 X4 h X2 t - $title = $_POST["title"];# [" V* z0 N1 F! ?7 v) G# g* C
- $content = $_POST["content"];
1 [( f8 G+ G9 _, m3 }- N& P! Y+ j - $tags = explode("_",$_POST["tags"]);
* l' n( P; m* @" p8 G% Y9 ` - $cate = $_POST["cate"];5 [0 W( u& X; e7 M& |5 Q3 F
- //print_r $tags;; } ]6 G' U8 m$ l
- //
+ |& I' }. s1 ] - /// S: j: y% X3 {: t" K& Z) v
- $wp = new WP();$ R/ C: w+ j F* g2 M
- $wp->main();
- [9 n# w5 b+ ~8 k* p - //) H4 n/ C5 D: g @" h: K8 R
- $my_post = array();- |0 n4 c0 n; ^! T# F, C) b1 F
- $my_post['post_title'] = $title;/ Q7 u. j1 u( `/ p( ?8 I
- $my_post['post_content'] = $content;* L, R7 C: S! Y. R3 K
- $my_post['post_status'] = 'publish';
' n' L. _0 z- L% r1 B5 v - $my_post['post_author'] = 1;0 `# ]7 d5 G4 x% J+ \
- $my_post['post_category'] = array($cate);
) S$ f5 c' M3 Z: @/ q - $my_post['tags_input'] = $tags;
8 Q, l" i5 ^; z: d+ T! e* i2 n - //$my_post['tags_input'] = array('tag1', 'tag2');
Q9 p0 G& X7 K% A4 x! f4 p - //$my_post['post_status'] = 'future';5 s6 R; ]- o6 z9 l
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
- U) J0 w" G7 n- y& y' m1 K - & R- t8 L$ B9 h( v
- // Insert the post into the database
0 e: K( ?9 G6 a; d' H - $ret = wp_insert_post( $my_post );& b. J' g0 J, a+ T, I) b* n
- echo $ret;- I) g+ e" y2 j
- ?>
1 D: ^+ X+ g& w+ ~- Q( [% d. X# i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 j1 G1 y* e$ n
- <?php
* N" r+ l0 p$ ]* ? - define( 'ABSPATH', dirname(__FILE__) . '/' );
7 }: q2 y/ W9 W' a) S c - require_once( ABSPATH . 'wp-config.php' );. T" E ~3 P5 \
- require_once( ABSPATH . 'wp-settings.php' );
6 j4 f( `5 ]6 e$ A6 n- b7 j - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. K, e# H" H8 P - require_once( ABSPATH . 'wp-includes/functions.php' );
, k% R9 p8 X% Q7 j, n2 ~, G - require_once( ABSPATH . 'wp-includes/plugin.php' );7 t5 a9 {* ~* @$ Z4 h
- $pic_name = $_POST["pic_name"];; D1 S& A( O( [ @ M
- $pic = $_POST["pic"];/ {) M6 b/ N* ?9 M }7 J
- if($pic != "" && $pic_name != "")
/ k1 n( z8 b C# { a - {
& w8 D E1 _0 w, ^4 { - $path = "images/";
* V7 \8 Y# a7 A6 H5 Z - $pic_name = $path.$pic_name;% u/ L7 j4 U6 J/ }/ Q' j# _ C
- echo $pic_name;
6 I( `4 G& @" V. [ - echo "||";* N9 w# R6 ?, W. ]! X8 j6 V
- error_reporting(0);
2 o4 _: j& F; q4 l - mkdir("images");
( B4 V/ e0 d" Q' g - $handle = fopen($pic_name, 'w'); v" l5 N2 o8 o5 G5 r' D
- echo fwrite($handle,file_get_contents($pic));" T" t/ Y0 d0 B1 G
- }& I4 s3 |" O% K0 `2 U! t; C3 {2 M
9 ]' S$ S6 c# ~- $title = $_POST["title"];7 j1 S4 s, e2 T! d1 b/ t7 a# z
- $content = $_POST["content"];' s5 j) w# H f( i+ a4 r/ _
- $tags = explode("_",$_POST["tags"]);
3 \: c4 P& e" [+ v0 s( A - $cate = $_POST["cate"];! l! U" V H4 z$ R1 `
- //print_r $tags;# k$ P. m r) E" [* C
- //
% i" C3 d! ^: U; W3 {9 X- a; c2 B4 G - //
( \, r% Q8 L$ O, L: a! q; F - $wp = new WP();- ^. Z+ _" A, M W
- $wp->main();
6 v6 J9 r' l, G/ `: [8 m1 Z: u - //
4 Q/ L7 J+ }" Y5 V8 p# y& i: w - $my_post = array();& i1 A; h# f" Q& O$ g7 G$ v5 x
- $my_post['post_title'] = $title;7 m8 m2 }+ M4 P3 s: F1 r8 q- T* \
- $my_post['post_content'] = $content;
. K' U# Y* J6 x - $my_post['post_status'] = 'publish';$ J5 h2 M5 W! {; d- Y% O! K
- $my_post['post_author'] = 1;, h3 O+ |) t& W, U
- $my_post['post_category'] = array($cate);
$ P! U2 Z, c1 ^ - $my_post['tags_input'] = $tags;5 V! Q8 I+ V, T
- //$my_post['tags_input'] = array('tag1', 'tag2');
' R. D# F- I6 ?, a - //$my_post['post_status'] = 'future';+ _& ^ s1 S: C; y! a1 h
- ////$my_post['post_date'] = '2010-07-04 16:20:03';+ U0 d: o- H9 r- \& n' ^3 `, B T
) a$ f/ r5 j, y- // Insert the post into the database; Z8 |2 v! K* i' A, y5 z
- $ret = wp_insert_post( $my_post );" |& ^, e, ^* Z* s" s ]
- echo $ret;0 w" r6 W- L+ D$ ^
- ?>( Z, L( { b% z3 {: a4 X) W4 G
复制代码 我自己写的( ], t7 ~8 N' ~% u B: T, Z
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|