|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 : ~ `) }% ?( u# I; x2 C, _: ^
; m: H. @: V; D0 l! |( ]
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持' m( u9 [ T& W
& m4 h3 ^( G/ O0 j
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了. G2 |4 D; i. N8 b- h+ B2 c
- e* G9 ]0 N/ G# N
方便实用 简单 何乐而不用呢- h/ @* B2 v& q
- <?php
' r; a. `* k/ c! q0 p - ( C. ]2 q$ _/ }. i
- define( 'ABSPATH', dirname(__FILE__) . '/' );* E1 W/ i0 _" Y' W. |6 z
- require_once( ABSPATH . 'wp-config.php' );
! X& T& m- g0 O) W+ h' {, Z - require_once( ABSPATH . 'wp-settings.php' );) K& C. h% u/ L5 h6 ?
- require_once( ABSPATH . 'wp-includes/class-wp.php' );* Z5 ]+ Z! h/ x
- require_once( ABSPATH . 'wp-includes/functions.php' );
3 }# O" {- j/ @2 n3 E0 A& u - require_once( ABSPATH . 'wp-includes/plugin.php' );* z+ D( j# T; Z
- $title = $_POST["title"];
' M) i% S8 p5 P. A, D5 X - $content = $_POST["content"];
9 R- M7 `4 X! P - $tags = explode("_",$_POST["tags"]);) k3 h/ B: k8 O! U! B7 P- ^0 K6 u
- $cate = $_POST["cate"];
: g1 y* O" E" i5 W5 ^4 I( y - //print_r $tags;
. ?2 s; {$ f4 Q* D - //4 O" J4 P' y. H8 f: s
- //
$ c8 V2 ]5 w) M5 M- a - $wp = new WP();# e5 B0 ?; A4 d5 I. q
- $wp->main();
1 S9 g+ H1 T8 ]& Y - //
8 o; f0 V' j& @4 u% G3 w) q7 J) U - $my_post = array();6 ?9 D6 a9 E; U
- $my_post['post_title'] = $title;1 q4 l! y/ S. g7 Z6 G
- $my_post['post_content'] = $content;
! s2 X& _& C: _$ n) p1 I* Z, `0 Z - $my_post['post_status'] = 'publish';( b W/ r) c; X. v
- $my_post['post_author'] = 1;
$ ]0 ^/ }5 W: y* x% U" e% ` - $my_post['post_category'] = array($cate);
* W0 W1 e5 Z2 k9 h - $my_post['tags_input'] = $tags;3 `6 B9 V$ F* e1 B6 m
- //$my_post['tags_input'] = array('tag1', 'tag2'); a! t# U! H& K
- //$my_post['post_status'] = 'future';% ]7 ?( p; W W2 B
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' n5 @/ C5 \# C! o8 i - 9 c8 G3 s! u* h0 e# m: Z
- // Insert the post into the database
N4 A+ w4 N% ^7 N C4 s - $ret = wp_insert_post( $my_post );7 f% A2 G1 A6 w3 f$ \ T6 S. a
- echo $ret;
) H" L( a% d- C9 a. U9 Z# j' m - ?>" b3 `+ z5 q7 G# _7 X$ i* z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ) I$ i9 J4 p4 m7 ~0 V; P2 N
- <?php
2 m3 u0 a4 o" ^2 F2 M3 T/ F: B/ d; v - define( 'ABSPATH', dirname(__FILE__) . '/' );- V" _# ~& _- H: y6 {
- require_once( ABSPATH . 'wp-config.php' );- u- }) b. v' x! X2 h8 c- g; s
- require_once( ABSPATH . 'wp-settings.php' );
7 d! M+ a0 c4 i0 H7 a - require_once( ABSPATH . 'wp-includes/class-wp.php' );( W2 ~( T2 h. @+ Y$ {
- require_once( ABSPATH . 'wp-includes/functions.php' );
' y# L1 |7 `9 p+ D - require_once( ABSPATH . 'wp-includes/plugin.php' );
: }) _& G, t1 N+ K$ V3 m+ w' v& k5 y9 z - $pic_name = $_POST["pic_name"];8 o' L) w5 ~. [8 t% v5 W9 L
- $pic = $_POST["pic"];
' U, @: _$ V6 S' X8 z+ G/ P3 { - if($pic != "" && $pic_name != "")
+ h. u3 Z) O s+ F6 r8 F8 v1 C - {
4 E: u, q* a1 M - $path = "images/";
+ q& w5 f2 N& @2 w$ M - $pic_name = $path.$pic_name;
) g( D0 {+ f! T2 J- `' l2 ^ - echo $pic_name;
9 @$ }3 C. h/ w; T- { - echo "||";
) W, y, Y" E/ z" f- w - error_reporting(0);( ]% s, s; `+ P, y# i6 u
- mkdir("images");
& f5 s% a) v- c/ Y - $handle = fopen($pic_name, 'w');$ ^4 d d2 X! [6 h! |; g9 D
- echo fwrite($handle,file_get_contents($pic));+ {' i8 ~+ L8 ]; P# l t/ W# s( f
- }
% O8 X% \: ~6 y) L( N& [
" }- r F: Y( N5 i' n8 h: f9 z. y- $title = $_POST["title"];
8 P5 A" e4 {4 q: y6 U6 X - $content = $_POST["content"];& w8 @1 Z4 o7 z1 z& s
- $tags = explode("_",$_POST["tags"]);6 \' W$ D5 z1 u# G! o
- $cate = $_POST["cate"];0 X/ w c! D5 f9 r
- //print_r $tags;
: p( a! r! V) ?/ _$ q e. J4 x - //
5 Q3 v7 \/ B( O9 s% R - //
5 J' a0 P( j* @' h# B: Z* O - $wp = new WP();# t+ A- B. C) c2 E- m7 l3 P9 L4 L
- $wp->main();% z9 l- V/ R* m+ d& Z) t
- //7 f- ?0 q" }3 a" F
- $my_post = array();
+ Z4 y: Y+ O* q* ^" Z - $my_post['post_title'] = $title;
3 S6 K$ p+ ?( p - $my_post['post_content'] = $content;
2 q: Q. z: J/ ?: F - $my_post['post_status'] = 'publish';
' W$ O5 M+ j! p0 s2 C0 g1 f - $my_post['post_author'] = 1;( [6 f) f! [2 y! g N# P4 {- h# \
- $my_post['post_category'] = array($cate);9 I4 ?7 Y% A+ u0 j5 ~
- $my_post['tags_input'] = $tags;
0 X! S& l; G( ^ - //$my_post['tags_input'] = array('tag1', 'tag2');* E. V/ X* Z) q
- //$my_post['post_status'] = 'future';
3 m. f5 g) ?- W0 F/ u - ////$my_post['post_date'] = '2010-07-04 16:20:03';8 q5 v0 X, i. y" a6 S
- 1 J" E; f' ^3 }. [: N4 k3 @7 E, A
- // Insert the post into the database! r M3 P' c, W) h3 d
- $ret = wp_insert_post( $my_post );* b* `! Y- m% d/ G2 V5 L
- echo $ret;4 l2 {2 i5 Z; Y8 F' X2 v ^
- ?>' a8 Y2 y) \- {3 R: v
复制代码 我自己写的
7 b M2 V8 x4 V m! f8 s7 g( O) B插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|