|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ; W' C5 W8 t5 g' D( h+ z1 D
5 ~1 l- n9 e& S" }. d" e
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
$ h6 N* U. V( y; W' {' z9 [: M" @8 x& l2 x) ^5 M
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了0 v: w1 G) w5 {6 m( Y
9 a3 c4 }* J0 `$ U2 g
方便实用 简单 何乐而不用呢
1 [8 t4 N5 l4 Q- N" y- <?php
. n0 h" E: C0 c1 `( F/ U" S J
! o& V) T4 X7 ^8 b- define( 'ABSPATH', dirname(__FILE__) . '/' );" {0 i$ ~/ g0 N! U" A
- require_once( ABSPATH . 'wp-config.php' );
7 g! B4 @3 N5 U/ F$ v - require_once( ABSPATH . 'wp-settings.php' );; K9 H2 o4 k5 [& O! r
- require_once( ABSPATH . 'wp-includes/class-wp.php' );2 e1 e |9 Z& i* x- V! |
- require_once( ABSPATH . 'wp-includes/functions.php' );5 s& h5 u9 j, l0 I# B
- require_once( ABSPATH . 'wp-includes/plugin.php' );8 K8 H" T3 D" M5 _$ \3 D( @8 G6 t
- $title = $_POST["title"];
% C- D1 F& j3 S1 w7 R5 x/ Z - $content = $_POST["content"];: l5 e* X' g' C0 V
- $tags = explode("_",$_POST["tags"]);0 y5 L2 x; k9 B* _
- $cate = $_POST["cate"];% V. p# l; ~/ e# J% a
- //print_r $tags;
4 ?8 M2 A5 {5 D, `8 g7 K - //. ?. Z7 i5 u6 y5 y( _0 }2 r
- //( i! d0 o: U( _+ F3 W. e
- $wp = new WP();
6 N6 Q+ m/ y8 l# E/ `# X: o" P1 W - $wp->main();2 |# ?7 y6 A* }/ n, O5 I6 M/ k
- //$ G2 J) f5 V- Y. R$ \
- $my_post = array();! M7 j6 M' ?/ |+ J" K4 a
- $my_post['post_title'] = $title;; {, d; o1 c, z3 L: `
- $my_post['post_content'] = $content;
; d1 I g+ T- c0 m9 ?! v - $my_post['post_status'] = 'publish';
+ r, F5 F7 z" c, Q: u! B# h - $my_post['post_author'] = 1;0 Z3 t, Z% M! c) F1 R
- $my_post['post_category'] = array($cate);1 m; Z& o3 ~8 G. J0 K$ m
- $my_post['tags_input'] = $tags;% D R. H1 v3 K8 P" I% S! T
- //$my_post['tags_input'] = array('tag1', 'tag2');
5 E/ S2 N" Z" L$ K4 k9 Y - //$my_post['post_status'] = 'future';
* U. w7 t# d+ o/ E3 [: i. U - ////$my_post['post_date'] = '2010-07-04 16:20:03';. E0 n" i4 t4 |
, R Y* \7 E) D7 s- // Insert the post into the database% `: O9 x+ a2 m2 r! O4 s/ ~: s: P
- $ret = wp_insert_post( $my_post );$ Q4 C& I$ b; M$ b# F# t7 {
- echo $ret;" d6 N2 ~8 s7 j* E+ R
- ?>
% }3 f3 R! ?5 o# A* V, `
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
( x- |) r' ~6 D& P2 C- <?php
! ?8 M2 E9 \: @" m: N7 I - define( 'ABSPATH', dirname(__FILE__) . '/' );
! w' v) E8 t+ ]0 f4 Y - require_once( ABSPATH . 'wp-config.php' );' U# G+ a3 |4 `8 U! t0 z
- require_once( ABSPATH . 'wp-settings.php' );9 t# ]+ D) M1 O g0 w! T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 Y2 f8 Z5 ?1 z. r1 U' U5 q - require_once( ABSPATH . 'wp-includes/functions.php' );
7 o. `) @+ e2 s2 [( W7 x - require_once( ABSPATH . 'wp-includes/plugin.php' ); o# B' m* I0 r1 p. q; Z3 s2 u
- $pic_name = $_POST["pic_name"];; ?- _# i# C; r
- $pic = $_POST["pic"];8 I% Q) P7 V: T; T
- if($pic != "" && $pic_name != "")
5 J$ U1 g3 v7 G" ^% T/ |9 |5 N - {
; ?, L2 E3 F+ Q8 R3 J W - $path = "images/";1 v8 b$ R" h' z7 x
- $pic_name = $path.$pic_name;
* \% r! W3 [0 c2 X( q. u/ } - echo $pic_name;
: B+ D* z3 `6 U# I6 D! F - echo "||";. Y. t! `: n8 Q% [
- error_reporting(0);
6 r: @) ~1 e% ]9 w" h - mkdir("images");* H4 w6 Z% L9 C' z1 G
- $handle = fopen($pic_name, 'w');! _3 r7 ?6 _( W: U
- echo fwrite($handle,file_get_contents($pic));
0 \! o& O7 ]4 V% B6 L% Y! c - }' C1 I0 F' ^4 e$ t/ T4 U
- + i w9 V) f* m4 f3 q
- $title = $_POST["title"];
1 T( C" v5 M8 g1 w - $content = $_POST["content"];4 ~: X; S Y) p* d% ^, R' w( x
- $tags = explode("_",$_POST["tags"]);
$ G y# g5 f8 A1 B5 M6 r - $cate = $_POST["cate"];
4 e- G4 \3 G5 m' H9 L. P - //print_r $tags;0 b7 f) H) m% v, a& _
- //
7 [" w/ \* @9 f4 ~4 B - //
: k( j6 q* L0 M& Y4 c* m* w0 x - $wp = new WP();
( P2 i- Q# }% _* V+ S - $wp->main();: o5 x4 w/ \' z+ V2 H
- //
* y/ Q1 r# O2 ^, o/ _& h - $my_post = array();
' u5 U1 _* Q0 o - $my_post['post_title'] = $title;
5 l* D! ]9 o& ?& V* L3 ? - $my_post['post_content'] = $content;, k. s- l. ?8 g6 n. x+ c- N7 V
- $my_post['post_status'] = 'publish';% y; f1 N8 B S3 Y8 j0 m2 F
- $my_post['post_author'] = 1;: Y+ P! N4 K/ E) x9 k% a
- $my_post['post_category'] = array($cate);
) W* V3 q+ |1 P - $my_post['tags_input'] = $tags; Y2 c: L( f! o, V# q' ]: a
- //$my_post['tags_input'] = array('tag1', 'tag2');: t3 K* I: Z/ Z, U
- //$my_post['post_status'] = 'future';
/ j5 w1 k3 ~" G - ////$my_post['post_date'] = '2010-07-04 16:20:03';* y {6 X& U8 z3 r/ f0 j/ Q
- # c$ x( t/ z ?% {0 l/ \
- // Insert the post into the database- M5 A! o5 G/ ]0 x- U# |% J
- $ret = wp_insert_post( $my_post );2 m+ {. ^* D1 k
- echo $ret;
' X" E0 ]9 j i$ K- p. c, R% D - ?>
8 M7 ~ A1 n" [
复制代码 我自己写的
5 y) k2 }- h9 D/ h插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|