|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 + Y+ T, ^) `$ T0 y
1 A/ `, W9 b) C8 y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持/ B8 x# }9 F" @8 @# a
% D( F2 v+ I) p2 e- u* T0 ?6 M* K2 v我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
- O9 Z1 i/ j/ ]; t4 R N; B# |; m
) h- q4 y' U! `4 D. j! Y方便实用 简单 何乐而不用呢
& _0 g8 |) \8 l: H) q" e B- <?php
/ {# q z( G+ v - & q7 ^+ Q; {" |2 f% `. l
- define( 'ABSPATH', dirname(__FILE__) . '/' );! A2 e3 v/ o( {& A; A5 ~! p
- require_once( ABSPATH . 'wp-config.php' );
6 {% q7 v/ M3 d2 c$ s! a - require_once( ABSPATH . 'wp-settings.php' );+ b* M' f6 f! w; k+ n, \* K; p
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 I2 o4 ]2 ~# \# ^# G - require_once( ABSPATH . 'wp-includes/functions.php' );2 o F& i* a+ Q; F' @( |
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: g, h3 d% }/ t/ y# F1 A - $title = $_POST["title"];1 l7 W- y+ p4 c; d% A3 r
- $content = $_POST["content"];7 H' r# e0 [, P9 o3 X# }0 Q
- $tags = explode("_",$_POST["tags"]);
/ s' d" J" t8 O% V. `1 l - $cate = $_POST["cate"];
Q8 z# H( D$ f% ]% \6 T; F - //print_r $tags;
6 h8 y' X# B; ?( P" F- d - //
3 Y: I* e5 P5 a% C; _$ L& Q! C5 D - //
: C! p- g( j4 L - $wp = new WP();3 j% G- n6 G5 l5 T8 W
- $wp->main();
: [. P" K8 ^5 {8 y [" w3 Q/ n - //
2 e* ]/ |* E) F" g3 o- t - $my_post = array();
. E: c% C6 }$ F* g6 Z - $my_post['post_title'] = $title;
5 R4 q! P2 e3 y$ V - $my_post['post_content'] = $content;& d. m8 ]6 C* T# |+ Q9 b( K
- $my_post['post_status'] = 'publish';
, D( M) J9 q2 z" A - $my_post['post_author'] = 1;
3 z, E! f8 \& r' f( H/ z m - $my_post['post_category'] = array($cate);
' }0 a$ V. t8 t% F - $my_post['tags_input'] = $tags;9 |# O0 ^& f; _9 \
- //$my_post['tags_input'] = array('tag1', 'tag2');& V; N. p' p, r% s% T% t
- //$my_post['post_status'] = 'future';" `$ i2 A) N0 r
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 X7 l! B& \$ ]9 u* _* M - 0 R3 ?$ k, J8 z; e; ^/ U7 S( H
- // Insert the post into the database
: c4 a* h8 O$ N! o+ r2 l- g. H - $ret = wp_insert_post( $my_post );/ O8 @; [, o/ w/ c3 M6 U
- echo $ret;
& c! u% ?6 F9 m4 b - ?>1 j a0 ]5 F2 ]& S7 ?9 l% J7 v- [
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 6 ^; y. u; ]6 F' N% t' n
- <?php! z) N8 C- u3 d; G
- define( 'ABSPATH', dirname(__FILE__) . '/' );) S& d) J& h4 D8 H2 `: M! |
- require_once( ABSPATH . 'wp-config.php' );, h, K, {' z4 }
- require_once( ABSPATH . 'wp-settings.php' );
1 o. f' Z4 d+ I - require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 u% i' ~. A m9 Z1 ~3 J- s - require_once( ABSPATH . 'wp-includes/functions.php' );3 _" s* u) k A/ S6 i
- require_once( ABSPATH . 'wp-includes/plugin.php' );
4 e/ O- p, v; y! P - $pic_name = $_POST["pic_name"];
5 n2 r' A H; ~; h8 D& k1 W( ?1 ? - $pic = $_POST["pic"];
5 f& a5 V- I5 d* f - if($pic != "" && $pic_name != ""). _$ ?' w& I; h/ G! \
- {
! Q: G2 x4 l3 J% V - $path = "images/";
. F) Q& \0 M6 R3 u& F0 ^ - $pic_name = $path.$pic_name;
5 ^' N! I& z- Q0 h$ Q( g) `5 I - echo $pic_name;
4 @7 I" Z% O9 N - echo "||";
7 [" E8 V6 C9 x: J - error_reporting(0);
/ x/ m K8 @5 c! g& m0 Z% q* `3 C - mkdir("images");
- R; {5 ^% o. q2 x, i6 p - $handle = fopen($pic_name, 'w');1 F/ g& n0 t6 o
- echo fwrite($handle,file_get_contents($pic));, ]$ h1 P/ X7 j: }
- }9 F, K- [4 v) I+ \6 ^" Q1 p, y
3 S; G4 ~1 o8 O) w& [: @! Y* J- $title = $_POST["title"];
+ ^: V( j5 |/ ?8 N* Y3 |0 r; Q - $content = $_POST["content"];
. E; L' I' t6 O C' X - $tags = explode("_",$_POST["tags"]);! o# {' l1 [6 |
- $cate = $_POST["cate"];
. O1 i' R* y4 B* n9 J. u1 c/ T - //print_r $tags; i4 Z6 f( w, D# p/ \& w
- //
/ v% b: b) U# a1 {! s - //$ m4 b$ @3 L' `. ]6 j' e
- $wp = new WP();
* F. X! U# }' P6 A' Z - $wp->main();
u, {% t& |* X7 ^" t1 {3 P" |! a - //8 U( ^& I$ |5 ~* D5 C
- $my_post = array();" A5 s% i) x/ g, D1 B" O0 A
- $my_post['post_title'] = $title;
* ~4 R5 o* |1 z8 M - $my_post['post_content'] = $content;
" Y5 X* Z% G' z% v" e - $my_post['post_status'] = 'publish';
: t0 ?" i$ |. e/ J2 @8 g! b) Y8 ] - $my_post['post_author'] = 1;0 u" z1 h# ~1 G" ]/ |
- $my_post['post_category'] = array($cate);* {; f: ?+ p" x9 z' ]$ s
- $my_post['tags_input'] = $tags;( H+ ^( N5 A8 o- t' u7 Y, l
- //$my_post['tags_input'] = array('tag1', 'tag2');
/ G C+ ^0 o+ q# M: M# Q% D2 i3 H - //$my_post['post_status'] = 'future';
) K2 U1 D d- i! `: b" d! G5 ^9 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 D" x1 c, l4 t3 ^+ M( |
- ( z8 h: T1 s% U4 k* P* ]
- // Insert the post into the database
* ?2 h+ A2 j( q: x8 Z3 Q& S" @% T - $ret = wp_insert_post( $my_post );
( W2 M1 g: {4 D - echo $ret;* P2 s: O# _* v8 v/ K2 z
- ?>6 C5 |2 u+ V5 H$ _( D
复制代码 我自己写的
( m3 q3 y/ w" J* }6 `" Z插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|