|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; z; b* t% ]( x& b5 w- g( \- Y' v; N; ?4 b! q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 l2 H2 U4 [/ m& K% X, r8 G2 t* C2 F& ^4 G
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% r: ~# {7 q# `% l9 x& F4 T1 [* ?
T, x- H+ ^/ t- W5 D: D0 H: m
方便实用 简单 何乐而不用呢- * f7 n( I: L: w7 A5 q2 D
- <?php
8 D: W: Q- ?' F% H5 o9 e6 b9 t - ( P8 W& |2 l. O9 ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );! ]! M' W7 I( l3 u' {3 @
- require_once( ABSPATH . 'wp-config.php' );- l# x+ I" P* g) |2 w
- require_once( ABSPATH . 'wp-settings.php' ); V$ C6 X/ a. J1 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ `9 S) O; m" q* {5 g: W# r - require_once( ABSPATH . 'wp-includes/functions.php' );$ V" Z$ C3 W3 m3 d
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# l9 {0 \9 p* @ - $title = $_POST["title"];) ]3 M+ y* ~# F) D+ a7 C
- $content = $_POST["content"];
+ h7 P5 G% C) Z3 l - $tags = explode("_",$_POST["tags"]);" R5 ^6 K0 O' G7 |5 U1 c
- $cate = $_POST["cate"];: ^( U+ d D* @1 r# G5 f
- //print_r $tags;1 e& h0 M) r Z& V. H7 J8 j
- //
2 {# J' b S7 n - //+ R- F) \) u! p* F
- $wp = new WP();. K0 n1 c/ \+ T: p; w2 G! q7 t! r
- $wp->main();
* W$ }! `! U) V& r; u$ q* z) V - //. p: Y' v) K. I- {
- $my_post = array();8 T/ ]2 k5 g, Z/ Y& `+ h
- $my_post['post_title'] = $title;
; h2 m9 N' \0 e8 k - $my_post['post_content'] = $content;" O2 \, Y' l0 M% ?* G
- $my_post['post_status'] = 'publish';
; X7 J' Y& C% g) ? - $my_post['post_author'] = 1;
' ^# Y9 T% I/ x7 [, { - $my_post['post_category'] = array($cate);) ]0 q. _6 M( F( X) w
- $my_post['tags_input'] = $tags;
+ L* T* O* T, U' m9 V2 \7 o - //$my_post['tags_input'] = array('tag1', 'tag2');8 S7 q: k* b9 l2 e3 S8 q& s
- //$my_post['post_status'] = 'future';
/ A3 ^" y Z/ U% h x2 u0 \ - ////$my_post['post_date'] = '2010-07-04 16:20:03';, Q: a8 W2 [) E5 L" L% W
- 9 F6 ?$ |: K; |
- // Insert the post into the database! x3 C, w) t# G- r+ O
- $ret = wp_insert_post( $my_post );
# J& a! r/ D4 ~! L+ Y - echo $ret;) v3 U" V: [& S
- ?>
( ?$ q c+ a" R A4 ~% a, j, a( a7 ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 R: p. h# Y0 }1 E2 U# |, s- <?php
% p( }7 W& h! N- y3 Y& y8 x - define( 'ABSPATH', dirname(__FILE__) . '/' );
! B: l* G0 c+ r: {% ?. @+ K - require_once( ABSPATH . 'wp-config.php' );
# E' L9 j* h/ k% R- M - require_once( ABSPATH . 'wp-settings.php' );' f/ O1 X9 u1 k% B( Z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );2 n- r) g1 Y; K0 L
- require_once( ABSPATH . 'wp-includes/functions.php' ); T! N/ y4 X a! S
- require_once( ABSPATH . 'wp-includes/plugin.php' );
1 Q/ n& }, L1 X - $pic_name = $_POST["pic_name"];
: ~ W- y" j' Q( c$ K - $pic = $_POST["pic"];
# @; g# p" K4 Q* l/ u. n5 u - if($pic != "" && $pic_name != "")4 Q: a, a4 h2 `2 Z% k
- {
" ]# V' J+ @- n' \( Y& e8 N - $path = "images/";4 u9 X: b7 V. g2 m- K( W$ \
- $pic_name = $path.$pic_name;2 U. ?8 H; U$ v3 i) n5 h
- echo $pic_name;
/ u \; N0 _2 [- l9 p# N& u - echo "||";
' d$ {. k2 V x - error_reporting(0);( K9 `& x' G& ^) B' V u3 y+ t+ n
- mkdir("images");. t% H( K& k, s& Q8 K
- $handle = fopen($pic_name, 'w');
' r; H2 a5 J k J8 a7 o - echo fwrite($handle,file_get_contents($pic));/ q4 n! E6 B1 n+ ]8 d" i8 R1 p
- }
! J q/ W' A6 z) K0 O& ^+ r
7 O0 V7 C, U; n( |7 ^4 l; |6 k( }! o- $title = $_POST["title"];. A# B* h. [+ Y( O9 ~3 E. a
- $content = $_POST["content"];
5 R# U" z# Z+ ^ - $tags = explode("_",$_POST["tags"]);
# N( f( v' v# F; u3 f% |# k - $cate = $_POST["cate"];) Q, Y# `. \# T# I s6 @
- //print_r $tags;; a: K, W' f* G. b& \+ B4 H, P
- //1 I) P' x" V. p/ e7 l
- //3 X4 `6 N- L: _6 d2 b
- $wp = new WP();/ }8 G' f( X# L7 e, x R( j3 `. [
- $wp->main();/ x6 Y' m0 _8 @
- //! }% y ]2 F8 A( o/ t- J2 z9 T* K
- $my_post = array();
) J, `5 p9 @) `6 [ - $my_post['post_title'] = $title;/ f2 j& P2 r- ~2 N% H; T& N r
- $my_post['post_content'] = $content; O6 q" n2 u6 m) _% E/ A
- $my_post['post_status'] = 'publish';
8 n+ C' F# |% u4 K) t( b4 i( B - $my_post['post_author'] = 1;6 y- B' T0 R! I3 \7 l- f4 }$ e6 {6 e
- $my_post['post_category'] = array($cate);# h8 d* X+ A! Z% V
- $my_post['tags_input'] = $tags;
% e1 E Q+ ?/ ^0 `* }# X) U. C - //$my_post['tags_input'] = array('tag1', 'tag2'); X. F& A c R. d5 G: _
- //$my_post['post_status'] = 'future';
, x, ?: m2 d8 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';* R: B/ G& N$ Q4 c7 _- j- d+ ~
1 _; C* P! N& N$ U- H* z- // Insert the post into the database
$ \, J [$ G; Q8 p8 U& y4 L P - $ret = wp_insert_post( $my_post );
5 b; V/ d) e, ? - echo $ret;
; E6 Z3 y2 x; j1 f - ?>. l( p: f$ A' }, ~
复制代码 我自己写的4 E2 q8 X l+ b1 i) B- P( j
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|