|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
/ p8 V& q5 B4 ]6 U. R# z% l, X( I& T
/ G# Y! }4 U: ^ z! j3 i; F* @% \4 c直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持) y7 \$ d3 k6 g% c
- c& z l8 }: P* }& ]
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
) ~4 g I1 g2 I" t
. D/ Z/ u5 N- [, i5 X. H方便实用 简单 何乐而不用呢
7 k6 F3 w3 \7 c4 S% ~- <?php
; {' }' \* a. m - 4 n( f4 k6 g- j1 w+ P0 A" u
- define( 'ABSPATH', dirname(__FILE__) . '/' );
+ d2 m/ G" P# |2 [4 H5 n - require_once( ABSPATH . 'wp-config.php' );) V5 \5 T/ y& G* I+ ^
- require_once( ABSPATH . 'wp-settings.php' );
& G+ X, r# D; N( v$ } O. u - require_once( ABSPATH . 'wp-includes/class-wp.php' );% t* Z$ S4 W& [/ l/ n& r) p
- require_once( ABSPATH . 'wp-includes/functions.php' );0 {1 _, @, o& E$ a* E
- require_once( ABSPATH . 'wp-includes/plugin.php' );* p; H" f p0 Y- F$ s6 \" o( D
- $title = $_POST["title"];
" k9 V9 H; ]1 ]7 u! E+ y) h - $content = $_POST["content"];
p; i: D! H+ | - $tags = explode("_",$_POST["tags"]);' `4 y9 Z, M' N$ {: G' Z" B, d
- $cate = $_POST["cate"];
" g& ~0 v9 `' O( k: ?( {3 h - //print_r $tags;
" F% o. j! c6 X - //9 I" f+ ^$ u- ^, E2 o4 F2 w; H
- //
4 G- @. z2 K# i( j& u- P - $wp = new WP();
6 {9 O# l! r+ k \ - $wp->main();5 p+ e( q6 X) g/ P9 ?
- //( D/ J4 l: A; Y) F* T/ J
- $my_post = array();& |$ I: C' ]- d
- $my_post['post_title'] = $title; Z7 Y5 f9 M1 [1 U# A- A! \7 l
- $my_post['post_content'] = $content;
- k1 e: c+ v& u - $my_post['post_status'] = 'publish';
5 H. b+ r; D% g5 h7 B/ n* `/ I - $my_post['post_author'] = 1;; R' p- y7 q! K. \, U( _2 M
- $my_post['post_category'] = array($cate);
1 c7 {5 T. C! i' k - $my_post['tags_input'] = $tags;
& I8 ]( b/ S! @0 P - //$my_post['tags_input'] = array('tag1', 'tag2');
" t' \( o, {' E: p8 T1 k2 ^ - //$my_post['post_status'] = 'future';
: Y. `- E+ b% H. r% f7 E) i7 B6 w - ////$my_post['post_date'] = '2010-07-04 16:20:03';6 z! s, b) q) A( v Y$ D0 @; o
- 5 h7 c& I# I* y! \& k
- // Insert the post into the database
2 V% n( @. }1 i3 |6 d% O* _ - $ret = wp_insert_post( $my_post );9 ~ ?% G+ b+ y/ ^. t9 d
- echo $ret;2 N3 D5 X( u: M; M" Z
- ?>" L! d" x5 Y) y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 0 B4 i2 y& }( X% r% u
- <?php
; K: w) _+ g9 u& S9 T# v - define( 'ABSPATH', dirname(__FILE__) . '/' );/ {5 A- Q1 O: @( X2 K
- require_once( ABSPATH . 'wp-config.php' );
8 e( M& \3 E; j, B5 P, `6 s: _ - require_once( ABSPATH . 'wp-settings.php' );% C5 k0 N) A* J: y7 h) h% M
- require_once( ABSPATH . 'wp-includes/class-wp.php' );# c+ _8 V' i1 C2 q5 z& Y# m
- require_once( ABSPATH . 'wp-includes/functions.php' );3 q7 g: j Z( ] A
- require_once( ABSPATH . 'wp-includes/plugin.php' );
3 f2 g( v! W) O( p0 ~' D! R8 D - $pic_name = $_POST["pic_name"];/ |' e6 K9 N* E- t) k. J
- $pic = $_POST["pic"];7 X1 u% p# y- }
- if($pic != "" && $pic_name != "")3 D, H) ]! T1 I; z' F
- {
- ?+ `5 V# `# h; k4 C4 m9 z6 c$ k - $path = "images/";
5 ~, J) F* k, v; f' p - $pic_name = $path.$pic_name;5 |: f, H/ e& g- Y
- echo $pic_name;
}, L) K, n, C - echo "||";
3 I" v' @3 A7 p! `! j$ c - error_reporting(0);- _! w! v$ f6 o# [
- mkdir("images");
" B$ m4 z- p- u4 z; F - $handle = fopen($pic_name, 'w');7 w( r9 j# C; }1 W! i
- echo fwrite($handle,file_get_contents($pic));- ~; a7 d% ~8 Z5 ~+ i5 a
- }7 s0 P) ]. e) O8 i' \/ q5 D
- 2 U9 ]' x5 v- O' ^+ M/ ]' }! d
- $title = $_POST["title"];
( O# W& E, s" J - $content = $_POST["content"];" X% V& f, ~% z8 k8 a0 n* |
- $tags = explode("_",$_POST["tags"]); V* |5 [. u/ M4 ]$ j: y
- $cate = $_POST["cate"];5 W" c9 q1 V. d/ x7 J- K
- //print_r $tags;
; l5 P% G2 T9 |7 T' t$ j - //
4 z+ F3 g7 n. E9 |6 R9 B1 Z - //
' D" Q. c& z! o3 Q5 N: I - $wp = new WP();
/ y. \" `6 D+ h3 F4 T - $wp->main();4 {8 r" V# B% h0 d h2 [4 e
- //, K) k8 ~4 e6 v0 _$ V0 E
- $my_post = array();4 j% g( A+ ^7 L8 n) _; Q4 I
- $my_post['post_title'] = $title;
- J5 w) C, s: }4 Y7 L& N6 Z, l! | f l - $my_post['post_content'] = $content;. g* X* i! B. [0 a/ Q
- $my_post['post_status'] = 'publish';; @3 _0 J# n; _" F( @( z
- $my_post['post_author'] = 1;
" ^" y3 G% L( a6 h) C; v - $my_post['post_category'] = array($cate);3 ^7 i" F( f( e) I/ i8 a7 ]- M
- $my_post['tags_input'] = $tags;2 _/ l: v6 x' p3 \
- //$my_post['tags_input'] = array('tag1', 'tag2');
6 @9 r* V3 L# A! T- c+ [" P, Q - //$my_post['post_status'] = 'future';
) [1 w; ^8 f. X6 a+ } - ////$my_post['post_date'] = '2010-07-04 16:20:03';) d/ O( I& l1 j2 v6 ?
- : w' a8 M6 F2 \) F6 K8 j# v4 `
- // Insert the post into the database
) ]& N( Y P8 s3 ~1 u - $ret = wp_insert_post( $my_post );, K" B4 H% f; F: p, {7 W9 O7 q
- echo $ret;( \- F% K3 I D2 Q: M W Q! h8 `
- ?>
5 N% z# p* |: X: c+ A: i% F( G- n
复制代码 我自己写的
. H t$ P6 O4 F9 q3 K# n插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|