|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
/ H4 K! L+ i( p) C' b6 Z
, z ]* y4 g7 ^9 O直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 j8 g7 ^ x( T& E
' {9 K4 ], f; F. }$ [我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
) M! b* U y h, T" o; J% q. ~: ?( F2 \" ^ y2 F
方便实用 简单 何乐而不用呢
: b2 b: o' H( u4 `+ g% b- <?php I: S& ^0 S$ C
; t8 L9 U; w! t. _- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 D/ Z% W2 B& [ - require_once( ABSPATH . 'wp-config.php' );8 L+ a/ f) l3 a) n, h
- require_once( ABSPATH . 'wp-settings.php' );( C, }* H) r$ D" n" ?8 @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );9 g- P. a% a9 f5 n+ c! ]
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ Y8 \* o, ~2 h% Z! C - require_once( ABSPATH . 'wp-includes/plugin.php' );
. r& C$ T0 c8 t4 H3 V - $title = $_POST["title"];1 @8 h3 r7 v2 j1 p
- $content = $_POST["content"];7 t1 V$ e# c$ O2 W0 T
- $tags = explode("_",$_POST["tags"]);7 V+ W6 b+ N* g4 s& t) y; a, F5 n
- $cate = $_POST["cate"];
. B% {/ n) f: C% v* f+ n4 ]- ~5 B - //print_r $tags;
4 }$ K: B; q, m8 X2 S7 T9 t - //
& G# f& F$ O. E( q( |8 V, V - //
/ u8 O- u8 M( k; S - $wp = new WP();2 ? v) M: h% p" S- J
- $wp->main();# L3 c, U4 y" B7 S
- //
* R$ Z* H" b- @+ A% P0 ]) j: q& v - $my_post = array();
T6 o) Y' C; ?- C( Y9 M" P- z' N - $my_post['post_title'] = $title;
+ ~0 F2 z5 g+ A0 \ - $my_post['post_content'] = $content;: g3 @+ A( C) O% K) V
- $my_post['post_status'] = 'publish';
; J3 b1 H+ Q% @, E - $my_post['post_author'] = 1;
" l1 P9 f7 x v# _* O$ R5 m - $my_post['post_category'] = array($cate);# }- w3 }: y& m i
- $my_post['tags_input'] = $tags;5 R# [7 l! z/ S9 f" O
- //$my_post['tags_input'] = array('tag1', 'tag2');% @. J; @* {1 B, p
- //$my_post['post_status'] = 'future';6 n& X, f9 l; E/ g2 U
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 S3 G( ?4 a1 f$ C
* R! j1 z& U, K' E- // Insert the post into the database4 M- k2 M3 Q# n. A/ z0 U# ?% h# o- s+ O; B
- $ret = wp_insert_post( $my_post );
6 ?) X0 F) T7 d3 d4 m }3 e, y - echo $ret;
3 l& G* d7 A Q- Y3 @! ` - ?>
4 K* V; Q7 g% K
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
( F# {- G. p3 V A- <?php
7 e! D4 p3 Q3 R - define( 'ABSPATH', dirname(__FILE__) . '/' );% T8 ~( Z, c {* i1 Z
- require_once( ABSPATH . 'wp-config.php' );
" o+ n2 Q( l! d% J1 ^5 d1 z2 a( i, A - require_once( ABSPATH . 'wp-settings.php' );: {6 s) f. F" H2 m
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ g- ~, P4 B/ W! y9 H$ b; i - require_once( ABSPATH . 'wp-includes/functions.php' );
# F/ F7 i- @/ {4 c4 }. [ - require_once( ABSPATH . 'wp-includes/plugin.php' );! \3 u) z7 v0 p+ N( p6 E: M, I
- $pic_name = $_POST["pic_name"];+ d' g. Z. W1 Q6 S# o
- $pic = $_POST["pic"];0 Y& d% D0 P8 n6 |+ w- U
- if($pic != "" && $pic_name != "")$ {$ c2 P, F. O, N B
- {3 U2 x4 A1 x3 j) H' |
- $path = "images/";
: M4 [ l7 K5 c5 x - $pic_name = $path.$pic_name;, H9 H( v# J4 I( w
- echo $pic_name;0 t& N" {8 W) S# E4 J
- echo "||";7 n; {$ N& c, R3 e
- error_reporting(0);
! f0 Q/ L6 q' I( Y - mkdir("images");
+ M+ W" C# N( V+ G Z9 } - $handle = fopen($pic_name, 'w');
& O6 g) o" S$ p. _ - echo fwrite($handle,file_get_contents($pic));/ D4 R0 s& y: o3 O
- }
; d; o6 X) g. i) f6 w
* a& B6 H6 x( f1 E6 _, ]& r1 r/ [2 P- $title = $_POST["title"];
+ Q+ r1 f6 A5 C% a - $content = $_POST["content"];
; g8 e4 j4 I+ A5 [, v2 { - $tags = explode("_",$_POST["tags"]);
) h2 o/ t8 y: N - $cate = $_POST["cate"];
; Z6 |( G3 w! a3 n5 H - //print_r $tags;
; f$ [# V4 R, y8 p8 R- I# w6 _ - //% \6 ?, ~ P3 M2 n" B
- //: m+ b5 p: q+ G" a; ^
- $wp = new WP();' A. H1 d: o8 @1 o, b
- $wp->main();
. r# I# R# t7 [2 j# G2 y! b/ c' o - //* h& k, B N$ E
- $my_post = array();
- U: I9 J6 `4 m- { - $my_post['post_title'] = $title;1 X8 e5 A1 n& p' N
- $my_post['post_content'] = $content;
" m# v6 X- c" t+ p, h - $my_post['post_status'] = 'publish';
# \. L9 e: U* B: z - $my_post['post_author'] = 1;
/ t0 z% B9 L" U4 g9 | - $my_post['post_category'] = array($cate);% I/ {8 P! y4 U q: d
- $my_post['tags_input'] = $tags;
+ G/ d9 v$ B1 [1 V5 x' E - //$my_post['tags_input'] = array('tag1', 'tag2');
& n% T( n1 ~8 D% z7 m - //$my_post['post_status'] = 'future';
, T, c& P- Q" n9 [6 C* J2 s+ ~9 ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 ^# \" U* ]) W
( l# [$ n! k" T. ?. c- // Insert the post into the database
3 x" X+ m6 F i7 F - $ret = wp_insert_post( $my_post );/ H$ P) `6 N k+ Q5 \6 R
- echo $ret;6 q2 X4 O* Y% f
- ?>$ K0 p5 A" n/ y
复制代码 我自己写的
: R; O/ j$ z; a插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|