|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! d) d& G* n5 S- E( f* [3 s
7 y; H( s$ B0 T. Z4 X# |直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% `3 y n, D: B4 o1 ]
) m& Y/ b( M0 o* W' T% ~8 f' M我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ _9 o4 G$ u9 R& v0 P: |! {: A
6 S* c8 }' V) O, g3 ]% r6 V" c方便实用 简单 何乐而不用呢- 3 `* Z* C# x3 ~8 l
- <?php
& U+ |0 W9 i" \6 \9 [! ^- l5 l- @) o2 ~1 Z/ j
! ~1 X- f, H' O5 S7 S" V p0 ~# L% o- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 A0 D; }& [- ~ - require_once( ABSPATH . 'wp-config.php' );2 j$ o% q$ h9 [# X0 L9 G5 e/ `
- require_once( ABSPATH . 'wp-settings.php' );
7 g3 U6 R: h* o; P - require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 f" H# `- U+ N" w8 K7 l5 v - require_once( ABSPATH . 'wp-includes/functions.php' );3 M; P: S7 b! d. s E
- require_once( ABSPATH . 'wp-includes/plugin.php' );
& w- }2 ~" z7 ]# y. d: W - $title = $_POST["title"];8 r/ _" F" ]; M i/ {
- $content = $_POST["content"];
- T6 f. k- \+ x/ g/ o - $tags = explode("_",$_POST["tags"]);8 \- Q N% Q, [. O3 N5 o* n% J% n# w
- $cate = $_POST["cate"];
" @! v# D% o: s! [& O# k - //print_r $tags;, F6 w+ q W, D* X2 a, N
- //. z# Y" _" y7 }2 {3 \# N! u; f+ i m
- //
" T! B! @* C/ c& ^. B - $wp = new WP();0 r4 L2 i% F% K, T4 k9 I7 `/ `
- $wp->main();* G& P* o7 E3 X$ h8 V
- //0 f3 s2 z$ m4 L# R/ k
- $my_post = array();+ I% ^- ~0 e1 s! J2 f- [ b8 k
- $my_post['post_title'] = $title;
: p- W/ S- l* S$ D L3 h5 h - $my_post['post_content'] = $content;: B. E+ [" b8 |
- $my_post['post_status'] = 'publish';! y; ]0 a9 t# u
- $my_post['post_author'] = 1; }0 @. w% s2 T3 }; H& u5 q, A! T
- $my_post['post_category'] = array($cate);
9 D% k) ?# U% E$ A" e, d6 ] - $my_post['tags_input'] = $tags;
) W7 Q/ {3 ]$ \3 h, d2 Q - //$my_post['tags_input'] = array('tag1', 'tag2');" F/ l, v9 E3 n$ w2 ?, {
- //$my_post['post_status'] = 'future';/ `# j6 T6 `, O) J/ ]* [! c0 Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';2 }" ? P( A& Z7 y$ N$ G, g
- $ w; C& j8 o- e; \% ?; U
- // Insert the post into the database
" H' C2 H3 I4 I - $ret = wp_insert_post( $my_post );$ p7 F8 d# [% _3 H5 \: _9 ]
- echo $ret;) {) G7 ~" r* Y0 M( v
- ?>
" O/ a) J4 e0 B* f- k
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 7 d# b- u J& ?
- <?php
1 W# M8 |9 H+ a7 W# ]$ ] - define( 'ABSPATH', dirname(__FILE__) . '/' );
6 r7 R7 P7 t, H2 j h7 v - require_once( ABSPATH . 'wp-config.php' );4 U& n+ P' m# p1 T
- require_once( ABSPATH . 'wp-settings.php' );* ?! Y- t& V/ z! w- d& u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 w( {3 m5 K* h9 Z# @. E# b# g9 I9 v - require_once( ABSPATH . 'wp-includes/functions.php' );
2 S: Y4 o+ u' W' @# w- W3 G( g1 a - require_once( ABSPATH . 'wp-includes/plugin.php' );2 Z9 j; F2 c5 j2 @4 n2 R
- $pic_name = $_POST["pic_name"];
# s2 _# K, X7 y - $pic = $_POST["pic"];8 ]8 D& c% y2 d% L. l# d1 M
- if($pic != "" && $pic_name != "")
Y1 t3 ^8 \( J4 s- s2 u - {
) h+ Z: q8 D! b# u - $path = "images/";8 o% W* W! X% B8 E+ J) i: w3 p7 n
- $pic_name = $path.$pic_name;
, h2 d' T9 {: _ - echo $pic_name;
2 c. Y. b2 o3 W& J4 W3 I - echo "||";
& [1 w0 \) O; E9 N9 u! n - error_reporting(0); q) V! F' E6 ]8 j; ? X
- mkdir("images");
( S+ S( S& [& Z! F# }. z - $handle = fopen($pic_name, 'w');
9 a* w) X4 d; D; m& C - echo fwrite($handle,file_get_contents($pic));; Z) Y7 S% J5 Q- I0 t: Q
- }
$ i5 X1 M1 h3 V" Y" j$ P - ! q% B0 D# |% c( n
- $title = $_POST["title"];% ]. S8 }7 s G! f
- $content = $_POST["content"];6 Q, q0 p" `0 M9 G+ W
- $tags = explode("_",$_POST["tags"]);7 E) K5 H2 b, [% `/ L
- $cate = $_POST["cate"]; m) V9 G' Q& q1 @
- //print_r $tags;9 z- Y4 A" {5 W: L" a
- //
2 _$ M, c- X) z - //
; s# C& t7 h( J% v% i4 E - $wp = new WP();( V) C" f3 L8 ]; U0 }( Z9 h8 ?
- $wp->main();
% h) [- j, u) S! y - //! y/ s3 r) f6 \- x8 C- f
- $my_post = array();/ |1 u4 M# I# ] B- q! x- F
- $my_post['post_title'] = $title;
& u: i# r2 D9 c# [ - $my_post['post_content'] = $content;
' G/ J' d9 P! d. j/ u - $my_post['post_status'] = 'publish';
& B. o% ?2 T# _+ F- E& i* g! l - $my_post['post_author'] = 1;
$ z W* {' n5 m& R, m - $my_post['post_category'] = array($cate);
3 S8 n+ |0 f& ?# ]5 x. ~ - $my_post['tags_input'] = $tags;' f# U$ A* L4 p- `3 c7 L1 |
- //$my_post['tags_input'] = array('tag1', 'tag2');* b% q3 Z& ]0 V
- //$my_post['post_status'] = 'future';
5 t3 T4 o0 C5 C - ////$my_post['post_date'] = '2010-07-04 16:20:03';
% r4 W. z# Y* ?- V7 | - 6 R8 d& o7 T8 r7 E8 s
- // Insert the post into the database Z" \$ t# c' q& O- @5 Z
- $ret = wp_insert_post( $my_post );" @8 Q2 V% J. z, W! ^5 q4 ]; u
- echo $ret;
1 ~/ r" g3 c8 A# M7 I - ?>1 o# r4 k h0 r# ?4 O9 |! {& `
复制代码 我自己写的. E- Z ?% w0 P+ C2 e, V
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|