|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 e! Y5 p! ]7 u9 @! p, T2 L" e H) N/ _" z" V
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 L8 n3 C9 u$ H4 l& y
9 g- `+ b" k8 O& e我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ K: g% J; c" s% S5 q8 ~! ]# k% K/ G7 }% t& y+ G5 u' |* V
方便实用 简单 何乐而不用呢
+ K2 h0 U. R$ p: e \& P- <?php
6 a+ D+ I1 P# y. d3 { - 0 Z. w" O. ]' a5 M* g9 n" l/ Q) D
- define( 'ABSPATH', dirname(__FILE__) . '/' );" p& U( s1 z4 w3 l9 `
- require_once( ABSPATH . 'wp-config.php' );
3 _- L7 K+ u/ {* T; P0 a; B - require_once( ABSPATH . 'wp-settings.php' );
5 N: I- z5 r5 b- n - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 n. l7 [- T8 f* R* u% F$ w
- require_once( ABSPATH . 'wp-includes/functions.php' );% o' N& [' a2 d" y* F
- require_once( ABSPATH . 'wp-includes/plugin.php' );7 a, u/ h( i1 m6 g* M) t
- $title = $_POST["title"];
5 b8 d0 P# }' a; R) D8 D+ r4 e* W$ ?+ g - $content = $_POST["content"];* \7 q& ^3 k: ]& B5 A- ~, F
- $tags = explode("_",$_POST["tags"]); B) H+ { P7 }- x' d
- $cate = $_POST["cate"];0 J- L& G& b% v7 K/ a: ?
- //print_r $tags;4 J+ t( M$ [% U6 V$ t( k9 j+ Y) H
- //5 p: k/ r" t/ _% d. f+ q1 S. B
- //
$ \: N" g2 b% r2 W; F - $wp = new WP();
; H" J3 C; \6 Q7 o) v - $wp->main();3 B5 [/ E/ D. u5 O
- //
7 h7 X$ K2 D. V& ]6 P1 T - $my_post = array();
/ J( S6 W& k; I/ p - $my_post['post_title'] = $title;
8 e; B* ?6 r4 p+ w; p2 n - $my_post['post_content'] = $content;8 W1 ~# A8 |; p8 b
- $my_post['post_status'] = 'publish';
* R4 j d+ R( A8 P% m - $my_post['post_author'] = 1;0 G, I4 h3 |0 j9 \
- $my_post['post_category'] = array($cate); _2 `! ]0 b) g+ Z
- $my_post['tags_input'] = $tags;
4 v1 d4 A4 T; |+ Q$ W# \2 n - //$my_post['tags_input'] = array('tag1', 'tag2');
7 u% f7 u& v0 U! { - //$my_post['post_status'] = 'future';
: b' z/ j6 V( a2 j( _ - ////$my_post['post_date'] = '2010-07-04 16:20:03';# J* ?8 m. B0 P6 C% B3 E# U
- T* X3 }) I8 t+ ~
- // Insert the post into the database
( Q' G4 v; Z1 m6 m3 _ - $ret = wp_insert_post( $my_post );
$ y0 T+ i6 i" L. F4 V - echo $ret;( F& D! `% n8 G' r3 p) p0 y$ k
- ?>
0 c: s! {2 H# }/ g9 w! Z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" e, @, i: h% o$ r) _4 G+ r- <?php; c: E1 b9 p" A+ W
- define( 'ABSPATH', dirname(__FILE__) . '/' );. ^! Y% W# n- U% u
- require_once( ABSPATH . 'wp-config.php' );
. A% Q1 t# ]* f3 V- Y* c - require_once( ABSPATH . 'wp-settings.php' );
, a' b) F( M, ]% N* c1 }# f% T& n - require_once( ABSPATH . 'wp-includes/class-wp.php' );
# ~5 b0 Z& Y7 J, _$ ^" g: q - require_once( ABSPATH . 'wp-includes/functions.php' );
8 ^" r/ S. M" C; p3 G5 k - require_once( ABSPATH . 'wp-includes/plugin.php' );
- x. d5 a* T; {8 P: z8 T: j - $pic_name = $_POST["pic_name"];# O$ Q0 E# a" h1 r' f8 \
- $pic = $_POST["pic"];8 N" m @2 j2 A( H8 e6 o+ b
- if($pic != "" && $pic_name != "")
0 F# U, Z3 L6 T1 F6 n8 g - {
' o% c' J' ]) G4 g! d. z - $path = "images/";: a ^6 q( x1 v* F, ?1 j
- $pic_name = $path.$pic_name;. e9 m- y& D% }
- echo $pic_name;8 ?/ i Q9 s7 _1 j
- echo "||";. w5 h3 J8 R7 R( m: T8 _
- error_reporting(0);4 b( c* A$ a3 Q. I- `& j C
- mkdir("images");
7 r6 I+ k% k6 A/ c- G+ D9 Q. ^ - $handle = fopen($pic_name, 'w');
2 V+ V9 H% R6 g. H }, s - echo fwrite($handle,file_get_contents($pic));/ T' O* e9 ]2 P7 S8 U( ~% {& B
- }
: S+ P9 U) Z$ P2 F9 i
) ^- L+ E, |$ t9 A- $title = $_POST["title"];# |6 G3 \. X' R0 h, x! m6 V
- $content = $_POST["content"];
5 b, k. s7 l& r0 v - $tags = explode("_",$_POST["tags"]);6 N- a# v5 D4 U+ Q
- $cate = $_POST["cate"];
9 C! i) R& a. Q$ n" v" F - //print_r $tags;
6 r' e9 @* W D- e+ k: @ - //, M7 M& O# Z( e4 p6 V
- //
" j9 t' c% l. V7 f - $wp = new WP();
1 T/ x& Y0 z0 {4 Q - $wp->main();
" ]; Z) ^; g+ [2 \; E - //
1 X, [' T/ p* `$ z, r( C - $my_post = array();
8 M8 s/ T* }; C& { - $my_post['post_title'] = $title;/ E- b9 t# N9 }3 D
- $my_post['post_content'] = $content;
# \' f5 n4 @" |$ ?% z1 m0 V% Z - $my_post['post_status'] = 'publish';( U/ C7 f. U+ I9 \' a2 X
- $my_post['post_author'] = 1;
! ^: W: _. i! O9 I+ N1 X - $my_post['post_category'] = array($cate);
& q( ?8 ` ?+ N - $my_post['tags_input'] = $tags;5 F4 i$ e3 h r, @/ V% ]% K
- //$my_post['tags_input'] = array('tag1', 'tag2');
' m r$ a( p/ | - //$my_post['post_status'] = 'future'; N7 E8 w$ n: F$ ]% G( g6 r
- ////$my_post['post_date'] = '2010-07-04 16:20:03';/ ~* X& U6 I$ ?( v5 X/ {
- 8 \2 B3 p, Z! m$ C, ?9 q$ L4 B7 r
- // Insert the post into the database! k8 ?$ h5 G- O% ~
- $ret = wp_insert_post( $my_post );
2 m1 A( M# P' u5 [# U. w7 F - echo $ret;
5 C( U7 u' B C$ A# M5 A, T9 r - ?>
8 c- |# r H9 u
复制代码 我自己写的
9 g, u# r8 B. g插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|