|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 x$ @; S& z) u5 a% @9 V- b; B* e6 G( @' o- J7 [
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
4 B- B$ v7 ~/ [+ K+ u5 c/ i5 S* B' `0 x1 g( r" D
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
& c; I& A: \6 j9 j0 s) }' W
2 g6 e M4 R e- W: \2 a方便实用 简单 何乐而不用呢- 7 t# U& D Q6 b1 K( g0 m+ }
- <?php
! q/ s ^# v5 F y$ ]( |
* ^0 J4 k% K6 {- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ E( z( h/ `" p9 a3 j8 r0 x - require_once( ABSPATH . 'wp-config.php' );
% L- `! `8 Z# R( a9 Z/ M - require_once( ABSPATH . 'wp-settings.php' );
0 C. R1 I; c1 R, _ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; M5 E) ^# C* S/ B - require_once( ABSPATH . 'wp-includes/functions.php' );
) c- [& f- q4 B' V - require_once( ABSPATH . 'wp-includes/plugin.php' ); t( N2 a4 V. i Q s: l, x
- $title = $_POST["title"];
: g" O+ J$ x5 K& C7 d) O V6 V: I - $content = $_POST["content"];3 w J2 e! ?' w3 L& j2 |
- $tags = explode("_",$_POST["tags"]);
6 ^/ v/ Q/ y; H+ _, [9 D9 p - $cate = $_POST["cate"];1 M s _; h# B+ ?, y% y( K* s( y
- //print_r $tags;
3 y! ^1 t/ `" q( m# s - //1 U5 s1 r7 P& G d4 F* Z3 w
- //' C' C* G8 C* v" {8 r! O( n2 j
- $wp = new WP();
4 L# t0 j; {; q5 g3 W+ f - $wp->main();
0 f" h3 q2 e. `* O# Z& k) R# f - //
3 B1 A- j! \% A8 P M- \ - $my_post = array();" |. I2 M% c) r U' r. d; n' Z1 M3 g
- $my_post['post_title'] = $title;
6 G. W# k8 r! n* t# l0 L4 b# t - $my_post['post_content'] = $content;
0 W! ~+ n9 q8 k0 M, ? - $my_post['post_status'] = 'publish';; z# g! R+ x9 D8 c# E8 R2 L
- $my_post['post_author'] = 1;
0 D1 E) O: v: N: _% y2 w - $my_post['post_category'] = array($cate);
# h* v1 [, M) A+ A - $my_post['tags_input'] = $tags;
3 E% ^8 i: z9 T' X/ h- D& [# ^7 b - //$my_post['tags_input'] = array('tag1', 'tag2');
' g" f' _7 Z' r; e! ?# J - //$my_post['post_status'] = 'future';
4 F( W, e* Y3 [# d! b1 r - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 m/ \9 I! i: B7 L
- # U2 d& x3 [( t8 m6 O/ y
- // Insert the post into the database
4 X7 K: ]9 u I - $ret = wp_insert_post( $my_post );
, x6 B$ d7 ~' f - echo $ret;
1 v* @+ I. ^* W4 U" P - ?>: G8 }9 j# f7 t3 Q7 i; b- \" y7 {
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- # s4 s3 I- W! e4 P8 W) {3 x
- <?php) z5 _) ^; c# j& n+ O! \7 ^
- define( 'ABSPATH', dirname(__FILE__) . '/' );' a! u" s% O$ |7 {, Q5 h
- require_once( ABSPATH . 'wp-config.php' );
% f$ {! B8 t5 \1 F$ d - require_once( ABSPATH . 'wp-settings.php' );5 |5 O% t) i" p3 @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
: G. Y; L$ ?, ]* r2 w, _+ E+ C - require_once( ABSPATH . 'wp-includes/functions.php' );5 c, h' s X) M/ a5 s, [8 R% x
- require_once( ABSPATH . 'wp-includes/plugin.php' );2 T4 s5 _/ X6 a* \
- $pic_name = $_POST["pic_name"];
) h: D; Y6 Z3 V- [' O' e5 J' C: Y - $pic = $_POST["pic"];
+ ^" k+ P ?. U; b6 P - if($pic != "" && $pic_name != "")
5 H% H6 X' K: ]$ g$ s* ] [ - {
8 m# t2 g1 h+ ? - $path = "images/";: Y8 ^1 Q1 e x, ?
- $pic_name = $path.$pic_name;
t4 H7 ~$ m5 u- k$ k - echo $pic_name;& q3 x+ f( U5 r
- echo "||";
% q0 X. o, \& W( e1 v7 B7 E. ` - error_reporting(0);# N* c7 F3 x2 Z" p
- mkdir("images");
7 B! I( J$ u# r' N3 H - $handle = fopen($pic_name, 'w');3 O9 ]+ D! r6 z
- echo fwrite($handle,file_get_contents($pic));! E# Z8 P/ M4 S, d( q" y
- }! W+ s# v- X3 M+ F5 [0 D) I
" h( @" [) L$ X/ ]8 C3 k* a- $title = $_POST["title"];' Q5 f7 y$ ^; D
- $content = $_POST["content"];
+ p. {' u- }" ~ - $tags = explode("_",$_POST["tags"]);
% ]5 X5 q' b- {# e, `" J - $cate = $_POST["cate"];; s! b* g% c0 g
- //print_r $tags;$ a' h, E1 Y# Y4 `2 X; x- X
- //9 c: Q2 q# O9 g$ V; w* d7 O
- //% B7 W3 |+ `2 @% P5 U4 {9 H6 d
- $wp = new WP();
4 ~7 @9 X, V# H5 o) a( I - $wp->main();% \/ h, U2 _8 O, q$ X
- //
: _+ D9 Z7 N: i! Q' W; R" a - $my_post = array();
4 w' I9 I% q- u$ I* D: { - $my_post['post_title'] = $title;. \6 J, b, d/ @& }- y
- $my_post['post_content'] = $content;; S4 S. s( f! M; a+ m' L
- $my_post['post_status'] = 'publish';
. @* [/ @7 P3 g/ a - $my_post['post_author'] = 1;" R/ D8 d6 U9 S' {
- $my_post['post_category'] = array($cate);' D! W8 @# v% l2 M+ B
- $my_post['tags_input'] = $tags;
. A! n: e; G+ X' ~7 E4 `2 A+ J - //$my_post['tags_input'] = array('tag1', 'tag2');
+ |9 M5 ?! D* d7 l* m% @% i1 W6 b: S2 l - //$my_post['post_status'] = 'future';0 |3 P! R* X! { c& u2 }
- ////$my_post['post_date'] = '2010-07-04 16:20:03';: f' C# \; v8 J1 {" ^2 Q
- 3 C8 r* v- d: }
- // Insert the post into the database, I& d- M6 x' H2 E: F
- $ret = wp_insert_post( $my_post );
7 {/ n5 W5 Q3 O+ o% R - echo $ret;
9 Q4 T( d7 l0 l. _ - ?>8 _: @1 f. H" c. Q7 ~- t
复制代码 我自己写的
! c$ q2 f+ F+ U插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|