|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, B* N3 D; o1 ]" }# y) s) v% _2 \: ]% S2 M4 z9 K' m, Q4 c
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 _- C! V& U/ A' B/ f |: v' B9 R- f$ J
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) H) E4 B5 d8 W% J
6 v3 J. ^; K% J. o% F2 ?
方便实用 简单 何乐而不用呢
" S% ?! Z" p' X- <?php+ ~$ G9 W% b8 {. y* d: _5 S% P
8 ^/ w- \$ \% R8 o. j4 d- define( 'ABSPATH', dirname(__FILE__) . '/' );, D% e- A/ b" Y+ r2 H: I! _
- require_once( ABSPATH . 'wp-config.php' );
3 B) Z n9 z* T - require_once( ABSPATH . 'wp-settings.php' );
8 p9 K! \5 N% k0 V - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 x& C& G3 m8 I O5 q - require_once( ABSPATH . 'wp-includes/functions.php' );6 q4 w8 ]* J7 H1 c0 _# I9 R
- require_once( ABSPATH . 'wp-includes/plugin.php' );" J' L5 O( \8 @0 {- \; O& a; d
- $title = $_POST["title"];& I3 s( p, D: q6 A/ a
- $content = $_POST["content"];
7 f# j0 J4 `: j; S - $tags = explode("_",$_POST["tags"]);
: ]) Q6 Z8 y6 w7 @/ Q- @ - $cate = $_POST["cate"];
' n' j$ I# p# ~1 y+ f7 Q - //print_r $tags;
, ~6 g l6 e# h8 z) R# S - //
) m3 B( C' ~$ r( Y - //9 J# O0 x# X4 C4 o z; d4 c9 r5 s
- $wp = new WP();
! [9 H) B$ |$ l- F$ [" k - $wp->main();* d; C$ ~- q% t8 X, u+ `
- //. J# B2 C" g* C3 c
- $my_post = array();
4 W& d0 i. d5 o - $my_post['post_title'] = $title;
. Q& `9 o) N- k8 r - $my_post['post_content'] = $content;+ K+ h2 _/ X9 s
- $my_post['post_status'] = 'publish';
- I" g- [8 z8 Z - $my_post['post_author'] = 1;; |3 H, D" ], a
- $my_post['post_category'] = array($cate);$ K. p, S% Q4 r" s! q
- $my_post['tags_input'] = $tags;0 _" |" w! R; M" o6 H/ y
- //$my_post['tags_input'] = array('tag1', 'tag2');1 R. Y/ f2 Q1 C9 r* @' ?( ^
- //$my_post['post_status'] = 'future';
* ?( p/ @# T( S# j7 K* D& t - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 a8 ]/ m( N6 _
- p0 _. M6 I8 N a- // Insert the post into the database3 c* p# E |- k O$ q* n2 l
- $ret = wp_insert_post( $my_post );
6 M8 t) z' @9 \% c. I# ]* L - echo $ret;
6 g* _, x: ~( B) Y7 C% p+ C: C& N7 ?, C - ?>! w( |, j+ D5 _! `
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" t: t6 \3 A) m- <?php9 c6 Y# z4 F# b( K# L) |# x
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 e! B4 l8 p; a
- require_once( ABSPATH . 'wp-config.php' );
8 s2 c& q5 h* G# r8 Q- B- z - require_once( ABSPATH . 'wp-settings.php' );
. H. f% i: Y6 {; M5 z6 d1 n - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 d( t0 I& q1 v) F! B6 K
- require_once( ABSPATH . 'wp-includes/functions.php' );8 x8 e5 E. v+ t( }) i* w* m
- require_once( ABSPATH . 'wp-includes/plugin.php' );
; s1 \/ Z) o6 e/ k7 N - $pic_name = $_POST["pic_name"];
8 c- U# d& t9 E. Y4 h" k: K1 d1 B6 W - $pic = $_POST["pic"];
3 \ M7 Y" D: y; ` - if($pic != "" && $pic_name != "")9 v5 z0 K9 Y7 T3 v6 u2 [6 H9 d
- {
, W8 ~- t4 B5 l - $path = "images/";* s5 o i% O: ]" O! ]* H
- $pic_name = $path.$pic_name;
8 S3 a8 g) h- @1 O+ Q9 C0 l* @9 V! h - echo $pic_name;; ?6 o1 [2 _0 g
- echo "||";
2 M% O" x' s$ v* t- X" z - error_reporting(0);* J( b* h4 v5 Y) M7 j a8 J
- mkdir("images");
% W' t1 P3 P* [/ t- Y' c, m - $handle = fopen($pic_name, 'w');) o3 |& N$ K2 R2 d9 y: p8 D) v! u/ O
- echo fwrite($handle,file_get_contents($pic));( i) `4 `# g* _; E1 M
- }% d* I8 O3 k2 h* K4 r# Y( _* l* I$ v
- 7 X' f6 \: i- f: z: F
- $title = $_POST["title"];: L. i" B7 T- o3 P7 ~3 V0 ~ t% S
- $content = $_POST["content"];, C9 ]; q! F. W* U8 p
- $tags = explode("_",$_POST["tags"]);
: `5 d! V- f+ h1 r& g. k - $cate = $_POST["cate"];) O- p* S4 r4 a& s& J
- //print_r $tags;1 x" h3 Q/ a0 W! G: O
- //3 J' I" S0 K* a- Y
- //6 M5 K+ G; K0 M9 z: m- T
- $wp = new WP(); W+ C) l q$ o8 L5 G" v
- $wp->main();& l$ a$ x5 T6 n' C- p
- //; Y: q6 G$ g7 {+ D, e( Z# Q6 y
- $my_post = array();, h9 d0 X' X5 ~# K& ~
- $my_post['post_title'] = $title;
- ]4 q0 [4 B# ?% [; c9 ?$ V, k9 i - $my_post['post_content'] = $content;
) K/ Z- A0 {+ ]6 H$ B( Z! v - $my_post['post_status'] = 'publish';8 A3 u4 B4 o$ j9 t8 `
- $my_post['post_author'] = 1;; q% E( x0 j: |; i
- $my_post['post_category'] = array($cate);
" z" t) {: j9 { - $my_post['tags_input'] = $tags;- q( k- t& _- P6 f p1 Q5 R: N
- //$my_post['tags_input'] = array('tag1', 'tag2');+ z" d! l3 J$ c9 o0 z. E1 n+ Y
- //$my_post['post_status'] = 'future';* E) F" I$ U2 D7 e2 A, G( P
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' }% v2 ?2 }# _! o9 l/ d# P
* R1 A- x9 L2 f/ {5 X6 q5 W# l- // Insert the post into the database
; B! |; D( N$ ^- B8 u - $ret = wp_insert_post( $my_post );
1 O: o( A5 [( w8 | - echo $ret;
1 s: s2 V* x* B3 ^; P - ?>- U; Y, t* x! W7 U8 a ~
复制代码 我自己写的! T3 q4 m {# `8 }* d4 L2 Q8 l5 C! Y
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|