|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 7 L3 W) R9 R- {; |+ M1 W$ V1 O+ B
5 R$ l7 f& |% g8 T6 X) U8 b( q q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持% O7 a( w0 T& `) c1 B, ~- M
0 K* c. [ G6 R' l8 M我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 U5 n3 X2 E" o" p. H6 X' U( x+ }9 ?& T+ V
方便实用 简单 何乐而不用呢
; s7 B( L% u' y [( l- <?php
. i- H/ L* j; b- A' c) i - ) r4 d- {4 `7 o! Z% T) W/ X
- define( 'ABSPATH', dirname(__FILE__) . '/' );2 K$ e2 |5 t* P5 V! i/ f( J" b/ u
- require_once( ABSPATH . 'wp-config.php' );
5 i! r7 v7 F( P/ s s' N/ W - require_once( ABSPATH . 'wp-settings.php' );
2 T8 A7 t$ d/ S+ A, | - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ S$ U! j# b E: E - require_once( ABSPATH . 'wp-includes/functions.php' );
/ B ?# c6 y/ I( ~5 H; V - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ u8 T6 i h& J5 ` ]! r - $title = $_POST["title"];
6 p! f& s& V$ y- U - $content = $_POST["content"];
. t, Z5 a. Z& P% S$ ~ - $tags = explode("_",$_POST["tags"]);) W' ^% R, x( ^' {
- $cate = $_POST["cate"];- ]5 \3 z& d! f1 O! ~) p# |
- //print_r $tags;6 D- D" O# I% P2 a' {$ d
- //+ U |* y, _) r m3 B1 B+ `- f
- //8 X: Q6 N- U: }9 I, u
- $wp = new WP();* t! y7 F/ _" ]6 P9 E* ^) m
- $wp->main();
% T& X5 z: T+ }; q$ e5 V1 i" T: c' F& W - //; b E1 x, a& @1 P( P
- $my_post = array();* N; O9 N' z% h
- $my_post['post_title'] = $title; h* h% n3 g/ ]$ C
- $my_post['post_content'] = $content;! v4 [( z: [, n4 K
- $my_post['post_status'] = 'publish';
! E4 w4 c2 H5 `# q( P5 K - $my_post['post_author'] = 1;$ u9 l4 v4 O& ^+ N( e
- $my_post['post_category'] = array($cate);" `, k" d. Z/ C
- $my_post['tags_input'] = $tags;
/ w* V7 Z4 H8 Z) Y& k - //$my_post['tags_input'] = array('tag1', 'tag2');
( t$ P' u+ c* S - //$my_post['post_status'] = 'future';, L/ q" I# V( |. t% ^: ?
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; `, `1 U6 H! _# h8 \
- + p9 Z# y; T: u y# N
- // Insert the post into the database( ` w% X+ Z/ O" M+ w+ a
- $ret = wp_insert_post( $my_post ); ~4 M, b$ s* j0 F8 P& R4 L6 ?
- echo $ret;
8 }& A5 F5 i# v# ]3 g- C2 ^ - ?>( P, x; P) G$ U& P. i& i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
H# u; f" w- a+ q- O+ ] j7 K. X" k- <?php( e* k9 x& P4 F9 v' V; B
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 {. z6 t4 n0 P; ^ - require_once( ABSPATH . 'wp-config.php' );- O$ a4 f( Q/ J% p
- require_once( ABSPATH . 'wp-settings.php' );
7 ]+ _6 W+ T9 h) O$ }$ {' T - require_once( ABSPATH . 'wp-includes/class-wp.php' );
i. p% e5 r3 V( V" d+ t) o - require_once( ABSPATH . 'wp-includes/functions.php' );8 e+ W) N* W/ I3 w
- require_once( ABSPATH . 'wp-includes/plugin.php' );
* e4 H' M0 h" k- j% e0 M6 ^ U - $pic_name = $_POST["pic_name"];* }% @+ p {1 N
- $pic = $_POST["pic"];
' X7 p' R3 u' `' g - if($pic != "" && $pic_name != "")8 z; k, p6 R9 ?
- {: E$ `) e) N( ^1 G, H( [& A6 ]
- $path = "images/";
( z- y b& t9 r - $pic_name = $path.$pic_name;
. z4 r- ]2 q9 g5 C* s% J4 m, y' S+ J* |; w- h - echo $pic_name;& S0 I- O8 `2 @
- echo "||";5 b+ t) y$ p; ]9 R
- error_reporting(0);+ e3 o# M, |& w$ g, x( }# f5 `' R
- mkdir("images");
3 P* m: f& k5 } - $handle = fopen($pic_name, 'w');$ `3 p- [/ v) A4 z% A
- echo fwrite($handle,file_get_contents($pic));/ V7 X* z& S+ j
- }2 E; p- b5 X( P/ c
0 R; p. J9 ]9 O: n+ Q- n- $title = $_POST["title"];* y4 @/ M7 m7 R
- $content = $_POST["content"];
2 C f: I- o5 C$ T4 p7 Y/ K - $tags = explode("_",$_POST["tags"]);5 d( q, g9 @8 u. s
- $cate = $_POST["cate"];* D7 V' h# Z9 W- H1 J3 [4 g( S5 J
- //print_r $tags;
& @/ l) [5 d: P) J& I- `% w' s8 V - //
; i' p; p% O$ u- i - //0 r! u8 C$ c# z" T3 A; W6 y
- $wp = new WP();9 Z) E7 B8 x) H. m7 i
- $wp->main();
# Z, T# A# w3 K, I - //6 ?% c# u: ~( h% v
- $my_post = array();
, \4 M+ p4 f5 j' G8 K7 m% X - $my_post['post_title'] = $title;
+ V; I+ z, I7 ?/ [+ t U" f - $my_post['post_content'] = $content;
+ M% i! d' X* e9 ]# E5 I - $my_post['post_status'] = 'publish';) I9 M1 @- L/ W1 i* g2 [$ Q0 m
- $my_post['post_author'] = 1;7 b7 T# b$ q1 v( t0 m7 ]9 Y& x
- $my_post['post_category'] = array($cate);
^0 S: p4 q4 b% |) c, y - $my_post['tags_input'] = $tags;
9 o/ U9 ? n3 O: a+ w: h4 a9 } - //$my_post['tags_input'] = array('tag1', 'tag2');- b8 B6 h7 G' ?
- //$my_post['post_status'] = 'future';1 N; E# L( b% i; [
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# E2 X# ^) K/ v. ]( u' S( d$ X2 @
- ( @6 O' B& o7 R* d" |; _9 o0 z
- // Insert the post into the database. K* X8 K! E- A. p5 \0 f- @4 N" Z
- $ret = wp_insert_post( $my_post );
S5 N5 U. ?/ d# ~$ k1 Z( l - echo $ret;3 h- j9 K9 b- ?( o' m! \* @
- ?>
9 z# G( ]. n! V
复制代码 我自己写的
# o: u2 e7 c, v* N2 _& i插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|