|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ' R" Y) Q& O7 {3 H
/ {: H- M9 l- s4 X$ ?3 T& E
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
* t+ R2 `. E( r7 |- |) U1 C
, J5 M, P) q! R0 T我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ w" c1 n0 N' j3 J( U1 U5 _/ _+ O& G+ D( V" _1 R1 j E
方便实用 简单 何乐而不用呢- , B& D2 e: }8 I* P) V
- <?php
/ M8 U4 ]4 p% m - 8 ~* J' `4 O# W' r
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 O( R) Y( y0 D' `0 q
- require_once( ABSPATH . 'wp-config.php' );
4 R# x" m) Z: h b, s! l - require_once( ABSPATH . 'wp-settings.php' );1 p' H) E8 r2 l4 ?+ f) _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 W) J, V7 s% V+ n T, l0 }: H# r - require_once( ABSPATH . 'wp-includes/functions.php' );% P1 Y* s) R+ K( m$ X; W: U
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! l+ ^7 P: X% s2 V0 G - $title = $_POST["title"];. O* Z. q% R; k6 v1 V' m
- $content = $_POST["content"];
0 E& k9 X+ U E5 S8 n c - $tags = explode("_",$_POST["tags"]);
+ J+ ?6 C$ I/ h \8 J7 X$ n! `1 R - $cate = $_POST["cate"];
. E+ ~8 o2 ^4 ~ - //print_r $tags;7 P& [7 J' b# v- c% r
- //
8 ? r7 m/ F' B5 { - //
& V, \ b% [) M% f - $wp = new WP();) ~7 u( E; D, g) s9 h
- $wp->main();) p1 |- Z4 ~5 l; Z! B/ V4 |6 }
- //
7 T1 w: q, j8 G8 a' E; `& E - $my_post = array();
" k+ j7 I" U: Z9 J& p - $my_post['post_title'] = $title;
. y) m6 x" Q j# n6 [, v) q - $my_post['post_content'] = $content;0 h1 i* e; \# q
- $my_post['post_status'] = 'publish';
( F1 Y: r, I2 I, s6 Q. O% s$ _' n - $my_post['post_author'] = 1;
3 A/ T+ u, r: I& r - $my_post['post_category'] = array($cate);0 t: O& o$ o( z( e; M* d
- $my_post['tags_input'] = $tags;6 X- c* j/ \% P C" s
- //$my_post['tags_input'] = array('tag1', 'tag2');9 x$ Q2 |& I9 b) ?
- //$my_post['post_status'] = 'future';
9 ]2 O7 U s' K! a. [: y" a - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 `9 p, f* S, y+ z! C7 y& Z! F2 @ - " {3 \3 P( T# `2 \' u0 z, K$ H
- // Insert the post into the database! k( c5 M- L, V- K' F0 J3 k4 I; d
- $ret = wp_insert_post( $my_post );0 T6 n) \% B# A5 Q; z X* P
- echo $ret;! M% X/ S! ^6 C. o: j: J. |; z# j: Q
- ?>8 q, q: |7 ^1 ~! F& v6 I
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
* L: \" J9 h% u& P( M( a- <?php G: Z, P. K5 p! e6 e
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: H) Y; K, }1 m$ }0 E - require_once( ABSPATH . 'wp-config.php' );# O- h- b8 k1 ]0 R/ E8 T6 G T$ M
- require_once( ABSPATH . 'wp-settings.php' );
& M# F& u* ~& p. b+ Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );! u" s% V7 Z9 n k5 Q
- require_once( ABSPATH . 'wp-includes/functions.php' );
+ Q8 }# h- W3 ?8 t- K- z9 F, n! u. _ - require_once( ABSPATH . 'wp-includes/plugin.php' );
4 K5 n( k) U x" ~8 } - $pic_name = $_POST["pic_name"];2 l& f: f8 Q$ |9 h: o; S4 L8 V
- $pic = $_POST["pic"];4 A5 C% F7 E+ f
- if($pic != "" && $pic_name != "")
' \' ~, o8 S6 F5 m - {
1 ~1 {7 _# U6 d6 X q - $path = "images/";
% c! {1 N: p7 a9 t9 K: t - $pic_name = $path.$pic_name;1 }0 n8 T! l" [ M! _. E
- echo $pic_name;
5 F' P4 S8 x) u8 j: u - echo "||";
: h& I+ u! d; T- |" b - error_reporting(0);
$ _6 t0 h' X1 @' {( c - mkdir("images");
8 _0 f- K3 ?0 N2 F! f1 i6 l) e - $handle = fopen($pic_name, 'w'); E4 O( G- z4 W3 k+ b' N: p5 l- \
- echo fwrite($handle,file_get_contents($pic));
% \4 M" h/ f( g; ~+ M" @4 p8 W - }# V1 l$ w- k# c7 a, J! _
- 8 A, ]; k; i; g( J4 ?
- $title = $_POST["title"];
1 Y' J5 D6 \& M - $content = $_POST["content"];: C* a" z* p+ k1 S" h& W$ v+ o" d
- $tags = explode("_",$_POST["tags"]);& M4 @! v) f* E
- $cate = $_POST["cate"];
$ e; e; L* n7 |. Z% C- v) j4 n v( m - //print_r $tags;. @7 Z& L; ~0 n5 ~; n
- //
/ F* s& O0 Z+ U+ @: e - //
0 y9 t" ^6 _& f4 D1 w) c - $wp = new WP();3 G" d% j* E- U3 t- G
- $wp->main();1 _! N# Y% X( S- [1 p; x4 y2 k1 U) [
- //8 `9 W- F. G) |: a
- $my_post = array();3 z8 H; ?0 h/ {* C# d, J/ L$ q
- $my_post['post_title'] = $title;2 l9 N, Z: c6 t
- $my_post['post_content'] = $content;1 n6 U4 b( B& a) Y8 ]' l! ^# m
- $my_post['post_status'] = 'publish';
1 z* p" `2 v) R - $my_post['post_author'] = 1;
8 ?7 `' z* C6 ~! d - $my_post['post_category'] = array($cate);0 C; B# ?$ B- T* h4 W+ f
- $my_post['tags_input'] = $tags; k8 n( {- w/ E* j- A% T: {% p
- //$my_post['tags_input'] = array('tag1', 'tag2');3 f3 N5 {+ S) H/ l
- //$my_post['post_status'] = 'future';/ |" ?% n! j, h C4 l7 {
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ U8 @$ y7 _0 V% |1 V
8 ]9 E. F0 t3 K- b* j% D- // Insert the post into the database
3 `1 v' m) e( x - $ret = wp_insert_post( $my_post );4 W4 ^" P" [* n2 D/ Z
- echo $ret;- ]: J S" n5 \) j6 @
- ?>8 V0 ]0 N9 M1 k" O7 N4 I
复制代码 我自己写的
0 n2 i% W" e; t& [插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|