|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 5 l$ h# T! Y( x7 |& c; D& ]" P
! h7 n n" d( X, t7 n
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
: _: p) r7 R! C2 p% B6 q7 H8 O% m8 r6 M
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 V9 s* R( z# |% H; i8 V* j. x f
# W! J' q0 N4 b* P" B7 _# ], Y! [方便实用 简单 何乐而不用呢
* P0 |/ @2 u2 M- ]3 `1 G' I7 k- <?php6 U+ z- d% w7 T2 `& X( k
3 P8 H1 a0 X8 H' H& r7 V& \% {$ h; W- define( 'ABSPATH', dirname(__FILE__) . '/' );
! c ]2 X5 x3 c T - require_once( ABSPATH . 'wp-config.php' );
( X# K& W% ]1 }6 Y1 W9 Y - require_once( ABSPATH . 'wp-settings.php' );. L; b1 I P# k( y7 g; [2 `5 J
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
# j8 f0 k) }0 V I [! _3 ]5 H - require_once( ABSPATH . 'wp-includes/functions.php' );0 r( V1 v- G0 ?7 g1 y- f5 l- l
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ G" x! f0 b/ [& @
- $title = $_POST["title"];
- J/ f, _; w$ i) v - $content = $_POST["content"];+ C& s- x/ f6 C' d. D
- $tags = explode("_",$_POST["tags"]);2 V/ J# r% G% f
- $cate = $_POST["cate"];: M3 ?, z) c# h# U
- //print_r $tags;
+ P. o$ D" G6 y7 c6 c - //$ u- i/ |* b8 ?/ p1 U0 \
- //
( P9 J$ N9 P( R/ U( l* Y - $wp = new WP();
4 l; R4 y9 U. Q8 X) M* m, B0 J0 K - $wp->main();
/ r; _7 J2 _- y) d/ I) B+ k - //
( J \$ E8 Y3 y' I: e - $my_post = array();1 J& _; U5 ~/ A. g- N/ A
- $my_post['post_title'] = $title;; m" n# j/ N# Q: i0 s: l/ s
- $my_post['post_content'] = $content;
9 U, q) G1 E# D) B - $my_post['post_status'] = 'publish';- j6 c# u6 a. Z/ G0 ]! L r
- $my_post['post_author'] = 1;
% j( |8 f, U5 P6 \; L8 F+ r - $my_post['post_category'] = array($cate);
2 h0 ^+ ~ B; I @) x0 J( G - $my_post['tags_input'] = $tags;
2 q2 [2 Z4 g6 a4 E! J1 s! E3 j - //$my_post['tags_input'] = array('tag1', 'tag2');
5 A7 M6 _6 i) Y' X- c4 ~ - //$my_post['post_status'] = 'future';
" T" p) y3 G1 M, K1 m7 i% F - ////$my_post['post_date'] = '2010-07-04 16:20:03';
" j* x& x- f) g( G3 q7 B( D - ; b7 l8 u F6 [" b) }6 F
- // Insert the post into the database4 _( B" t- f U& C3 r! L7 t) |+ Y
- $ret = wp_insert_post( $my_post );
, ~4 k3 W; O k/ I( T - echo $ret;/ ~7 `% W( R1 T, ~3 o
- ?>% r: ]. b5 Y ]+ r+ C: T
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, \' M4 l2 N1 E6 G+ P/ Y5 w3 D8 I* {8 `- <?php
; U/ P, r" r9 }. M4 N2 e8 I - define( 'ABSPATH', dirname(__FILE__) . '/' );* p6 E2 A" @$ [
- require_once( ABSPATH . 'wp-config.php' );
! G9 S) m& [- Q# ] - require_once( ABSPATH . 'wp-settings.php' );! E. O; T, l5 `! l+ P/ r
- require_once( ABSPATH . 'wp-includes/class-wp.php' );8 l/ E8 A, c/ E
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 g# g* u, A" m( x: Y: U$ W - require_once( ABSPATH . 'wp-includes/plugin.php' );
" I4 g, r( m1 P* z5 o - $pic_name = $_POST["pic_name"];( c* @8 S* K6 K
- $pic = $_POST["pic"];
: ^' K7 W V& S# a3 @' M - if($pic != "" && $pic_name != ""), j, t- Q) P, l- ]/ n( m
- {
6 M# D+ P3 O; v: E+ N# j7 U - $path = "images/";- p/ w0 m6 ~# K/ r0 W& L* z% s2 a
- $pic_name = $path.$pic_name;0 x9 J. [, S; Z2 M1 n
- echo $pic_name;. U! ^; z ?! Y! B
- echo "||";
) u% g4 B L' Y u1 Z - error_reporting(0);
* a1 ]9 Q; q1 ?( K8 U; P - mkdir("images");
9 D0 S& P x; _: M. d4 r - $handle = fopen($pic_name, 'w');1 O h6 N! U( c) p+ B7 _
- echo fwrite($handle,file_get_contents($pic));+ s- O, O9 v) Y) p6 h* Y
- }
8 ]: T5 { Z6 s% o; ~
) _0 ^- B% W" p' N6 R/ w8 `4 W- $title = $_POST["title"];
3 U9 O: Z4 Q: w$ p K - $content = $_POST["content"];
' j1 ?$ h$ }. ~+ [ - $tags = explode("_",$_POST["tags"]);- N$ H; [; V6 S6 b
- $cate = $_POST["cate"];9 e4 y! G/ r. ^5 n& I' L
- //print_r $tags;: l6 r) ~- \' K
- //% o! j+ w+ _* n: c2 U" b" {
- //5 W5 z7 J# h" {
- $wp = new WP();
* h# L, m1 }" X* R! e9 x6 P9 i - $wp->main();
" t* J0 z1 O" F - //
( P& a+ s- s8 N, v$ @2 _ e - $my_post = array();! T4 G3 |9 G8 O) P
- $my_post['post_title'] = $title;
/ F4 v5 j5 }) Y$ c! w: \" Y - $my_post['post_content'] = $content;
4 X& ]* \/ t' A0 V/ Y - $my_post['post_status'] = 'publish';
3 c+ x. i5 N: c4 T - $my_post['post_author'] = 1;" d4 J! m5 h( `/ k: L7 |" L" e J
- $my_post['post_category'] = array($cate);
# y+ K6 k, j+ b# | - $my_post['tags_input'] = $tags;! L6 \9 D0 I# \7 ^0 z" @. ]: J
- //$my_post['tags_input'] = array('tag1', 'tag2');
; ^* M7 {/ ^6 E+ h - //$my_post['post_status'] = 'future';
8 {- h1 \/ d* S6 I7 [$ X - ////$my_post['post_date'] = '2010-07-04 16:20:03'; F# _& i" x0 {( ?2 E
9 I& P# `' I' i& d7 q3 K5 i- // Insert the post into the database
+ h5 M% H* Q4 {" U - $ret = wp_insert_post( $my_post );! ~# a' e' U' {: G+ }
- echo $ret;4 h! K8 N$ A. [- E* W6 d: C
- ?>, W8 o( _& E& q/ F2 h
复制代码 我自己写的4 K9 l& A& a1 g3 l; o
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|