|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ! w7 `, U: t6 {* h, a4 N
# T) ]) o& j: N7 z- \) c4 c: [) i
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. A' t4 [5 z' s, o/ [0 x
+ p; |* A4 y% j0 O我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了8 r# X% `8 C7 N8 ~
+ |- }. V: @, ~% l+ [8 H/ @/ y
方便实用 简单 何乐而不用呢- ( y+ B' ^4 u1 U M
- <?php/ C7 X9 w) J0 @
9 O0 q! Q6 H5 E) y- define( 'ABSPATH', dirname(__FILE__) . '/' );# ]: d3 _# A- r5 ~, C2 m+ e7 K
- require_once( ABSPATH . 'wp-config.php' );' ~1 I) U5 {' _; y) `
- require_once( ABSPATH . 'wp-settings.php' );8 X+ N. }2 [/ D* x+ W0 U; m, \0 M
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" N5 Z+ u- t" y
- require_once( ABSPATH . 'wp-includes/functions.php' );8 m, s( {; V1 ~5 [5 O, R. o" N2 V
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# N6 W. C: E- ?% Y1 k, x- v - $title = $_POST["title"];- i! W% ?+ i6 i7 X! B. t
- $content = $_POST["content"];. q$ l5 ~# f) ]3 g) o P
- $tags = explode("_",$_POST["tags"]);
5 [) Q+ m5 |' g - $cate = $_POST["cate"];
/ Z' A3 z9 H, Y0 b0 D - //print_r $tags;
% }4 u# A; X3 S5 o' | - //( S. w4 M! y# v9 O7 f
- //4 S- ^" v# i# B/ y$ h0 A
- $wp = new WP();
3 _8 ^7 P0 F: O% b* ` - $wp->main();
# Z: g$ B6 N; y( u9 N2 s' { y$ T - //3 X' y. b/ }) z3 g6 t6 b& W' g- y; W
- $my_post = array();( y0 ^: R# T! m
- $my_post['post_title'] = $title;. e" l4 s; X/ ]% O E3 G K5 N
- $my_post['post_content'] = $content;
2 y1 q3 K j( Y2 ~0 E4 F% r - $my_post['post_status'] = 'publish';
3 |7 |, e" E8 W# w7 [) o5 U) } - $my_post['post_author'] = 1;
( C/ G+ T/ }8 c1 {7 b) M - $my_post['post_category'] = array($cate);) A5 F( ?. u( y% x& I9 ~* }
- $my_post['tags_input'] = $tags;# L# S) W- }7 j& n
- //$my_post['tags_input'] = array('tag1', 'tag2');
) W: G C. v3 {0 f$ b - //$my_post['post_status'] = 'future';, t) z: W `& O; A, {$ T- O; s7 W
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
# E% v% j7 `! u7 X2 C8 V8 j
0 e' b P7 W9 `# e1 w' M- // Insert the post into the database
3 g7 Y' [6 r9 Z8 \+ L - $ret = wp_insert_post( $my_post );. T1 U3 [' Y( s# w ]) A
- echo $ret;* ?- ~+ q* M1 c5 v2 U* I
- ?>
/ A& ^2 v/ n+ k" o" @% f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 K8 P) {3 J( [0 b. Y8 k+ o, c- <?php
( Q: p4 p# U/ j) x* ^ - define( 'ABSPATH', dirname(__FILE__) . '/' );8 R# m* `8 t# u3 ?1 q
- require_once( ABSPATH . 'wp-config.php' );, m( G I) C- Q
- require_once( ABSPATH . 'wp-settings.php' );! I2 n* \) j; @' e1 j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ N# n8 c' }- G - require_once( ABSPATH . 'wp-includes/functions.php' );/ o* w7 N( R; }6 W: I) O, P% K
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ [; j5 u; F o" D - $pic_name = $_POST["pic_name"];0 b3 {) c- b& c: _% M
- $pic = $_POST["pic"];+ G: v. }! y2 S# _4 Q
- if($pic != "" && $pic_name != "")4 |) n5 W3 q! f: e. ]
- {
0 ~% F. ]+ v, z - $path = "images/";) w# Z/ Z. `8 _6 C* g, o
- $pic_name = $path.$pic_name;& x7 p, P7 Z0 Y4 U$ j
- echo $pic_name;
1 ~! M) t' t8 X/ J - echo "||";! W' }8 o- _8 F6 h; K! i- z
- error_reporting(0);7 z) _' U( q, y# ?: |' ?4 R
- mkdir("images");
1 R; U6 F7 }/ h" b1 E - $handle = fopen($pic_name, 'w');5 J4 Y, [0 f0 d3 I$ i4 w% p
- echo fwrite($handle,file_get_contents($pic));
2 Z. @! H+ }* ] - }
/ n3 }$ [; |$ r& c0 @* {1 Z - 7 n: U* N& S5 S; [) ]0 g+ C
- $title = $_POST["title"];
% X x6 E2 E# T - $content = $_POST["content"];2 Y* Z( ?; N; {( o3 i |3 S
- $tags = explode("_",$_POST["tags"]);$ L/ O3 ~( B: C7 o& Q! Z5 O
- $cate = $_POST["cate"];
7 E& B, R1 ~/ t$ L: ^+ w/ Z - //print_r $tags;9 o! h$ \1 n* g& L% U
- //
\0 d9 F4 Y G4 Q7 m- o - //- r* b: e; ^8 s: Z8 \/ q- J1 H
- $wp = new WP();
' z7 m) A5 m c. L5 h7 b - $wp->main();$ c. k3 T( R" O* j, ^; [
- //
( N3 d/ D1 q8 m5 ~0 G6 O- x( g( t M - $my_post = array();
" R: i7 v g I, n - $my_post['post_title'] = $title;
. S! \. |. I: R0 c3 E0 a) z' Y* `0 o - $my_post['post_content'] = $content;
% f) j3 T2 x7 ~ |' z' G - $my_post['post_status'] = 'publish'; \: y# {- _/ l- R9 Q* f6 C6 Z
- $my_post['post_author'] = 1;
8 y4 Q9 ^" ^! f$ |2 D2 b* ?7 Q - $my_post['post_category'] = array($cate);* Y0 ^+ J$ R! B7 [! |, g
- $my_post['tags_input'] = $tags;
- a$ M0 M7 Y9 W9 s' r7 X - //$my_post['tags_input'] = array('tag1', 'tag2');& G8 N% ]) `7 C4 \+ [& y
- //$my_post['post_status'] = 'future';8 ]: k( u% ~ q& B8 a* Q; f
- ////$my_post['post_date'] = '2010-07-04 16:20:03';8 f {" @2 M/ w9 o! p
- 5 D9 z: c- j) s0 W" u1 Y- C
- // Insert the post into the database
; S- ^# O+ _; n5 a% Q% B# Y - $ret = wp_insert_post( $my_post );
K }. u' x! G, z( Z9 z4 E - echo $ret;
9 n% B# \0 J" r& x. W; l0 O+ } - ?>9 a( J9 S, v. B1 V8 h
复制代码 我自己写的
% A' g! w, ^6 L2 a4 ^插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|