|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, Y( e3 L. D# ^" n9 z% C! d5 _/ w3 O5 z
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% N+ |6 L' L& t& \. ^
' [" _! K8 m) d. x9 y" U% n/ O2 S我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ x- A! h y+ l9 g6 U
1 _! l" ]& w' Y8 P. G8 y方便实用 简单 何乐而不用呢
6 \( V2 k: Z6 ?# f" e u- <?php: d, w. r: m0 D" I0 Y; f: A
; N2 g- V+ a: o6 F- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 h6 X8 ?/ P' k6 V+ c, d% ^ - require_once( ABSPATH . 'wp-config.php' );/ ]$ d) x1 Y- G+ i* Y) `1 N
- require_once( ABSPATH . 'wp-settings.php' );
7 Q2 d* w b$ D3 h% t: y - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; A J) j5 u7 H8 c# X* U& X# d - require_once( ABSPATH . 'wp-includes/functions.php' );9 Z+ e! n4 |% u& \3 t1 e
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 z& x& V5 u& D6 L9 l) K1 x
- $title = $_POST["title"];
% T% V4 |$ P" l) B - $content = $_POST["content"];
$ I5 u! y* M, G% `- n - $tags = explode("_",$_POST["tags"]);) M, E: u. H" F" ]& Q
- $cate = $_POST["cate"];% G5 A5 R8 A/ z' m( m
- //print_r $tags;, K1 p( u* t9 w9 M/ k3 q
- //
/ w+ V, u/ i. z# a6 X" ~ a - //
/ g- f% k" B: y - $wp = new WP();
0 q& ^ E7 X+ D/ m B7 v x: W2 B - $wp->main();1 _* w' N- _4 {( Y. o& M
- // Z: o, q, C9 e) l
- $my_post = array();# j3 e0 _1 y! ^5 ^8 u6 c7 x
- $my_post['post_title'] = $title;: f- w& Z# v& h
- $my_post['post_content'] = $content;
' J: T+ q6 L4 C7 y+ a( \ - $my_post['post_status'] = 'publish';) T2 U! Q1 X3 L7 o: d
- $my_post['post_author'] = 1;
1 E: o# T/ W. X& k - $my_post['post_category'] = array($cate);
, W# }- y9 k+ H+ r) S - $my_post['tags_input'] = $tags;% b% c1 m5 }! O4 y: N! {1 h
- //$my_post['tags_input'] = array('tag1', 'tag2');
* e% C! b6 \# s. ] - //$my_post['post_status'] = 'future';* t6 Y* b3 ` y% y7 `* I
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 D% J, o' t6 d. ~6 [0 X - 7 b+ ?% ^! a; _4 W9 Y5 d
- // Insert the post into the database/ n! |6 x$ u- y; d6 P1 L- _, x0 a8 ~
- $ret = wp_insert_post( $my_post );. Z5 n* V9 }( G( E4 Z! e
- echo $ret;; t, t C I* x% {' p3 E; V+ ?
- ?>6 V$ H7 l/ m( G9 c* P8 y, Z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + x( O. C# m, }' J' b# c' S
- <?php" D) A6 V+ G8 t. d, @6 \9 x- J; p
- define( 'ABSPATH', dirname(__FILE__) . '/' );, |# G: a" d5 L; k& R
- require_once( ABSPATH . 'wp-config.php' );0 f! z$ R0 x2 a. D% N
- require_once( ABSPATH . 'wp-settings.php' );
( D0 A0 L+ f: ~9 n' s - require_once( ABSPATH . 'wp-includes/class-wp.php' ); Q" [2 S! ?8 d0 \1 i5 r
- require_once( ABSPATH . 'wp-includes/functions.php' );
. S& N3 M; O! x - require_once( ABSPATH . 'wp-includes/plugin.php' );
% P4 o- r5 I6 ^4 W! E& X0 d - $pic_name = $_POST["pic_name"];
+ T, y/ E+ N0 } A- I - $pic = $_POST["pic"];( A" u% U p, d8 M+ x% b, Y7 L1 W
- if($pic != "" && $pic_name != "")
/ w/ ]: {( g' B. O/ y& ` - {
9 E. e, K8 J& U9 }) K! p8 n( ] - $path = "images/";
1 G5 i2 ]/ C5 ]+ f% ^( }& p' ~+ R - $pic_name = $path.$pic_name;
6 D( m/ [% U& S5 f0 J: o - echo $pic_name;( n& h0 G1 s6 x7 w! s! F
- echo "||";
# t6 i2 d! a8 ^0 V - error_reporting(0);2 _: ]! `$ L3 k/ E
- mkdir("images");
9 S6 C: e9 n- h+ C - $handle = fopen($pic_name, 'w');
! l; r) ^+ l7 C+ ] - echo fwrite($handle,file_get_contents($pic));
$ g6 K2 C; Q. N8 P% R2 g$ m - }, [+ e* Z& T" ^
/ k4 X" j, C, E. K- $title = $_POST["title"];
1 O* e' a5 J& M5 W - $content = $_POST["content"];( m' m, r! h0 s" d7 J. y
- $tags = explode("_",$_POST["tags"]);
# f2 W0 q: {: |. j0 Q - $cate = $_POST["cate"];* c* r# r' b: F
- //print_r $tags;
, P& v9 v' i9 Y8 ?- y+ k - //
2 {6 b& V$ [ L& [ - //
* l. H4 W8 P V" p( f- V o' D - $wp = new WP();$ W0 W+ i$ G; f3 A# H
- $wp->main(); j0 D# |; |9 I, C
- //
; |5 g, ]7 I7 H - $my_post = array();
" A. M7 e& X, z - $my_post['post_title'] = $title;
/ Y) p) b( a _7 U1 s. ?. B - $my_post['post_content'] = $content;
- E1 U/ p! { Y& G/ f - $my_post['post_status'] = 'publish';
0 i: f! H5 ^8 Q2 O" U - $my_post['post_author'] = 1;, ?# _3 P# o* f/ J2 H
- $my_post['post_category'] = array($cate);/ D% l; s [# M/ V
- $my_post['tags_input'] = $tags;
' ^& A5 f: i# d! T5 _ - //$my_post['tags_input'] = array('tag1', 'tag2');
: f! h) @' ]! n7 m. L - //$my_post['post_status'] = 'future';! |9 X+ L n |) \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 W2 O5 n+ P/ b+ K) G3 `
) g* d( n0 Z& B, m0 J- // Insert the post into the database! v/ A2 P4 L' G& ?# ^
- $ret = wp_insert_post( $my_post );
- G( F4 [" S7 x; \2 J - echo $ret;
0 L& N7 x4 Q. v* a( Z - ?>* q( Y( ~1 q9 D6 e/ H
复制代码 我自己写的4 r$ n8 @: Y- n2 ]4 v: O0 @ N, F/ O
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|