|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 O& _4 M% a$ ^
L% Q* l- W3 f. P: S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 F( f5 X c7 A2 }
, c( l: H$ w) T( J7 X+ X ^! q我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( b# x0 z5 x+ j% _" I
2 w3 \/ J4 b0 U方便实用 简单 何乐而不用呢- 2 `9 }( h$ z7 j
- <?php
: A8 O5 Y9 H0 q
8 A+ P; g$ _2 Q2 M- define( 'ABSPATH', dirname(__FILE__) . '/' );9 C7 I! l8 [5 P2 D4 e. S/ @! ~) ^
- require_once( ABSPATH . 'wp-config.php' );
6 E2 f' C9 p! v& n! D( H- i - require_once( ABSPATH . 'wp-settings.php' );! v2 D4 p" A; Z" w/ y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" U( h0 e0 K: B* @
- require_once( ABSPATH . 'wp-includes/functions.php' );
. N; S% z$ q7 a& e% }6 u( U0 N - require_once( ABSPATH . 'wp-includes/plugin.php' );
: z" D$ P( H n* L3 `7 s% } x8 y3 s - $title = $_POST["title"];0 {/ n4 Y: O& X. k2 y& h
- $content = $_POST["content"];
9 r: `' x) k2 n+ F! u - $tags = explode("_",$_POST["tags"]);
* ~3 F. y, @/ }2 H - $cate = $_POST["cate"];- y8 [/ D8 q+ ^3 |8 Y3 ~1 V1 E. h
- //print_r $tags;
- T, |, t* x5 J& Q3 @: z: u - //' z: ]) F" v. q. ~
- //
: z2 J: N! P/ \+ D" \6 g+ H2 M - $wp = new WP();$ [7 G* ?) L& T# d, M6 g
- $wp->main();
# B. b: V6 v* g" |9 r - //) W1 O2 k7 p$ @+ D+ Q9 p4 _4 F
- $my_post = array();" H' g+ q9 E; @$ t8 G7 x# g
- $my_post['post_title'] = $title;
9 Z- N- z' A' \ - $my_post['post_content'] = $content;
7 z0 B. e( }# m' q: _ - $my_post['post_status'] = 'publish';
; D; A/ O* h, [* n - $my_post['post_author'] = 1;0 x I! ?' J- H+ @4 F
- $my_post['post_category'] = array($cate);* I$ I. V7 K/ G$ |' }6 D. l: e
- $my_post['tags_input'] = $tags;
8 P4 r3 b3 c2 y t/ \4 ]+ x" J - //$my_post['tags_input'] = array('tag1', 'tag2');: W' g. F) l* Z9 K4 F& \/ K) R
- //$my_post['post_status'] = 'future';+ ^/ G9 {2 q, I% y; g& f. Z: f
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
) r% c2 W" v, `
/ Q5 X$ Z$ ?: Y( u0 b- // Insert the post into the database7 q+ \0 k+ m/ [. {2 Z+ Z' r, }
- $ret = wp_insert_post( $my_post );
$ o. i. W1 }% n& U" [: N - echo $ret;
+ G" S& L2 U$ [) F0 u7 J - ?>( e3 D5 F& i3 D- O
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
+ _5 X+ I2 a& G- `0 J1 V2 G, k% N- <?php
# m l+ c/ k- L8 l* n' _ - define( 'ABSPATH', dirname(__FILE__) . '/' );" j* d& r+ P4 q g# `
- require_once( ABSPATH . 'wp-config.php' );
: L) ~/ X% W7 g - require_once( ABSPATH . 'wp-settings.php' );, E6 d: H) r3 l* x
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
, u! X! f; W" {- i5 Z - require_once( ABSPATH . 'wp-includes/functions.php' );5 g5 z- Q0 i. w% w
- require_once( ABSPATH . 'wp-includes/plugin.php' );
. J: h8 Y, Z$ p% m% A+ }3 s, a - $pic_name = $_POST["pic_name"];6 U& u% B4 \5 W' u) ]+ X2 Z
- $pic = $_POST["pic"];& V, g4 p) Y1 t2 w9 C u9 d
- if($pic != "" && $pic_name != "")
+ ]" W) }) O2 s' J* k% i - {/ G5 C V: V: c) y( c, S9 F0 J
- $path = "images/";3 {, ^$ f& D6 ?: y
- $pic_name = $path.$pic_name;
8 v Z5 r+ V8 s- f7 F' @1 a0 V - echo $pic_name;1 t2 v/ G5 c* B$ @5 c! n
- echo "||";
& c+ k; [6 ]: @, d9 t/ m - error_reporting(0);
+ j* N2 B, E K7 M3 s - mkdir("images");
3 t& r. s/ g( l+ N - $handle = fopen($pic_name, 'w');/ [* `. p1 d. h$ W/ R! A
- echo fwrite($handle,file_get_contents($pic));
6 A+ Z* S6 \: \( b j5 k8 Z" ?% r - }$ j, I8 @6 s# F4 r
% X* c$ d) e# i- $title = $_POST["title"];
) Q* p9 {# J7 `5 [ H - $content = $_POST["content"];
% f5 R1 h4 a. V u) P m - $tags = explode("_",$_POST["tags"]);! H. m& c7 y3 k/ x0 W1 |0 {
- $cate = $_POST["cate"];5 ]- e( D* } I* s: l( s8 v. G
- //print_r $tags;( D- f# f0 y5 G+ X
- //
# \) h H' u" d6 n' w - //
' p; C* ?" g% ^( W0 t! s [ - $wp = new WP();5 Y9 K4 J2 P9 d
- $wp->main();
& k6 J3 h, c" U2 ~9 f7 ^! R - //
, z/ B# b. a% j. ~8 \5 q. _ - $my_post = array();
* y" @" i5 \7 w i8 Z! @! E6 m1 ~ - $my_post['post_title'] = $title;( E) p" j# {9 z# g
- $my_post['post_content'] = $content;$ y1 M% N5 y5 ^ S
- $my_post['post_status'] = 'publish';* R/ g6 [6 \. C* i9 i
- $my_post['post_author'] = 1;2 T4 K' ]* j% V4 v2 V$ e ~( H) L
- $my_post['post_category'] = array($cate);$ W- Y. Y: A' [$ s+ t
- $my_post['tags_input'] = $tags;
5 u5 T9 w* \1 h- e* @) | - //$my_post['tags_input'] = array('tag1', 'tag2');
: V& O' `6 i1 v! d - //$my_post['post_status'] = 'future';0 p+ q9 q& {! T% j" l% K* N/ n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ H' R5 z* ]( N' z* J - , y+ q( `: ?6 u& K2 r- z
- // Insert the post into the database b/ k* b m; _6 O' u/ ]) v
- $ret = wp_insert_post( $my_post );1 U8 j: g* E; @; f. f
- echo $ret;! ?! F: v7 @3 H9 t
- ?>9 t" r& E. ^. l+ {/ b( I6 D
复制代码 我自己写的! S2 ?! e8 b3 G( h1 v
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|