|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
& ` f: R/ D S4 _8 ?8 N. D, f) G! d1 o3 n: X% f
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 M* J' T8 \* {6 J$ H0 z2 C! G0 H. J; U0 ?
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了; ?; _. V# q: i5 U5 n
* h3 _4 @+ ~. Y" b
方便实用 简单 何乐而不用呢
0 o8 {8 e" q) `" L& u4 K" c- <?php, N3 B) T3 `2 Q
- 5 x+ f% x, d) t# M
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ R. t- g- i# P# c
- require_once( ABSPATH . 'wp-config.php' );
, g7 Z0 O4 l/ { - require_once( ABSPATH . 'wp-settings.php' );
- w0 g% i3 @& h X - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: m' Q" D8 S/ g2 u" B1 l8 c T, f - require_once( ABSPATH . 'wp-includes/functions.php' );2 U, O( Q8 e; ~: @
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" S* |; `: t: y$ }- u - $title = $_POST["title"];
0 J" p# P) [' b2 J - $content = $_POST["content"];
$ T& C, Q( t; h8 T$ x - $tags = explode("_",$_POST["tags"]);( X: N' M" d4 T6 y# r
- $cate = $_POST["cate"];' ^2 |( H7 c# x1 E0 F
- //print_r $tags;3 T! ?: X% g) j
- //
^0 o. @- q7 U* z+ d. ^ - //. |% x2 i, `7 ~- _3 y, h
- $wp = new WP();6 L" Q- t) Q* t' G# d0 G
- $wp->main();
' ^8 y9 R' g7 O* M7 Z - //
) c; m4 v" d$ Y5 P. b8 r9 ` - $my_post = array();
+ ?7 i" m/ p1 h+ C! z" i$ ] - $my_post['post_title'] = $title;8 Y. D A& n. j' [& \9 h* k0 w) B
- $my_post['post_content'] = $content;
" q. _- m4 P' o6 j - $my_post['post_status'] = 'publish';% ?" I3 d7 y& ?3 P
- $my_post['post_author'] = 1;
! e9 E7 J' v: p! T" j$ q; k9 K - $my_post['post_category'] = array($cate);* n* h2 D' g! Y+ K6 x B8 N4 Z7 k: c
- $my_post['tags_input'] = $tags;
, T% ^! D7 T4 C0 {6 y7 W - //$my_post['tags_input'] = array('tag1', 'tag2');
: ?" L( K4 w9 L$ G" g7 l - //$my_post['post_status'] = 'future';9 d) t7 e( g1 G. }; Q
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
( l) ~: s/ P$ c; n6 s& o - 9 I7 i7 z% u1 _# I! C
- // Insert the post into the database
4 @) q* \3 T6 v; [5 q7 c - $ret = wp_insert_post( $my_post );4 e3 }3 u c b) R
- echo $ret;
; A8 u7 X: G" E7 s - ?>( W* k5 z7 C- z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , t# Z6 }6 ]: M5 `4 P l* T
- <?php
: U, U5 S8 D) w' a - define( 'ABSPATH', dirname(__FILE__) . '/' );% v9 T( W4 W8 K
- require_once( ABSPATH . 'wp-config.php' );
# z" L+ l0 S; O+ H# V% W4 G& g - require_once( ABSPATH . 'wp-settings.php' );) b2 A7 Y1 D, h9 Y2 X
- require_once( ABSPATH . 'wp-includes/class-wp.php' ); _) L; l& d4 V
- require_once( ABSPATH . 'wp-includes/functions.php' );1 M/ b7 X* s) e6 |7 U3 x: C
- require_once( ABSPATH . 'wp-includes/plugin.php' );
& c* s4 O) E! m0 A1 k, N5 T - $pic_name = $_POST["pic_name"];9 g, N1 Z7 a% U+ L% Y* w
- $pic = $_POST["pic"]; m3 v. D# {7 b( u
- if($pic != "" && $pic_name != ""); u. a4 I* t" o# g) P" A
- {, Q8 N1 A J9 r4 g/ L8 o
- $path = "images/";
& ~( O8 x% G+ a; I - $pic_name = $path.$pic_name;
6 ^ n1 j! y9 m5 ?9 t% l - echo $pic_name;
I' t; r1 }2 b: m K6 W - echo "||";
. o8 k/ d/ t- K+ }% X9 v& S - error_reporting(0);
$ u& o5 ]+ [% X" y) A2 R - mkdir("images");$ ~/ r7 E2 Y0 j
- $handle = fopen($pic_name, 'w');0 Z& ]: P6 h+ I9 i* z
- echo fwrite($handle,file_get_contents($pic));
2 j' w* \. X1 R5 |4 h - }7 V p) \" S; z, Q' `0 r# I
- & K; ^* j& X+ S/ ]8 x3 i" _
- $title = $_POST["title"];
8 ^4 o& O$ z: S1 z8 q8 I - $content = $_POST["content"];# P% Z/ T" [5 }1 ?9 z
- $tags = explode("_",$_POST["tags"]);
+ n- Q: H7 v' h7 c9 f - $cate = $_POST["cate"];' Q+ J. z6 q6 o% s5 \
- //print_r $tags;, i6 R3 h- U( e
- //. E5 c" r, V# H- K, l0 n- f/ x
- //1 ]& l7 Q& O6 r9 k0 b" }
- $wp = new WP();. P" Y7 D, C' q* X
- $wp->main();
2 \9 C: H( p% g8 Z% g. g6 m" Q2 g - //3 h, v& H; C6 k# t
- $my_post = array();5 ^$ @6 M. r8 V9 S! S- w# k
- $my_post['post_title'] = $title; I. p, Z( r8 q9 H, K* q* N
- $my_post['post_content'] = $content;
1 ]' t5 y; q% U+ v - $my_post['post_status'] = 'publish';8 `4 `& W$ Y7 @+ s, I6 r7 a
- $my_post['post_author'] = 1;( J Y6 f# j4 U; o% c7 z
- $my_post['post_category'] = array($cate);9 K* M& L. @2 d/ M1 W- s
- $my_post['tags_input'] = $tags;
0 B. D( `6 } U. K4 } - //$my_post['tags_input'] = array('tag1', 'tag2');
' L# Y8 ]1 ]7 {7 _1 p# C# n - //$my_post['post_status'] = 'future';
6 Q+ H8 h* \6 L$ C - ////$my_post['post_date'] = '2010-07-04 16:20:03';
& \' f0 ?; }9 k% }. n9 H
- V/ a* f V) d4 p, I$ N& M9 g- // Insert the post into the database4 m0 I1 L6 r% p5 a, t3 J" X
- $ret = wp_insert_post( $my_post );3 v& c0 x" Q+ x, U
- echo $ret;6 ~' R" j0 t# l7 ?; a, q, A$ m+ O
- ?>( F. T5 d6 O: z
复制代码 我自己写的
+ `1 ^! D: P5 j- ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|