|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 , g. ?$ _7 L1 U; s% A
4 [" t+ A) s' J; I# Z; t
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持- s; G) e5 s! O+ z. w
# |; @9 f6 q4 I ~- w1 Q7 h我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; s* v$ u& R4 j: r+ N+ L
9 f# X: }4 Z. `2 h3 z# K方便实用 简单 何乐而不用呢
. C5 Z5 M' W, B$ R% O- <?php, c' k0 u+ D0 U: H4 o( q. c- ~
- F, H6 K3 c( ]5 w9 r
- define( 'ABSPATH', dirname(__FILE__) . '/' );: I# L# n2 f) s* g' z$ \
- require_once( ABSPATH . 'wp-config.php' );
4 G/ L, e% \" q6 a$ \& H - require_once( ABSPATH . 'wp-settings.php' );
5 K" r1 I( c2 h# ^; b - require_once( ABSPATH . 'wp-includes/class-wp.php' );! V) u, K2 y& S9 Z
- require_once( ABSPATH . 'wp-includes/functions.php' );
8 Z. C0 G( P6 u - require_once( ABSPATH . 'wp-includes/plugin.php' );' R8 m; M3 g% p
- $title = $_POST["title"];
9 o( b, b1 a7 y1 f$ | - $content = $_POST["content"];
. v9 H& C) w& T+ b9 }- [: n7 } - $tags = explode("_",$_POST["tags"]);- U; s& i! K; i
- $cate = $_POST["cate"];7 o! w5 ]* B0 U- t$ o
- //print_r $tags;
: q, s! y4 r, c1 Y+ v I: e, { - //7 b; k! r; [. D5 x" {
- //
3 O) I% b; z6 ^ - $wp = new WP();
! ^+ G% R( W) {4 ~ - $wp->main();8 {2 k6 Y8 p" S( W7 d) S) X* c
- //, e, U' U! l6 {8 I; t; u: y. B5 p
- $my_post = array();; O% }' M+ X9 h" \7 N' f% A
- $my_post['post_title'] = $title;
3 h$ n: A* ~3 O7 ^3 p2 H C- Y - $my_post['post_content'] = $content;7 t) ^# [6 f, B8 g5 T
- $my_post['post_status'] = 'publish';
( D, c$ ]5 _% r3 w- e; b - $my_post['post_author'] = 1;
1 F i8 J/ q, |+ p - $my_post['post_category'] = array($cate);
( w% i7 e8 M( V9 T - $my_post['tags_input'] = $tags;0 }' @; k' m5 b) d& l" p, M, X$ L/ Z- N
- //$my_post['tags_input'] = array('tag1', 'tag2');1 g& ?1 u" g, x5 \! ^. D
- //$my_post['post_status'] = 'future';
6 k( }8 K" E; A3 d0 e# R - ////$my_post['post_date'] = '2010-07-04 16:20:03';! w) D- R% P* f* A
- t1 M6 d+ v$ i; W( B/ x
- // Insert the post into the database
+ X# I; H o; v - $ret = wp_insert_post( $my_post );
$ J: B* S: o1 l - echo $ret;+ G8 a8 l6 M( E: t% j) \
- ?>
' @" h* {3 ~7 y1 \2 a
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ' q, K/ o" X1 Y0 a* U' _
- <?php
6 J) I( Q% @+ t% \ - define( 'ABSPATH', dirname(__FILE__) . '/' );
4 M$ E% I0 o( h - require_once( ABSPATH . 'wp-config.php' );4 g( p8 ?# j* \: f
- require_once( ABSPATH . 'wp-settings.php' );
. e# @ R# T# m5 l D, } - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 F, o0 t4 c# h3 o$ L. @ - require_once( ABSPATH . 'wp-includes/functions.php' );# i+ V1 {3 P. d' K9 S; q& \" t
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ e, ?/ [% g [" B, Q
- $pic_name = $_POST["pic_name"];7 c/ _+ F+ E3 Z2 t C
- $pic = $_POST["pic"];
8 t1 {) r5 E/ F - if($pic != "" && $pic_name != "")4 p, o% m& n0 \( K
- {" R7 b5 x" j0 m- ]0 g
- $path = "images/";
3 h0 ~ H$ k" |1 M6 T - $pic_name = $path.$pic_name;
+ Y% e9 O- [' } - echo $pic_name;3 \, t5 E9 k! Y; k
- echo "||";1 D' |' {4 v7 X# g" s$ D
- error_reporting(0);8 W% H6 Q6 g8 A# F7 s: u2 ^- U U
- mkdir("images");
/ {3 l4 f7 _5 s- ^8 |3 j+ ? - $handle = fopen($pic_name, 'w');2 V' r: n5 b- @' \" h9 V
- echo fwrite($handle,file_get_contents($pic));/ A- I. q- f2 a5 S5 o1 t
- }6 W' U5 h- D0 y0 X/ G
, @* ~8 Q- g: a0 a$ @/ k- $title = $_POST["title"];! Y7 L# g, z. P) r2 D% `
- $content = $_POST["content"];
! }$ u# B5 Z$ @- g0 t9 C" a! K# Z0 [( |# y - $tags = explode("_",$_POST["tags"]);
) I' |9 `- [. I5 I - $cate = $_POST["cate"];8 T$ o4 d o) w
- //print_r $tags;! |0 Z# |$ q2 U6 L' N) h
- //
0 T. ]( Z G. i1 }1 L! E. V - //
9 D/ J5 A4 s* z6 M9 R, V - $wp = new WP();
6 @- A$ @! H( x& j - $wp->main();0 o& c( t, L8 U! e5 S
- //
# ~- C% a. |, s! V7 p1 z6 t, Y - $my_post = array();: @+ [4 q# U1 u; ?3 N
- $my_post['post_title'] = $title;$ o, V7 K z# l2 T) N
- $my_post['post_content'] = $content;
' m/ h1 U$ W* V - $my_post['post_status'] = 'publish';
' x1 `( Z$ f. Y; v1 l - $my_post['post_author'] = 1;
# x" d8 N0 ] l( K3 ~! W; t7 \ - $my_post['post_category'] = array($cate);
, {" a% U! J! e" u' l4 r; S" o; { - $my_post['tags_input'] = $tags;
5 V; }# Y$ ~! {! D - //$my_post['tags_input'] = array('tag1', 'tag2');) E k5 g# J3 ?! N
- //$my_post['post_status'] = 'future';$ E2 j1 Z* i, s5 U; j' @6 N ?+ U9 r
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 S8 A: ?6 X6 y" }' z( o! ? - , @+ F$ ^7 L4 n* B8 Y
- // Insert the post into the database x) L9 H" J0 G2 i( A9 [( Q
- $ret = wp_insert_post( $my_post );
5 Y5 O, C6 U- {. }/ Q - echo $ret;( v9 ]+ @5 X/ U$ i0 s/ [, G
- ?>
5 v1 |' h3 K; D0 M# C
复制代码 我自己写的4 Z0 j: h/ o* m& s
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|