|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 - {" t; ?1 m# t% Q, ?
; D2 S6 B7 }1 C% E) \直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
' C2 w* |, j8 X ^6 J; U/ y% l. z! y9 ^
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
5 E& I: H& F6 g: F# g
* l& w8 d7 P3 H2 i" G+ M) z4 L方便实用 简单 何乐而不用呢- # _: Y; u0 `) W
- <?php3 J! ~0 c) h E! T5 b
- * n2 b4 [# O! |% x8 t& C/ F: u
- define( 'ABSPATH', dirname(__FILE__) . '/' );/ k0 A* E8 ]8 C) D1 ]
- require_once( ABSPATH . 'wp-config.php' );
3 h" @( A5 C$ `/ {* m& o+ ~8 }; \* w4 i - require_once( ABSPATH . 'wp-settings.php' );2 Z. y" d3 S) e; t9 Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );! Q2 J* X) B0 }* _
- require_once( ABSPATH . 'wp-includes/functions.php' );
. L$ @" q3 k- r) { Z - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ l7 O' b& j, m+ h6 w- J. Z - $title = $_POST["title"];
. x3 e5 S+ m+ E t) ?0 o - $content = $_POST["content"];
0 _1 s }5 j) e8 _5 h - $tags = explode("_",$_POST["tags"]);
4 A- ~6 G# m+ }/ ]/ |3 Q - $cate = $_POST["cate"];
# h P- R a7 I$ t - //print_r $tags;0 ?, q2 `/ N+ R v, b5 S; k
- //! v7 ^4 A% V* f f
- //: C3 K m" Y+ A
- $wp = new WP();$ l/ w2 W5 M7 {/ `4 m
- $wp->main();0 |" P9 K( `0 M% a, z0 l( [
- /// [+ d5 ~( x* m
- $my_post = array();
6 O9 l* i* ?' k o - $my_post['post_title'] = $title;6 a, M v4 S: z/ Z
- $my_post['post_content'] = $content;# H) u1 `6 I, E
- $my_post['post_status'] = 'publish';$ N9 l- i& w2 k. v+ _
- $my_post['post_author'] = 1;7 B, t1 l j/ {8 W. E
- $my_post['post_category'] = array($cate);$ p, W% N O& s+ Q3 S
- $my_post['tags_input'] = $tags;8 V5 f0 S# L* h" Q7 |1 q5 f, n
- //$my_post['tags_input'] = array('tag1', 'tag2');% J9 x5 l; O% h0 J: D& J2 a) I
- //$my_post['post_status'] = 'future';
s0 c- G j: [$ B! H - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ V# l n9 D0 o$ X - ! L4 n6 z9 d9 e2 g
- // Insert the post into the database9 Z& n+ x7 s& z. ?$ R( `- M
- $ret = wp_insert_post( $my_post );! j5 e. e; X/ u
- echo $ret;7 t" G* j* k2 h! X( b) A9 c# Q& S0 w
- ?>) w. U \3 i. E @4 Z. y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
* j! s3 [5 G& F( ^ |7 j( H* ?& l- <?php
5 w& F5 d3 M- j! Y1 O - define( 'ABSPATH', dirname(__FILE__) . '/' );: S2 m/ z E- k6 k* F' o
- require_once( ABSPATH . 'wp-config.php' );
3 N0 I+ D, K0 c1 F1 C - require_once( ABSPATH . 'wp-settings.php' );/ x. @/ r6 k) {. `0 Q% T% I
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 k" x' a) B( T1 a2 [ - require_once( ABSPATH . 'wp-includes/functions.php' );
7 d( H* W) E1 g3 F; v - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 C! x& u( _' Z" C - $pic_name = $_POST["pic_name"];& _- y% L/ L! p4 }& `+ y# r
- $pic = $_POST["pic"];! g3 p. w$ Y8 j( d
- if($pic != "" && $pic_name != "")% m8 Z" x& c1 m$ r) R( |
- {% H* n T { k$ p4 Z. m
- $path = "images/";
* T/ W% I$ _6 {% h2 Y, t: F; y - $pic_name = $path.$pic_name;
8 h0 ^" i t+ r2 z) e5 N - echo $pic_name;' b: P0 I% n3 H: o% O% S/ B7 h
- echo "||";
5 l9 r4 J& A0 `& [: V( X% ` - error_reporting(0);) P" [, I0 Y* D% e# `" x
- mkdir("images");
. l) Q- d7 H/ L' e; `0 m' ` - $handle = fopen($pic_name, 'w');. P9 _6 n& M5 g/ ^; a5 D
- echo fwrite($handle,file_get_contents($pic));
, a: y1 }9 v# _* s/ E# @% f3 E& {) y - }
, y1 Q, W( Y/ O/ [0 O# B
$ t8 P w4 h2 Y3 m4 v- $title = $_POST["title"];( n. D# {+ k9 X* X
- $content = $_POST["content"];
) O. B% ^; s* a7 ~/ f6 w3 ? - $tags = explode("_",$_POST["tags"]);
1 v6 c% j5 w5 H9 \% E- p; E - $cate = $_POST["cate"];4 {. B b4 N2 M" F. {$ _
- //print_r $tags;% W* r. ~0 q9 `! _( H* J$ t
- //- a4 j. h; ~) T
- //2 `8 S( R, C' g0 a# X u
- $wp = new WP();; R6 w X3 q" s( t5 A. O
- $wp->main();3 Y2 N) L( h# r, ]4 p$ I, j
- //
3 s' d9 }/ [ A6 r/ I9 [ - $my_post = array();! W! D, N0 z; @$ N( X4 p3 {: z
- $my_post['post_title'] = $title;
+ X! @ m" r6 Q; D - $my_post['post_content'] = $content;
1 x0 g7 ~+ W2 E- D; G1 f - $my_post['post_status'] = 'publish';' T0 w' i+ z2 k' j! S+ G- v
- $my_post['post_author'] = 1;: M" e" a! O$ J& @
- $my_post['post_category'] = array($cate);7 E! b9 t$ l/ }4 s* M
- $my_post['tags_input'] = $tags;" o: J9 w u" ^( t+ h% k' Z5 Y
- //$my_post['tags_input'] = array('tag1', 'tag2');; c9 q1 a/ D! D4 c \/ [2 ]( i2 ^
- //$my_post['post_status'] = 'future';
3 S- L# {% W) B1 W# X3 Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ C. j( y) G# M( h0 y
# m* Y9 K9 [' \+ y& B1 \- // Insert the post into the database
3 ]$ i7 C1 o9 f" @8 `; Z% H' ` - $ret = wp_insert_post( $my_post );$ f" @4 `. O' ~: n) U& T( z
- echo $ret;5 e- }% D0 _" r6 j
- ?>3 O! q" \$ {9 w/ v7 F# S, Z
复制代码 我自己写的
/ `. x& M) i# ]8 k0 k8 @插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|