|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 p& Z( |7 }; ^
7 J) H3 U, c4 w; D+ B0 U4 }; b直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持$ t: {5 h) M, g) t$ P
5 Q% Q' D* G0 n5 D我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
# l2 X' b# Y5 I' y& N9 J' ]! N# i! M7 J( x' v
方便实用 简单 何乐而不用呢
$ Y( \) ^9 b* {- <?php
, ^* c& f' a1 ?, i `$ Q, w - 9 M( e2 a. t$ G" y
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 J' ?- B' n+ ~) p R
- require_once( ABSPATH . 'wp-config.php' );
! g: b6 S/ T8 E0 h - require_once( ABSPATH . 'wp-settings.php' );, @# q2 R* _) ]; l0 o8 N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );; z1 G- o% C$ l! l
- require_once( ABSPATH . 'wp-includes/functions.php' );
4 k( b3 }1 R/ |8 U! p: f1 C - require_once( ABSPATH . 'wp-includes/plugin.php' );
8 J+ i, q0 z+ c4 j - $title = $_POST["title"];0 ~4 W$ C- Z3 M9 N
- $content = $_POST["content"];
4 ?9 [ Q' M+ J0 B3 y4 P7 X - $tags = explode("_",$_POST["tags"]);
% e$ g2 ~' u7 Q: B - $cate = $_POST["cate"];
k8 K) S6 q2 m0 }7 A4 V* { - //print_r $tags;
2 R# E n2 h* Z& z' l, L! Z$ ` d/ b - // V0 N. N/ R8 [0 K
- //% r2 o7 ~! J' h, A7 @
- $wp = new WP();
$ D4 Y/ g: R; | - $wp->main();1 D3 I5 \4 |% M Y8 x, q
- //
$ r- b0 e) L0 u7 i - $my_post = array();
/ O6 }- b! a) C0 s/ ~ - $my_post['post_title'] = $title;7 N2 }% p# v# o2 `( w" z
- $my_post['post_content'] = $content;' x9 A% K4 b& F" h9 w2 I
- $my_post['post_status'] = 'publish'; u- r; k" b, i5 a
- $my_post['post_author'] = 1;' `- |/ s. J' f1 m. o- t
- $my_post['post_category'] = array($cate);, l" m$ t: Y# O& A
- $my_post['tags_input'] = $tags;
, C+ J+ i, ]* ]9 y - //$my_post['tags_input'] = array('tag1', 'tag2');
0 M V" [8 x. c1 w5 ~& J) r6 Z# R# D - //$my_post['post_status'] = 'future';1 m: ]" j. C, e" ]
- ////$my_post['post_date'] = '2010-07-04 16:20:03';+ K% a# S0 l, x8 B* f& V* z S& O! m
& l1 m( O9 o9 S: l& k" D- // Insert the post into the database
0 u+ i" H8 K: g% S - $ret = wp_insert_post( $my_post );- e5 @- n3 x8 }3 n. a% f5 I0 l6 T
- echo $ret;
6 ]$ c/ d" N6 w* ^6 n' P - ?>
! ^5 i7 F+ z1 P) J
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 1 C8 x U0 R! l! ?, Y$ u
- <?php( @ B! ]1 [. m3 C3 w
- define( 'ABSPATH', dirname(__FILE__) . '/' );. a% u o+ W' l6 z# b3 m
- require_once( ABSPATH . 'wp-config.php' );
3 `/ K9 w+ Y# b3 L* c9 h - require_once( ABSPATH . 'wp-settings.php' );% ?) ^3 b) A) T! m( |% A9 i
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ L/ D' y9 x. C) e7 p
- require_once( ABSPATH . 'wp-includes/functions.php' );0 m: J7 a4 a) n2 y
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ c; M8 ^1 L8 w/ j
- $pic_name = $_POST["pic_name"];; A. E) a& `! A0 A2 R8 E
- $pic = $_POST["pic"];
7 }( K- A' I/ M5 o4 P - if($pic != "" && $pic_name != "") d' s7 B; }& M! O# h& F1 Y) B
- {
6 c. Z, x( E. G - $path = "images/";; ~& v9 p- o3 V
- $pic_name = $path.$pic_name;
, H6 i) g& u) W - echo $pic_name;8 Z: q" x- `# R% t" D1 q% v
- echo "||";
' s+ K, C0 _5 H1 ]% k+ g" X - error_reporting(0);& m' W# _7 s2 M8 V' ?7 i
- mkdir("images");
) L, v# q9 l" A$ m; A - $handle = fopen($pic_name, 'w');7 e0 Q* G1 G {' {2 M7 F. J7 p7 N
- echo fwrite($handle,file_get_contents($pic));
, q* v0 p- P3 `5 L2 x" O9 m( X - }
4 N# ^6 K8 C. a8 A; N, Z - # E3 L% |: K$ s- M8 D
- $title = $_POST["title"];) R/ T( Y2 S { T$ g5 L+ g- @
- $content = $_POST["content"];1 p( t& J/ W& ?+ c T( |
- $tags = explode("_",$_POST["tags"]);
- p6 d# Y1 `* j - $cate = $_POST["cate"];+ N) O9 Y* z9 S# ^$ D* g: ]3 n
- //print_r $tags;' ~7 b; A4 U5 |
- //# X0 _6 V6 p; v# `. N- U2 z6 X
- //2 A& R5 J/ ]' ~! d% H
- $wp = new WP();
8 B# W% r6 p1 ] - $wp->main();4 d- s7 o0 r5 }0 h( V
- //
! V: Q1 W l( J# {& O - $my_post = array();, ?, ~: }( K* [ F; L& w
- $my_post['post_title'] = $title;2 l' s( ?% ~. d
- $my_post['post_content'] = $content;
/ H$ V5 _! P8 C) d6 n/ _+ c3 z - $my_post['post_status'] = 'publish';
) H( [3 r5 G% g# {1 O - $my_post['post_author'] = 1;% G' a H0 d+ S$ R
- $my_post['post_category'] = array($cate);
5 Z7 Y4 r, I6 Y% s9 t# @ - $my_post['tags_input'] = $tags;! g( H4 I, C; H. w5 Y" M0 j0 D5 m
- //$my_post['tags_input'] = array('tag1', 'tag2');
V$ T/ o0 j% G N& T. g - //$my_post['post_status'] = 'future';' g4 d8 E7 N$ f$ L- p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ ~; L6 @. ?! `, v1 K
: [/ y4 l% ^, B$ y7 Q- // Insert the post into the database% V. E; r W; f& K
- $ret = wp_insert_post( $my_post );" y$ t1 R* q" |4 W$ {0 f- R4 \
- echo $ret;
+ ?5 b5 U0 Q% G. Y) z - ?>
1 c' b2 r0 B% P' [, k( o, O3 U
复制代码 我自己写的. C* ~. Y# y1 `" E0 a5 d
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|