|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 I! y4 L* g: B* h
0 G: ?+ q5 A9 d0 e: S/ d
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) r* }+ I: g: w/ ]# Q) i( c2 x( }; X) D. m$ p! {+ ]" |+ y% o
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 ]' p. ^0 I9 N( n3 e( P# A; R$ p
% M( E, \4 K: e0 r! v7 [) Q6 d# Q方便实用 简单 何乐而不用呢- " @6 p4 |5 i! k4 f
- <?php, G% S1 T3 q3 Y8 v/ ^$ Y2 P5 }
- 1 K+ a" ?& e3 w z4 h: J) N% T& m
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: ~4 T, _, I6 D# f- H- R7 W - require_once( ABSPATH . 'wp-config.php' );" A2 P! E! f. M: Y y9 @, Y
- require_once( ABSPATH . 'wp-settings.php' );! k! m: }/ @" y( v/ e @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( c6 h% w9 Q& t# d - require_once( ABSPATH . 'wp-includes/functions.php' );
+ \/ ^9 E0 q! J- g7 Z7 A - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ b( u# M; B+ p/ K - $title = $_POST["title"];
8 i9 g; R6 I# ]& o% G - $content = $_POST["content"];# A1 S# C8 O0 H9 W
- $tags = explode("_",$_POST["tags"]);0 d" ] F; Z. n" ^
- $cate = $_POST["cate"];
! q. b- I9 C) d3 U8 y - //print_r $tags;/ c% g3 C, D* L
- //$ R- V2 E; T% e. n# q
- //
* Z0 `. i2 ~- Q, `8 J - $wp = new WP();' j# w+ v* h% w% O" }0 t
- $wp->main();8 N: a! i: i( X3 w; r
- //
6 H$ p, s# o) B. N& d - $my_post = array();
6 N" x' f. O' h9 e - $my_post['post_title'] = $title;+ [: J4 i5 g2 z( X8 p4 z
- $my_post['post_content'] = $content;
" J0 i& K8 T% z1 n5 m( }% }! d - $my_post['post_status'] = 'publish';
4 Y8 {/ z0 r" V8 a8 z, `6 \ - $my_post['post_author'] = 1;
- M, e2 c* }( Z, C# p% E. w' } - $my_post['post_category'] = array($cate);. L8 L& q: T8 e. c2 ]" A. c+ C) m9 e
- $my_post['tags_input'] = $tags;
" N( u0 l; Y! j1 Z - //$my_post['tags_input'] = array('tag1', 'tag2');; C, m4 k" o% x, b9 N# {" A
- //$my_post['post_status'] = 'future';
3 E0 O) H) t; y( t - ////$my_post['post_date'] = '2010-07-04 16:20:03';1 [1 t& h/ j9 n
* q- n- K7 B# R2 u- // Insert the post into the database7 K- y2 m2 z/ Q3 n
- $ret = wp_insert_post( $my_post );
9 ~& o0 U" ~1 V$ O* } - echo $ret;) c8 t4 U+ E3 z0 E( @
- ?>
# q. R% l, F1 a' `% }5 [
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & L% h( j, m9 l; {5 v4 ?: j
- <?php
; I) v- D8 n, b1 { - define( 'ABSPATH', dirname(__FILE__) . '/' );
: r+ h8 [1 t: ^; ?9 l9 R - require_once( ABSPATH . 'wp-config.php' );
; v+ `; q) }1 V: L+ x - require_once( ABSPATH . 'wp-settings.php' );3 P/ z* n( Y* ]) \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );% O, f/ V+ ~! G& A* V
- require_once( ABSPATH . 'wp-includes/functions.php' );9 G! |& s, M [( r A1 V9 W- |% _
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ o* K+ H7 i' Z1 r - $pic_name = $_POST["pic_name"];# T% C2 o |2 M. N+ o
- $pic = $_POST["pic"];+ Z6 q. E; X; m, h0 k
- if($pic != "" && $pic_name != "")0 i. m5 t/ V" O) q0 H7 S
- {- D0 | V1 f0 o7 u) f) T- v t
- $path = "images/";
, \" X, Q$ i7 h5 W5 n1 T( t { - $pic_name = $path.$pic_name;; j' L: u5 n$ ?% S3 ?
- echo $pic_name;
8 H1 @0 z/ W7 m - echo "||";) r: C7 ^8 X$ _& V
- error_reporting(0);
0 Y9 W' H* U7 T0 Z4 \ - mkdir("images");
1 w9 S2 p% P; F" l8 [ - $handle = fopen($pic_name, 'w');7 G$ v# ]4 i, v
- echo fwrite($handle,file_get_contents($pic));! ]7 U' @* D& s- X5 v9 L
- }
5 I1 _9 \8 h: ~5 H4 L, m( ^0 E
1 N' q: p W# m9 M8 }- $title = $_POST["title"];
0 N. b/ V2 T( O- \+ X% o) d - $content = $_POST["content"];; |& I$ o* }# |
- $tags = explode("_",$_POST["tags"]);, n! K7 V \2 P. Z7 X6 `0 L# N6 Z
- $cate = $_POST["cate"];
5 A$ b( p* @1 Z8 U `$ ]- U: \7 x' s) j - //print_r $tags;
# i U5 d/ T. M) v; B; e' \! e" W; b, n - //8 @/ Q" a4 f2 O9 G, C
- //
4 R; p$ ~% C+ _/ l. W - $wp = new WP();
9 A0 n. L0 d' X' T3 q* S: W - $wp->main();" M& m- d: {% [/ W
- //. K* I3 C( p5 K8 V. n0 D& K* E
- $my_post = array();. y {2 p/ p' W9 H
- $my_post['post_title'] = $title;3 C+ J; `$ w- O! A6 t! j& W
- $my_post['post_content'] = $content;
5 N. ]( N1 Z3 x) N - $my_post['post_status'] = 'publish';4 s! A# _3 l0 f0 O) r
- $my_post['post_author'] = 1;% z( I1 M; S1 z/ g9 y" ~
- $my_post['post_category'] = array($cate);5 {+ {! f( T8 f" V# ]
- $my_post['tags_input'] = $tags;
: z: p6 F2 ^6 V - //$my_post['tags_input'] = array('tag1', 'tag2');) J% D8 U+ Q& {
- //$my_post['post_status'] = 'future';
7 h1 q: c+ [" L+ F' |5 q! d/ o - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. M* O+ I5 B+ i. _* [5 S; k7 N
9 y3 r) `$ Y' ~ r5 |, \4 a; C+ t- // Insert the post into the database6 \7 p$ Y( s# Z( p
- $ret = wp_insert_post( $my_post );, G5 e. ?( ?* m* b
- echo $ret; ^/ ^% P% P' p5 B: z# G8 h
- ?>
8 C8 ~. A& j; }. J% U
复制代码 我自己写的8 F, ?. G6 m8 _0 w8 @
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|