|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 o8 V$ u n( h/ a1 M! n
+ {3 @% f7 }* p! \; a3 R3 D& g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
6 P% W" N. b6 m) E& P
- X8 o# z0 `' T" z, l1 }我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: g( b: ]4 A4 \6 n+ C5 Y- E: S3 ~ Q+ t, y* q- e6 G+ w* z
方便实用 简单 何乐而不用呢
F6 I) Y. R/ r/ s: m" Q. J- <?php
# l6 ~/ W, p b$ I: E
+ a& \) K) B$ E- define( 'ABSPATH', dirname(__FILE__) . '/' );
* E f# q% r6 c1 e# B - require_once( ABSPATH . 'wp-config.php' );: }. H; L: ^' E# I: e o: q* {, X
- require_once( ABSPATH . 'wp-settings.php' );
) J/ A4 U) O# p - require_once( ABSPATH . 'wp-includes/class-wp.php' );/ y* `4 i0 n- A
- require_once( ABSPATH . 'wp-includes/functions.php' );
: i f$ b6 x9 ~3 j0 A& H - require_once( ABSPATH . 'wp-includes/plugin.php' );
+ t# E* |; \/ F - $title = $_POST["title"];6 U# s& B& A. d7 J, W9 R" T
- $content = $_POST["content"];
6 E$ T( D7 b; I' V# i) U% r3 {" a$ R - $tags = explode("_",$_POST["tags"]);" j+ m* R u1 |+ X- o
- $cate = $_POST["cate"];) o6 y4 P2 t8 [$ c! m
- //print_r $tags;
) w+ c/ X& j b5 H q - //7 ?% E2 ^" G0 X& h
- //% L8 g! l" \/ r* \) Z: n5 R) ~
- $wp = new WP();+ o4 g: [$ b3 P+ j: h1 ^
- $wp->main();. A# {" I6 i% A& g9 x
- //
; A8 z+ N9 z+ x& d* H3 W: n - $my_post = array();
2 a: Z; ]9 T# n1 [: ^) U# G - $my_post['post_title'] = $title;
: _. g# s% j5 x% k - $my_post['post_content'] = $content;4 A0 L1 S, O3 D/ {
- $my_post['post_status'] = 'publish'; H+ \; o: @ A% |4 q9 R7 M
- $my_post['post_author'] = 1;. y# `4 h6 o+ o1 W8 o2 r6 S, x
- $my_post['post_category'] = array($cate);
* }6 p+ w8 T7 [/ k# Q; _ - $my_post['tags_input'] = $tags;
5 k4 ]: t. ?' ~4 c" x# L - //$my_post['tags_input'] = array('tag1', 'tag2');0 e5 x- w& q/ e& b! m0 a* T
- //$my_post['post_status'] = 'future';
3 ~2 X: E8 N2 U' v+ x" {: O% i( C - ////$my_post['post_date'] = '2010-07-04 16:20:03';
" O, T) l/ o8 |6 H
. |, D( i* P/ I% P+ V- // Insert the post into the database( C% R, A# A9 \4 J7 H- c6 o$ s7 [
- $ret = wp_insert_post( $my_post );4 N* I) U' S3 N, a4 k
- echo $ret;2 y8 {- f& o) S; Z% P. O
- ?>
s u" _9 I+ ^" Q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , C6 N V6 D* z: d7 b9 u ?
- <?php9 S+ p9 t, ]4 a T, ~+ C( j
- define( 'ABSPATH', dirname(__FILE__) . '/' );" @" U. H% V" [6 A) {! {
- require_once( ABSPATH . 'wp-config.php' );
9 [3 U0 }) |/ n1 Y0 h* J - require_once( ABSPATH . 'wp-settings.php' );/ k7 Q: ]8 ], N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- x$ F" d6 r; B6 }/ ^ [% @
- require_once( ABSPATH . 'wp-includes/functions.php' );+ f" ]+ i, C- I& Q4 T: v* D
- require_once( ABSPATH . 'wp-includes/plugin.php' );- B) l; f3 o& L
- $pic_name = $_POST["pic_name"];4 X, c0 @ v' W4 F5 n1 v
- $pic = $_POST["pic"];0 B0 P! S; C2 c$ T
- if($pic != "" && $pic_name != "")
5 G, C, `* E2 ?+ ?" }( I7 Y - {4 a4 p3 g% `/ j. W6 A
- $path = "images/";) K) e) o* z9 d" c
- $pic_name = $path.$pic_name;
$ C. T# a# ?7 ^( U - echo $pic_name;% B5 [3 `& ?7 I2 S
- echo "||";4 E E4 L. K6 U/ X
- error_reporting(0);
7 g6 q& r2 B" O" y, m - mkdir("images");& f" H0 Z* u1 Q# x3 |5 q
- $handle = fopen($pic_name, 'w');) S' s# S' ^3 D' R& M# Y/ `! f
- echo fwrite($handle,file_get_contents($pic));. S9 \ I: K5 f# ?3 o0 r& [
- }
8 g3 L( K1 L, Y% j - ( d! i5 ~7 n' W& M7 L }
- $title = $_POST["title"];) P7 a- r' w* P6 \% L& R. [
- $content = $_POST["content"];' O5 `* H) t r& g* H( o6 z
- $tags = explode("_",$_POST["tags"]);* F7 U: X5 M: x' }
- $cate = $_POST["cate"];
1 s0 a7 M/ |$ A8 i& d - //print_r $tags;- ]( } ?3 n0 j! `
- //
1 W( H" I \0 Y# _( f# d. a$ B - //
j4 K2 ^: G% o9 ]6 l& Z - $wp = new WP();& @ e- p$ u$ ?" y: A2 T. n
- $wp->main();
) ~# o P) f3 ?8 O! a$ S - //
( M/ J" X. V L: ], V& j3 } - $my_post = array();9 b H& t# k Q1 h
- $my_post['post_title'] = $title;
+ v0 S5 I' @. x& e6 p - $my_post['post_content'] = $content;
& F2 V5 B) a' I - $my_post['post_status'] = 'publish';6 U9 X$ a8 p8 A N
- $my_post['post_author'] = 1;
% b8 E7 l: O% K; z - $my_post['post_category'] = array($cate);; {6 V/ `9 k$ O2 W6 P: ]5 G
- $my_post['tags_input'] = $tags;3 x" @+ \ u" u. M
- //$my_post['tags_input'] = array('tag1', 'tag2');
1 B3 F3 P/ G/ I( P2 e - //$my_post['post_status'] = 'future';) y1 E- d7 F M. C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ ]7 @: w2 A( z1 q2 W
}% Y( n Z/ M+ ]- B+ K$ _- // Insert the post into the database/ ^ n( d- C% n# H( ?9 Q2 l& N
- $ret = wp_insert_post( $my_post );$ ~# F8 j2 W3 w0 ^, G
- echo $ret;
/ t3 j* i7 O' ` @; X6 w: E - ?>
' S/ K; w* S: `- d6 `& O$ B
复制代码 我自己写的
% ]# B5 ^6 \: h( F, @插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|