|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
$ @( t& R+ K0 W7 @2 l7 ?: G) f9 n7 l
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持0 k2 V* }' M8 I3 O9 X$ L
, x# F* H3 A9 F3 m
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
) x! i& P2 h( t
# x: p5 @! }0 {方便实用 简单 何乐而不用呢
* c s/ u8 A, G8 R4 ]- <?php6 @3 Z5 H5 X* s4 E# x# s, f
: J( o) T3 G& X( z3 l7 p- define( 'ABSPATH', dirname(__FILE__) . '/' );
0 K% P3 Q/ J1 B, a5 z! D - require_once( ABSPATH . 'wp-config.php' );. |/ _, V( G' n. [" B' F6 ?" }
- require_once( ABSPATH . 'wp-settings.php' ); q: ~) {7 y- x! B4 c, k% g$ D) J7 ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );; s s I; V6 Q3 L) `# A1 w
- require_once( ABSPATH . 'wp-includes/functions.php' );
( |! E* z, G- C/ q# A, B - require_once( ABSPATH . 'wp-includes/plugin.php' );
" [, x. u: J, Z - $title = $_POST["title"];/ o0 U. N' G' d
- $content = $_POST["content"];# [, f. G3 T, d+ p) ~) w$ h
- $tags = explode("_",$_POST["tags"]);' Y- H8 x) Y4 e, f- ~' g6 i
- $cate = $_POST["cate"];
' O" Q# {" E6 K9 I, n7 O - //print_r $tags;8 l& h+ a$ W; d1 k- k2 y
- //: e8 E' d( n: ^: A( N, Z
- //
1 A. j0 P* v$ j - $wp = new WP();2 V2 A1 R7 Q3 D; _7 \! N/ @# L
- $wp->main();; P p. N) C& g9 D
- //9 _8 y- C/ T; ]! b6 v. I
- $my_post = array();
7 L" ~" b$ q1 y& |4 h - $my_post['post_title'] = $title;
# X$ U$ C; U6 P* }0 c, F9 x" j6 _ - $my_post['post_content'] = $content;
0 C( O( V: h, Z - $my_post['post_status'] = 'publish';1 V( J7 e' J# Z! U9 {4 o& d
- $my_post['post_author'] = 1;
$ z6 a) |7 a; n$ o9 w+ d2 N v) E: R - $my_post['post_category'] = array($cate);
5 d' Z$ u( _" I @- l! L - $my_post['tags_input'] = $tags;6 n# O0 ~! Z- S+ q# i
- //$my_post['tags_input'] = array('tag1', 'tag2');8 B( w% M+ [- J1 A
- //$my_post['post_status'] = 'future';
" V. V* j+ k& p- t* `8 X - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 p" b5 E, }, K: v) N - % B/ O# n. P. q- |2 ~
- // Insert the post into the database
( i: {& z7 x+ ~/ Z - $ret = wp_insert_post( $my_post );/ p! `' P+ f ]
- echo $ret;
{, e5 s7 }* k5 ^! K - ?>
, [1 Y9 l) C" G- p, x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
/ @2 f- Z$ s) k- v7 B2 L. c& ~( g- <?php
8 A8 j3 ^4 k* W9 i - define( 'ABSPATH', dirname(__FILE__) . '/' );& B9 `' n7 m" s5 W) K
- require_once( ABSPATH . 'wp-config.php' );
! z: J) R$ W9 d! O0 U - require_once( ABSPATH . 'wp-settings.php' );# y7 R/ G9 \8 O% `7 }, ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! R7 F. O% X' O - require_once( ABSPATH . 'wp-includes/functions.php' );
" Y) I: u4 }2 `$ Y- B - require_once( ABSPATH . 'wp-includes/plugin.php' );( A$ [& K5 r4 d% R
- $pic_name = $_POST["pic_name"];
! ?, G* Q- d+ A6 W; J/ l - $pic = $_POST["pic"];# n9 C ~# s2 I7 \- q
- if($pic != "" && $pic_name != "")
& l: O% Z# j: a1 F9 i$ P - { b0 o0 P" @0 t7 `
- $path = "images/";
$ u; P2 @3 n! k$ l - $pic_name = $path.$pic_name;3 ~: t' Y* e/ W2 Q2 U9 J
- echo $pic_name;
! H& O& {1 z& B+ ]4 h - echo "||";0 C1 V3 C/ i* G+ a6 J$ Q! A+ Q
- error_reporting(0);
7 o( N5 b$ \6 R3 \& d7 ` - mkdir("images");+ B( ^( G& x3 B% x) v2 c
- $handle = fopen($pic_name, 'w');
/ F r2 y1 n G3 }% r) F9 b4 [- y - echo fwrite($handle,file_get_contents($pic));' y( V$ b3 D7 Y. t1 V r* M
- }* ]9 `6 u ^- g
- ! L- o4 e+ i& \. V
- $title = $_POST["title"];0 V/ z) r" q4 _, |+ Q
- $content = $_POST["content"];9 o- V! P! r5 p1 [5 c9 @. w- r2 P
- $tags = explode("_",$_POST["tags"]); J( [# `; P3 \" C1 ?- ^5 Q/ W* t4 E
- $cate = $_POST["cate"];. K" \0 I6 G8 D' J6 G
- //print_r $tags;
' n8 p6 s6 Q7 j - //
9 x4 [8 w8 a7 ^4 N i: J* P) p - //
k- ]2 |* C5 _3 P$ _ - $wp = new WP();
Z4 _3 ^: S1 o7 Q0 |( M* } - $wp->main();
# W2 T! ^" W' V; d7 X0 p$ i' ?' F' b - //
2 S% L; v- z$ Z0 H3 k4 s - $my_post = array();7 B4 ^. R L6 z) N, \8 l9 f% ?& I
- $my_post['post_title'] = $title;" Q$ \! X6 m- S; G% J% ?/ W& D2 _! D* B# k
- $my_post['post_content'] = $content;
3 {9 ~, t. }' K3 n; d! M. P - $my_post['post_status'] = 'publish';
7 r. W2 b2 |+ b - $my_post['post_author'] = 1;- W b. f5 I5 f: G4 R
- $my_post['post_category'] = array($cate);
9 k6 l8 B% g$ ~- C$ f - $my_post['tags_input'] = $tags;, {" z3 x7 g @$ z
- //$my_post['tags_input'] = array('tag1', 'tag2');$ c0 ]0 P9 p- c" a
- //$my_post['post_status'] = 'future';$ ^; S4 t% I1 ~( x* F* `) J
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- U" C' j( M9 |6 a
% @) |) g/ v4 S; w/ j! S$ |4 b- // Insert the post into the database
8 H1 E3 l. n$ S$ D$ I7 e {& I/ m - $ret = wp_insert_post( $my_post );
5 ?4 {; A$ R4 x/ [ - echo $ret;
0 M4 T& b0 u* W* M( d+ {* r3 ] - ?>2 d/ D3 D' m+ X3 U
复制代码 我自己写的
8 M# s3 o9 b5 S插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|