|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " w0 b0 `5 d$ {
# W' H, t; D6 q1 W% C$ E
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% I+ C# X/ h5 E+ T, k
" d+ ~9 a, c1 Y0 e# b' O我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 C% m6 _- [3 @4 z8 e& D- l
, p9 Y. g% \, I- c4 ~$ T X3 _. q
方便实用 简单 何乐而不用呢
. _+ _+ c1 z; ?4 V6 T5 C- <?php0 Z" w* y9 B8 c1 P) ]: w
- / Y7 f( K" _9 Z! y) H2 F" P" W
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 j. q' i, j p2 R( \& ?
- require_once( ABSPATH . 'wp-config.php' );# I; I! F9 B$ s
- require_once( ABSPATH . 'wp-settings.php' );* e1 _' C6 ]- d, \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
' J% W% d+ t+ l* q4 Z) M; @ - require_once( ABSPATH . 'wp-includes/functions.php' );
: o! f5 y @* \+ q) A# K! Q - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 {2 {4 @0 v8 G# v/ p1 ] - $title = $_POST["title"];
0 R; O1 ~7 @; n7 {3 k - $content = $_POST["content"];3 m8 s2 U9 c* {, i, z K
- $tags = explode("_",$_POST["tags"]);
" K! V: o7 k( u7 M: e# z, `* @0 } - $cate = $_POST["cate"];
* F1 v+ ~- u4 d+ c4 x2 E - //print_r $tags;- A& v" u$ D( u4 ~, d
- //
4 r5 h, _, L! Y$ \& A$ J, u6 O+ O - //( E5 r% N( p; g
- $wp = new WP();
& \3 f( v g& b+ B+ X7 ` - $wp->main();
) [5 W; x0 L* y2 N/ p - //
) R: I$ e0 L# z, r/ ` - $my_post = array();
6 S2 B: [ P+ I3 r& t$ | - $my_post['post_title'] = $title;
) }1 Y3 c% I& r) E5 Y - $my_post['post_content'] = $content;9 D2 t" Q: {) H
- $my_post['post_status'] = 'publish';
* A% T0 B# Q) V& z. V - $my_post['post_author'] = 1;, {# @% d, t( l# Q, O( L
- $my_post['post_category'] = array($cate);4 }0 `$ B: i& A! Y) P
- $my_post['tags_input'] = $tags;
5 X! H" X/ o& ~ - //$my_post['tags_input'] = array('tag1', 'tag2');1 k9 c5 C0 s; P. q L
- //$my_post['post_status'] = 'future';
0 b8 Q+ N6 }; L; u9 {# C2 G/ [" U. P6 T r - ////$my_post['post_date'] = '2010-07-04 16:20:03';( U: V1 N+ R9 V0 g# \' G# B0 }
1 c9 ?; k( t2 Q+ R! m _- // Insert the post into the database3 \& D5 k7 X5 Y9 Z5 o: g
- $ret = wp_insert_post( $my_post );1 \9 Z# [1 W8 c {1 Z3 _
- echo $ret;
( j2 j9 b# a2 h1 H! r0 j - ?>- D& ?/ Z; n6 I, p+ t! C- x; N
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! n. Y! ~: E4 X k9 Z- <?php
; z- R; E$ g- t! \; Y - define( 'ABSPATH', dirname(__FILE__) . '/' );! d4 \. U- V" W9 R2 ]) J
- require_once( ABSPATH . 'wp-config.php' );
+ y- G+ J6 p! y( e: t* J+ V - require_once( ABSPATH . 'wp-settings.php' );# X8 N. ]- v. T6 z% M$ Y( t
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 `$ |1 \3 ^. F( l5 T1 b
- require_once( ABSPATH . 'wp-includes/functions.php' );
5 y: z. j9 m( l- w) B - require_once( ABSPATH . 'wp-includes/plugin.php' );2 [1 F5 _# s8 U3 e
- $pic_name = $_POST["pic_name"];
# c& x/ C' M0 k - $pic = $_POST["pic"];
3 ~4 \# {7 ~& T1 { - if($pic != "" && $pic_name != "")% ], t, i9 O3 W" }/ _
- {
9 i, A0 U8 r* |0 `0 W - $path = "images/";
2 P, T! K6 w, d5 c1 j: O# L; \ - $pic_name = $path.$pic_name;+ q% a: T/ s8 K$ Y c
- echo $pic_name;
/ W( J8 L r4 ]: H, x - echo "||";
7 K$ G) {, P/ f* O7 v6 @# w - error_reporting(0);
* ~2 t0 ^. X- p3 ?7 l+ H, ^- n( k7 f - mkdir("images");& c1 T2 ?; ^# j$ j. d
- $handle = fopen($pic_name, 'w'); B0 J- e: R/ I
- echo fwrite($handle,file_get_contents($pic));
5 I1 h! t6 n: `7 p" e9 \; ] - }
' v T/ R5 w( d0 ^; {. t
/ `8 f1 D* {2 H% ?+ u- $title = $_POST["title"];
2 v1 [8 C. P+ I) L% K2 i) F - $content = $_POST["content"];9 I: _1 `* }& }% A j, @9 k
- $tags = explode("_",$_POST["tags"]);0 w8 v$ q5 ^: h4 q8 m
- $cate = $_POST["cate"];
5 L% ^/ m6 F) | n5 Y5 C - //print_r $tags;
, z T$ t* Q4 A, e - //
- N$ J; P" e- D$ d& O$ A. a0 C - //
% N9 N) R8 C3 @ - $wp = new WP();
I; W1 I4 w ]# v" w% e - $wp->main();5 {# d6 k( C( R \( U5 x
- //
2 ?1 ?3 r: @8 Y/ v$ E; w% E& w - $my_post = array();
$ |, o& p) d- x7 S* L/ E- B# B - $my_post['post_title'] = $title;
9 ?# I; Y. l& |3 W/ W0 C- } - $my_post['post_content'] = $content;3 T1 y* |" u& q; h% ?
- $my_post['post_status'] = 'publish';
, P0 C. _/ V5 b s- l/ p" B - $my_post['post_author'] = 1;
$ A% K; }/ G+ k/ `$ n - $my_post['post_category'] = array($cate);
J3 ^& K) w3 Z - $my_post['tags_input'] = $tags;% G0 W% h9 M, w% o D! V+ C; I
- //$my_post['tags_input'] = array('tag1', 'tag2');
# B6 q8 u8 W" _ - //$my_post['post_status'] = 'future';( { I8 N) Z2 u, T" N L, o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 W1 K5 n$ j0 c& b O+ ~6 |/ d+ n - ' G$ R# Y8 ~. r3 E4 ^8 g+ ^2 y
- // Insert the post into the database
' n9 \8 d& o+ j+ s0 x# Y/ T - $ret = wp_insert_post( $my_post );( O$ A) Q) h6 m* b+ Y
- echo $ret;
0 r/ }- ~/ H) G2 G' r4 [# _( b - ?>0 E! `; A! P' k; V
复制代码 我自己写的' B/ H! ~3 b0 Y# ~) N# F# p
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|