|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 O& i) o' S9 n: _0 o# W# M% c ^
: Q9 `4 p( L7 j0 S& w$ k
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 W0 i. J6 s0 E; Q1 c8 T( r3 U e) d/ _
% J$ U& F9 F5 x" k2 N+ V& O) A
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% b# B3 B3 T+ [" e# p/ \
8 ?, }/ Z- p- _3 H: F9 O5 a: ]
方便实用 简单 何乐而不用呢
! K9 |" B2 I" U: V- K( m1 Z% @- <?php
% q, x5 i+ v+ i3 I8 v w: E+ \7 m
1 k3 `. V/ j6 ~# s- define( 'ABSPATH', dirname(__FILE__) . '/' );) P. Q+ @( o, H1 X$ X6 q
- require_once( ABSPATH . 'wp-config.php' );
8 S; m B8 g1 A6 R - require_once( ABSPATH . 'wp-settings.php' );
8 ]$ s8 l% {7 a7 t# { - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 D6 _" B( m2 C2 S
- require_once( ABSPATH . 'wp-includes/functions.php' );1 c7 B: b- Y; Y- Z! j$ C: _3 k0 z
- require_once( ABSPATH . 'wp-includes/plugin.php' );. I2 W% o3 q0 _, v
- $title = $_POST["title"];
/ r2 Z; z8 c) T" m Y2 V$ m - $content = $_POST["content"];
. k- z; _# c7 U6 d - $tags = explode("_",$_POST["tags"]);, }/ k) f& n( L; D* `" |- S
- $cate = $_POST["cate"];0 h2 b' {% e! t) G. i
- //print_r $tags;! S6 @; b& ]1 i" u3 Z9 s; a" G
- //
% n* {) F4 }) I7 V$ J7 O0 }/ e# e - //
( f% U% E6 c w - $wp = new WP();, F/ N( I1 p2 [
- $wp->main();& V1 g3 d9 D9 a' W
- //8 F6 ~( i8 C& j7 g4 d
- $my_post = array();
2 O$ I! J# c) g& M' h: \2 a; r - $my_post['post_title'] = $title;
9 w E z1 ^! Y6 `+ d d! { - $my_post['post_content'] = $content;
/ W. C8 C9 C* ^# n( Q2 |5 w - $my_post['post_status'] = 'publish';5 j. w" _# J ]5 o3 [4 o V* Y0 Y0 F
- $my_post['post_author'] = 1;9 W) N# ]8 Z& N; S# J5 ]8 k6 J
- $my_post['post_category'] = array($cate); w$ d9 s( Q0 E# R' I
- $my_post['tags_input'] = $tags;
; y/ J/ i2 Y( a7 z2 X6 L4 r4 Y - //$my_post['tags_input'] = array('tag1', 'tag2');6 T3 }% ]# q" g# f) X6 ^! T
- //$my_post['post_status'] = 'future';
/ n# ]4 E" P Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 O5 j4 f6 ?0 I- b, C - ! P& A3 J3 Z& w
- // Insert the post into the database3 o) M4 W, _9 L: V" S: k' U
- $ret = wp_insert_post( $my_post );
2 \! X2 |+ |6 D: | - echo $ret;! I( [9 |% [, T' f9 T- o
- ?>
1 o7 |- |0 t) X8 b9 Z$ V: r
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- - h! F* x7 r+ L+ z' o
- <?php
; }2 H4 v4 w o/ l/ U6 s6 H p: t - define( 'ABSPATH', dirname(__FILE__) . '/' );
( \, Y- G7 `; m o2 i1 f - require_once( ABSPATH . 'wp-config.php' );
, C4 _1 ^2 A" |' q8 |) ^) b" G - require_once( ABSPATH . 'wp-settings.php' );' a) {0 H( P) L9 B" H1 G- P
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
# \' e6 A+ }1 \( z( K( K2 a - require_once( ABSPATH . 'wp-includes/functions.php' );4 g n, k o9 o9 r* j/ B0 P
- require_once( ABSPATH . 'wp-includes/plugin.php' );
) e4 p$ L- c4 v0 Y0 y* X - $pic_name = $_POST["pic_name"];
/ ~0 s5 F x% W( |; _0 l - $pic = $_POST["pic"];* ~: Q4 o5 ?4 T( t9 W O
- if($pic != "" && $pic_name != "")
' q. r3 C a5 O5 B' W+ z$ E: W7 R0 _8 L - {
$ i! ^" L7 `& j7 H2 L* k) z+ @. I - $path = "images/";
`1 ^% Z2 j+ ^ - $pic_name = $path.$pic_name;% ^* j7 ~! ?8 }4 G
- echo $pic_name;/ _3 w# f% K4 s+ M
- echo "||";
& h: y/ Y. {' C% c3 M/ v9 | - error_reporting(0);
6 k7 D* b+ s* m7 X9 ~) ~3 ~ - mkdir("images");! k- R' B6 B; t+ Z0 }/ S b0 D
- $handle = fopen($pic_name, 'w');9 s. A; H |: S5 n& j1 S
- echo fwrite($handle,file_get_contents($pic));
6 V1 m: }# e. J8 v$ e5 ^! y - }
. B! \2 Z. }% P" H8 K/ l& ] - 0 ?8 x0 j0 `" Y
- $title = $_POST["title"];5 Z8 }/ L8 o1 @8 r
- $content = $_POST["content"]; v/ d4 E+ ?) s' A: u! o6 E
- $tags = explode("_",$_POST["tags"]);+ d5 s# s' u. [8 @6 J; P$ d
- $cate = $_POST["cate"];, i/ B8 Y* z% v' \
- //print_r $tags;
$ @. s6 i8 Q. l$ c - //7 }1 x" Z# f! f: o# s$ S0 b, B
- //+ E2 x3 R3 g9 W4 D4 T; y
- $wp = new WP();
& q5 Y s6 L& f# z- ]2 ^, y - $wp->main();# X$ z. m+ h1 Z
- /// ^, l! M) p/ h9 ^ j7 r
- $my_post = array();
3 @' J9 [% b: Z2 j - $my_post['post_title'] = $title;$ ^$ f6 X4 Z; @4 k0 ^
- $my_post['post_content'] = $content;& R) P, z2 T/ r+ r u
- $my_post['post_status'] = 'publish';, |0 g1 r$ P4 _8 O& g" g$ V" w
- $my_post['post_author'] = 1;
( g; m2 ^+ o: v# o; l$ @( x - $my_post['post_category'] = array($cate);. ~3 P' `9 j. s
- $my_post['tags_input'] = $tags;
7 r' Y- g; ^3 V3 g - //$my_post['tags_input'] = array('tag1', 'tag2');
6 @) i' g1 q' ~& F; t E) m b! @7 ^ T - //$my_post['post_status'] = 'future';
& {2 p: R, j6 Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';
) B4 b( B% l" l% j - , B# o/ R9 H2 b1 a0 G
- // Insert the post into the database' t2 m" Q V4 X& |# N1 [' Y
- $ret = wp_insert_post( $my_post );5 o% Y. T" v. r' @/ g2 h
- echo $ret;' l' i9 S H6 I/ a1 ^
- ?>
5 O/ l6 M/ Y. F3 o
复制代码 我自己写的* |/ r3 [8 C" C- @% B V
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|