|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
B5 F: P N+ l7 x
. C+ S5 ~# h3 I: [$ @* E3 s直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( d8 c' d$ |2 T4 ~
' E! Z$ j! Y; P" `$ a我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了" Y. B) O5 C [' L" U% K# q6 d% z7 P
6 S3 C" J- ]* g+ P3 j+ [
方便实用 简单 何乐而不用呢- 4 D4 N7 V, V3 r0 j
- <?php8 _; H j: }# e/ a& |( c" m0 m: k
6 b3 h9 M9 M6 l* o/ Z7 }- define( 'ABSPATH', dirname(__FILE__) . '/' );
; b! u6 M+ N$ u$ N - require_once( ABSPATH . 'wp-config.php' );1 p4 `+ H: @2 h' L0 Z; |5 e2 U7 n6 l' w
- require_once( ABSPATH . 'wp-settings.php' );
+ m: A5 Z" W- M* S9 j& `7 l0 q/ W - require_once( ABSPATH . 'wp-includes/class-wp.php' ); S0 g2 _/ T. Q
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 V3 U: n/ d# ?" m3 g7 @9 C - require_once( ABSPATH . 'wp-includes/plugin.php' );
; ~- l7 Z' V! N. o5 A - $title = $_POST["title"];
4 ~% @5 |7 m% c/ @ - $content = $_POST["content"];
5 ~' ?9 ?) N+ i. `; p - $tags = explode("_",$_POST["tags"]);* _6 h% O/ C& D
- $cate = $_POST["cate"];
g1 G% a/ w3 d! Z3 P3 Q - //print_r $tags;
b8 \8 x$ y) N - //
2 v6 {( |& l" [3 @ - //
0 q7 K( x; u0 e% U - $wp = new WP();9 O1 L) s% }; a" G( Y' [2 @
- $wp->main();1 o3 N& g! U, F0 ~3 l
- //
1 t4 l# }4 D0 q2 S - $my_post = array();( m' J& M+ G8 A* m/ \: j1 c' }6 G
- $my_post['post_title'] = $title;
1 J% g, L& M% s8 Z1 d; o - $my_post['post_content'] = $content;
# L, J5 N( s! W# y' l0 |& j% X1 K - $my_post['post_status'] = 'publish';
4 ^! J$ J# S1 k/ O - $my_post['post_author'] = 1;# a; d4 m8 u5 m2 f& D
- $my_post['post_category'] = array($cate);
) Y2 O* f, p0 b7 ^6 N - $my_post['tags_input'] = $tags;
2 l5 ]0 p8 x, q" }1 g - //$my_post['tags_input'] = array('tag1', 'tag2');
: x3 Y; u* w* L3 T4 b; A - //$my_post['post_status'] = 'future';) f9 j: Z1 T9 N4 u" p! c% \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! k; B; z0 i" `& U
$ f4 m$ m5 [. G6 z7 ~7 r6 G- // Insert the post into the database) i( L. G. }# Y
- $ret = wp_insert_post( $my_post );8 l5 }7 k( K% R
- echo $ret;, ?: O7 \! C( O4 X$ @! \' a
- ?>
% G7 ~4 ^1 T1 x+ ?
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ' G2 O! n0 w) w9 F4 _
- <?php
. i9 v* S, ^# U, K0 q8 m1 h; H$ r6 r - define( 'ABSPATH', dirname(__FILE__) . '/' );; S1 j2 u7 I' L: H& j o* N# c W5 J
- require_once( ABSPATH . 'wp-config.php' );/ ?! g( p* k# F K( Y# Y
- require_once( ABSPATH . 'wp-settings.php' );
4 d8 `9 e0 d5 R - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. k' w/ X* ^9 B& s% f9 |* A- Y- u - require_once( ABSPATH . 'wp-includes/functions.php' );
7 B3 M8 ]. u: G1 H# {4 ?, F4 D/ H - require_once( ABSPATH . 'wp-includes/plugin.php' );
$ B$ C l" ?5 d. j& F% d - $pic_name = $_POST["pic_name"];# e- O* `3 z9 b+ y4 p
- $pic = $_POST["pic"];1 n- C* n) i/ L
- if($pic != "" && $pic_name != "")2 d, C2 F( ?4 _* p: p' j. e% D% H8 [
- {# W$ Z$ ]) i+ w" U+ j
- $path = "images/";; s& x8 c4 g$ K0 ]! F6 ^3 o U4 ^
- $pic_name = $path.$pic_name;8 F: }" D. b' b2 C: m
- echo $pic_name;
; h4 s- w$ Q/ z6 I - echo "||";- D* G4 S% Q( L# d1 v7 u
- error_reporting(0);, N5 t" a9 F% X+ m
- mkdir("images");
+ u X6 d$ U8 J& Z - $handle = fopen($pic_name, 'w');7 C0 ?# ~' x W6 F
- echo fwrite($handle,file_get_contents($pic));4 i. k' T) K9 z' ]) Z1 u) q
- }4 o& I+ s8 v+ ]# ^, B f# D, w# j% w
: X* t5 L# ^) i2 K: b6 l# }- $title = $_POST["title"];4 e4 g2 q7 ^& |
- $content = $_POST["content"];
" L" L6 ]% i% a. \7 p, j1 J2 w1 t1 F - $tags = explode("_",$_POST["tags"]);
% O0 e1 s% x. {6 J' b" i6 l - $cate = $_POST["cate"];7 s$ Q2 v* C% l3 P# @
- //print_r $tags;
* s7 h+ g% [* h; S# `7 M% x - //+ N0 V. T5 P3 K9 _+ e7 o8 o+ l
- //
' ?/ s# [: F9 E; C6 Q; O8 ~ - $wp = new WP();8 ?: n/ g0 [: k
- $wp->main();
* ?( D% u) l' ]) j. O; R - //% J0 Q6 o) I+ }7 M
- $my_post = array();
& [6 A! G! \& Y: \" |) W# z1 g - $my_post['post_title'] = $title;5 E+ W5 y X1 w; p* v4 i4 ]$ s" m
- $my_post['post_content'] = $content;2 R. G+ b- U6 V& G
- $my_post['post_status'] = 'publish';
3 E: `, x6 V5 y* `8 B9 n" B4 g - $my_post['post_author'] = 1;+ ]2 \3 h, [$ P* O( V4 A5 L) Q
- $my_post['post_category'] = array($cate);
4 P, p! A. J6 s. W - $my_post['tags_input'] = $tags;5 U" U G8 B% i# s h
- //$my_post['tags_input'] = array('tag1', 'tag2');8 ^/ I+ z6 B6 c+ ^4 z
- //$my_post['post_status'] = 'future';
" [- O/ N9 z. S1 ~5 g; j% ?2 p - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. D, N* C, I* ]
3 I/ }* ^" ^$ |. W1 r- // Insert the post into the database
" x/ Z. n( M; E9 k8 D; t - $ret = wp_insert_post( $my_post );2 [( j6 N* t* F8 X/ g0 E/ E0 L, M
- echo $ret;
$ `# G5 g9 ?+ u- I" C8 s9 d1 z - ?>
. W$ e6 [! b1 y: M. H
复制代码 我自己写的 ~/ }9 E$ o( c, D
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|