|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ' u, n8 d( |6 X% V
9 e8 ~. b& k2 E3 v
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
# `6 T) X+ [) T5 |0 V
% l6 q1 ?9 @* }- M* Z6 S* d我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 Z6 ]# k4 ?3 h3 Y E- z9 g9 ^7 E$ i( D3 \
方便实用 简单 何乐而不用呢- % l, I: P# P* f) y9 `
- <?php% L0 y5 E; Q |+ @
- % W p+ p. m5 e/ T2 Z- P, z
- define( 'ABSPATH', dirname(__FILE__) . '/' );+ }- p6 ^6 y8 s$ x: G, f
- require_once( ABSPATH . 'wp-config.php' );
- _1 H" P& z. _6 H. K! z: t: g: ] - require_once( ABSPATH . 'wp-settings.php' );4 e Z- l$ A5 C0 P! {
- require_once( ABSPATH . 'wp-includes/class-wp.php' );! h( f( p9 M; ?) C+ s1 |9 u
- require_once( ABSPATH . 'wp-includes/functions.php' );
: Y/ c5 p( e( `% w1 l% d1 c0 f - require_once( ABSPATH . 'wp-includes/plugin.php' );) {+ b4 R0 D. R9 |
- $title = $_POST["title"];
" U/ V8 g5 e' i, q8 { - $content = $_POST["content"];
5 P+ H& i0 q" t# A& u - $tags = explode("_",$_POST["tags"]);
5 T5 J7 G, R: _ ^8 s - $cate = $_POST["cate"];0 K4 C, |% U* o' j
- //print_r $tags;
2 }1 c9 d# V6 `* k! _" _ - //
$ ?2 V6 S+ Z3 ?6 w - //
0 m/ x$ a2 o1 k8 q" s - $wp = new WP();) M& z5 E% N) B4 H# d& v
- $wp->main();% b' d1 H3 J: t5 u d5 e1 e }
- //! a' R" Y2 e" ]0 |' H# [" J
- $my_post = array();
! `2 A1 c. P0 l6 t3 b$ f& l$ i - $my_post['post_title'] = $title;5 {# u+ w8 a- p1 o/ r
- $my_post['post_content'] = $content;
4 R$ ^5 T5 S! S4 F9 U - $my_post['post_status'] = 'publish';4 g' W5 T s0 R, k9 X
- $my_post['post_author'] = 1;9 q1 ~- ~0 s+ V( S( L, _# K
- $my_post['post_category'] = array($cate);
5 J% `* k2 ?3 g& |8 X/ L - $my_post['tags_input'] = $tags;
4 t# p) y1 |* X. f4 U: p6 q - //$my_post['tags_input'] = array('tag1', 'tag2');
* M; ^" v- d. Z - //$my_post['post_status'] = 'future';- Z* V* h$ E j% J
- ////$my_post['post_date'] = '2010-07-04 16:20:03';+ D: t9 S2 p2 Y; D3 u. |' x/ v
- 3 |% x& G8 z) p) O* `2 t
- // Insert the post into the database/ ]4 M1 r; c; U+ t7 V: I- r
- $ret = wp_insert_post( $my_post );
% y6 ?+ ?$ |" ]: ]; D3 F - echo $ret;
{# w/ \& f7 y9 |# `, \7 N; H - ?>
% B: y9 W$ o$ i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- " d. }; c7 R8 Y* Q/ X
- <?php
, _" L5 n: t: `7 Z/ B: ^. [ - define( 'ABSPATH', dirname(__FILE__) . '/' );
- P- }( a. b1 `- z* s - require_once( ABSPATH . 'wp-config.php' );9 i% w* _" ?1 ~
- require_once( ABSPATH . 'wp-settings.php' );
+ a2 E& S! W7 K m - require_once( ABSPATH . 'wp-includes/class-wp.php' );( `; v) z# K7 k) j- ^
- require_once( ABSPATH . 'wp-includes/functions.php' );
5 g2 o, _- W1 T ]% w/ d - require_once( ABSPATH . 'wp-includes/plugin.php' );: F4 k& R% o Y2 ]' L
- $pic_name = $_POST["pic_name"];* d+ i9 v r3 H. t6 ^9 C
- $pic = $_POST["pic"];% R9 S; p% A/ ^) ^3 H
- if($pic != "" && $pic_name != "")! a/ V! r3 l0 k6 l1 e
- {
, Y2 y/ r; ^5 x! ~6 Y - $path = "images/";. J s; T- y' o" ], R4 g4 S
- $pic_name = $path.$pic_name;2 |" {8 ~& [& e! b8 Z) ]- e
- echo $pic_name;) W' f, F; J6 d) m
- echo "||";
3 | u. b0 w" Q" d - error_reporting(0);5 q0 s6 y+ l! {5 M0 I# l
- mkdir("images");
! y7 |8 W2 l, g/ ~3 S$ V - $handle = fopen($pic_name, 'w');
! p& F" }, j, q - echo fwrite($handle,file_get_contents($pic));% O. D& P* |8 }, H
- }
t+ E; s' I& e0 L+ S
, C) E7 q) E" E" M. p- $title = $_POST["title"];
6 d) F) Z# m" | - $content = $_POST["content"];
- j0 n5 q; M( Y' T8 |% e - $tags = explode("_",$_POST["tags"]);" D ]' d/ Z! x- U- N. X
- $cate = $_POST["cate"];
' I6 \1 j- v* h7 W - //print_r $tags;
4 }4 t9 T" r* F, a# u w1 c: e - //& e$ b& W8 h7 _
- //4 F9 e/ O. u/ T
- $wp = new WP();
5 d' a* ^2 t V0 X M( Q' q) B - $wp->main();
; y6 t& W& `4 c6 @! L - //7 F1 {) a: b2 l" b
- $my_post = array();
% @! ]3 m7 g6 l, W - $my_post['post_title'] = $title;
& {. Q% ^! x6 k" M# T" V! W3 v - $my_post['post_content'] = $content;; o' n; j6 w: U/ i
- $my_post['post_status'] = 'publish';
: Y7 J. I7 f( r3 D9 ]$ Q# D' T$ Z8 I - $my_post['post_author'] = 1;* w6 z9 G5 f# K8 S% e
- $my_post['post_category'] = array($cate);6 x$ G7 Z6 S+ I( l2 f
- $my_post['tags_input'] = $tags;
. q/ R' I' B! \* k - //$my_post['tags_input'] = array('tag1', 'tag2');
, H' I; c( _; J6 X+ ?) ^ - //$my_post['post_status'] = 'future';8 ? x1 d: ?; ?& r Y. `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 T7 w1 X v: ^) G
% w1 q) j( h' G* c: t& U' M: H- // Insert the post into the database: D$ }' t8 K2 L( R5 n/ l3 a
- $ret = wp_insert_post( $my_post );
0 z+ `, o: `9 N$ A" j7 a% b - echo $ret;& y8 O# P" {/ i' M% }' ~# e; v
- ?>
* T! v c- U+ A$ K9 W! t# b
复制代码 我自己写的
) p+ N C& j& h3 x3 ~5 ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|