|
本帖最后由 finder 于 2014-12-28 15:13 编辑 % ?8 ^3 n% b+ [, w
- c% O# i! F& _6 y- w
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ d2 D, O7 T# x' r. [) e7 B4 I0 c7 _: D5 q# X* t# O
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ c) K, ?( e% ]" [! ^* L0 g" _% S; @: J/ M2 F+ h
方便实用 简单 何乐而不用呢
. m4 ]$ V! A" x) T* M8 u! D- <?php' `2 c ^, g# }6 L3 O
4 P! E6 r9 A. ?( V7 Z( L$ L ?5 v/ B- define( 'ABSPATH', dirname(__FILE__) . '/' );( N8 M1 Y2 E; c
- require_once( ABSPATH . 'wp-config.php' );
+ U, Z/ T; ]- c- T; H) ~2 n - require_once( ABSPATH . 'wp-settings.php' );* U3 s+ c& H$ o8 [1 P+ @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 D* j2 H# x( B; {" V. l/ k - require_once( ABSPATH . 'wp-includes/functions.php' );& [( r8 L+ |- b% w' n; K. y$ l
- require_once( ABSPATH . 'wp-includes/plugin.php' );7 e5 e7 _/ Z! Z k6 ~% d
- $title = $_POST["title"];( H5 S5 [: i! p7 K
- $content = $_POST["content"];0 l. A& c0 `1 }% k* l; D1 g
- $tags = explode("_",$_POST["tags"]);8 w# U. r( o. R4 @; L+ ?
- $cate = $_POST["cate"];
, O/ K: ^1 S% X7 \- p - //print_r $tags;8 T$ L9 f: c! z' o4 y6 f3 V: i1 }8 {* M
- //
5 w% t, o5 o8 M# J. H K m - //1 V% o8 R# e5 w! `* X; s, ?
- $wp = new WP();' o6 l1 P. `( e; e- b4 Q, p2 \2 ?
- $wp->main();
) |" M% S$ d9 ]# t4 a - //6 ]4 r2 A& A0 f+ \" p- H
- $my_post = array();
3 a5 x; r m8 \& U1 {' a3 r1 U m - $my_post['post_title'] = $title;4 e& c4 j6 ?# o" I
- $my_post['post_content'] = $content;
1 N) P6 E6 Y8 p# d. l# Y - $my_post['post_status'] = 'publish';2 M( l9 L: z w; W* Z) e3 n
- $my_post['post_author'] = 1;' s# c% a6 f) D2 A# z
- $my_post['post_category'] = array($cate);
$ Y! V$ i: e/ g - $my_post['tags_input'] = $tags;
* X& p- m \* y7 K5 o2 u - //$my_post['tags_input'] = array('tag1', 'tag2');1 L. P5 H C! z3 j
- //$my_post['post_status'] = 'future';" K! K+ B" D- _! C _, S
- ////$my_post['post_date'] = '2010-07-04 16:20:03';) N3 D3 e1 \ |2 C( b# `
- ( T {5 I% y' r* Y2 \3 t8 G% z W
- // Insert the post into the database, ~$ Q0 [8 @: ]9 O9 R* l: _# ^
- $ret = wp_insert_post( $my_post );
6 H4 f+ s2 T) ^* c8 h7 ]0 F9 w - echo $ret;; T6 ?' {% g( l* @% O( p
- ?>, y/ _1 x2 X& J2 m9 R; I
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 }9 }- D2 }2 P9 R; P3 J- <?php
9 h# e, m% C. w% P - define( 'ABSPATH', dirname(__FILE__) . '/' );
j% @: u# }0 _2 r- `% A5 b2 t - require_once( ABSPATH . 'wp-config.php' );
9 q' i7 w, @ H2 `$ l$ H - require_once( ABSPATH . 'wp-settings.php' );' G# s7 |- q; v# E; }
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 K+ Y4 U. N! [. K# F
- require_once( ABSPATH . 'wp-includes/functions.php' );
" @: d- [: m" s0 u, D8 w4 e - require_once( ABSPATH . 'wp-includes/plugin.php' );
) G$ j3 W/ @! P# F, ~( u3 m6 w1 A - $pic_name = $_POST["pic_name"];
& ~2 M6 o: R5 ~ - $pic = $_POST["pic"]; r( I% v' ? ]' U: b. d
- if($pic != "" && $pic_name != "")
$ u) M y* n& j" _1 A8 z$ Y - {
! g$ b% A& P( P+ F2 E8 B( w' G" J - $path = "images/";
4 H9 Y: v- I5 n3 W5 ^% @+ a6 i* k, a - $pic_name = $path.$pic_name;7 T# \6 c7 u+ C6 L$ p' b
- echo $pic_name;
, a: H5 V6 a$ R& w4 X0 |, b- t# ? - echo "||";
4 R- T% r. ?4 }1 i9 J' c - error_reporting(0);) n- J$ z4 a3 Y1 O9 e; Y) y
- mkdir("images");
6 B5 G Q1 F: |% W - $handle = fopen($pic_name, 'w');
! b0 w# b, d* a/ j' x- c+ Q - echo fwrite($handle,file_get_contents($pic));
. y% g+ ?5 S1 ~ - }
, @$ F1 B4 k6 q7 K( w" ? - % P% E/ O/ g3 { W3 M! C* ^8 H
- $title = $_POST["title"];( L/ Q& U1 Q* n5 x
- $content = $_POST["content"];+ \$ K/ ?% K4 T1 a. L1 m! Y8 ^
- $tags = explode("_",$_POST["tags"]);6 \# R- F ^: q6 e/ R; W) n
- $cate = $_POST["cate"];6 Q2 i9 }, N8 o( ?, e5 n* N, D
- //print_r $tags;
2 ]+ G* a7 q' \. I( V - //
: S- v+ @. Y2 {( r - //" l% S5 h3 s) @
- $wp = new WP();$ D1 S( a1 j3 p# ?' W" E U$ _
- $wp->main();
7 I% r# J# t/ D3 N4 P: ?' O2 e' D: K - //$ N8 L5 D2 v% p
- $my_post = array();# I Q1 z, i( i
- $my_post['post_title'] = $title;1 E* ?( [) Z/ X5 h* h, h$ N, S* F
- $my_post['post_content'] = $content;
' p1 D% b; h p- E- D3 S7 Z - $my_post['post_status'] = 'publish';
% l- t. P* d2 F/ w Z: K - $my_post['post_author'] = 1;
' i$ ]) h% a# P6 \! c7 H. T - $my_post['post_category'] = array($cate);* h/ ^; b. A+ r5 }' q- A
- $my_post['tags_input'] = $tags;3 x% h. B6 d; e) H4 C0 z
- //$my_post['tags_input'] = array('tag1', 'tag2');
5 [; R3 C7 z |1 u) n+ G. E* ? - //$my_post['post_status'] = 'future';& E5 F6 O" r0 y) l5 \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';3 h: h' c0 h' u/ m9 R
- & O! r; g; E( y
- // Insert the post into the database
9 h7 C+ ^$ u( P( F - $ret = wp_insert_post( $my_post );
9 }1 F: n( r1 _3 ] - echo $ret;
3 Z8 {8 R. z0 A. Q; d5 s! m5 R - ?>
* l/ P7 B2 o2 F+ k ~
复制代码 我自己写的
" K7 W/ n$ f* [1 K4 t# ^ M" p插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|