|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- B. E2 U7 c3 g9 s
' q' y. `: ^7 t1 [* p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. n) f! o: c+ w0 W$ T7 k9 Y8 n( @, w# Q. m5 ^+ E
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
/ e4 {; z0 l8 a; g
X5 e4 K! e1 d, Q1 h6 l4 I方便实用 简单 何乐而不用呢- / ^1 t# d# v5 p, D
- <?php! i" o& |4 k' k! _3 A" I
/ @3 x0 V6 S. H- z0 D- define( 'ABSPATH', dirname(__FILE__) . '/' );
# T% R; Y$ w2 G! c - require_once( ABSPATH . 'wp-config.php' );, @* e# o" a' ]3 }' I6 l
- require_once( ABSPATH . 'wp-settings.php' );
7 I+ X5 ], F( U i - require_once( ABSPATH . 'wp-includes/class-wp.php' );
" D& V& h* O$ \, G/ o; K( y - require_once( ABSPATH . 'wp-includes/functions.php' );
5 d0 ^* O" x- v: l. o3 L - require_once( ABSPATH . 'wp-includes/plugin.php' );
- x4 d/ d+ k" d# [ - $title = $_POST["title"];" B) M' L7 j" Y# p
- $content = $_POST["content"];# T: y5 w( F1 [7 ^
- $tags = explode("_",$_POST["tags"]);9 j+ j: _5 p) |4 |: z
- $cate = $_POST["cate"];
, V9 B) m4 ?1 j8 P; |$ B - //print_r $tags;
7 @4 J# J2 D& k5 S1 T! F9 J - //8 G6 D% W. L4 h. Q% q0 x. f
- //& J h4 }# y/ N; u2 t
- $wp = new WP();
1 _, b2 ?7 r% \6 b - $wp->main();
9 N- s4 M0 r% p. W% d5 A - //
' H/ w! Z5 [# `" r - $my_post = array();( Q9 }3 Q6 m$ }9 `6 B
- $my_post['post_title'] = $title;% O9 `- u# ^0 s; k+ l
- $my_post['post_content'] = $content;3 [# H7 Y1 ?5 I
- $my_post['post_status'] = 'publish';
2 M7 H: B4 u! y d% e8 i3 |5 @* T - $my_post['post_author'] = 1;* \; t' b! u9 ~4 B. i K
- $my_post['post_category'] = array($cate); h# S% D3 p" K% X. |! L3 i& s9 @
- $my_post['tags_input'] = $tags;: w3 K" x2 ], A1 l* s; @- e# ]
- //$my_post['tags_input'] = array('tag1', 'tag2');6 M/ h4 j9 @4 I3 v; G# G( Z
- //$my_post['post_status'] = 'future';! p2 C c% [/ k: J2 {+ J# k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# H; z {* u& }3 N9 [8 c5 z: v
( S. S1 h8 C+ q2 @- // Insert the post into the database5 {+ w: {$ g& y4 C6 E! K2 G% u$ w
- $ret = wp_insert_post( $my_post );: }2 e3 Y+ _. x' |/ x
- echo $ret;
2 L$ q$ M8 Q# u5 w - ?>
7 c1 t- @ @# w" h$ A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- $ R& y2 M, H( W. z
- <?php
, I4 X& T& ~+ V, R3 _ - define( 'ABSPATH', dirname(__FILE__) . '/' );4 X( m! D8 z6 ~- s7 g0 ]; }* H
- require_once( ABSPATH . 'wp-config.php' );
9 M/ T( p T) M6 ^ - require_once( ABSPATH . 'wp-settings.php' ); a7 t& K! F- v3 H( n5 g% `
- require_once( ABSPATH . 'wp-includes/class-wp.php' );/ ?$ C H! d$ p
- require_once( ABSPATH . 'wp-includes/functions.php' );0 ?/ b m) y/ o- E
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 G& k0 G9 g T: o
- $pic_name = $_POST["pic_name"];" Q/ y: W$ M* e1 c y. p( W
- $pic = $_POST["pic"];$ p$ X8 j& H7 d d
- if($pic != "" && $pic_name != "")
! z0 a: I# E4 f' w5 F - {
* l9 i; j9 X2 {5 w) d" e - $path = "images/";
$ h) z. U; W7 B% I - $pic_name = $path.$pic_name;
* k n/ V! f4 d - echo $pic_name;6 V8 |' {& j; j6 r, [" V- `3 g$ E% ]
- echo "||";4 [/ }, c" D$ L3 L
- error_reporting(0);
8 H% G' i9 J, f5 i0 o* A/ m5 L. J - mkdir("images");
6 t! p0 X1 M) D7 @# s - $handle = fopen($pic_name, 'w');5 L- ~, m* ?5 ^, n# ^, A! i5 p( u
- echo fwrite($handle,file_get_contents($pic));
1 G5 N" A: J! {$ d* i( h - }
+ l2 I1 C5 E" I1 W# }! c9 {3 k8 | - 1 f* P9 p+ a& i; j; K
- $title = $_POST["title"];5 U# w( h+ [# Y" ? f- s2 p
- $content = $_POST["content"];
S& x u1 O1 b3 Q - $tags = explode("_",$_POST["tags"]);% G6 [5 e+ J1 p+ j& i) h
- $cate = $_POST["cate"];* ~, k, M* M; c: [
- //print_r $tags;: V1 z- _0 J6 ]5 |* ^# r! n( K8 \5 l3 [8 ]
- //
0 _( U {! _5 ]' H0 I: ` - //
4 n7 r% Z0 E/ _# Z - $wp = new WP();' { `/ t5 R e& R0 R
- $wp->main();
/ C7 |* K5 A3 ~' X4 Y0 Y - //( I9 O4 |5 t; [9 x
- $my_post = array();3 a" U; E: B8 \2 j
- $my_post['post_title'] = $title;
* M2 I: O: @7 N - $my_post['post_content'] = $content;9 f3 W Q5 a) Z/ _
- $my_post['post_status'] = 'publish';
% V4 ?2 p" @0 X# Z$ n - $my_post['post_author'] = 1;
' b8 N$ B6 y1 C/ Z- @" c; B - $my_post['post_category'] = array($cate);6 K* E- O w% A3 o# q% h7 `
- $my_post['tags_input'] = $tags;- i8 _4 I* x5 Y9 b
- //$my_post['tags_input'] = array('tag1', 'tag2');5 O9 S8 b# y l X, }
- //$my_post['post_status'] = 'future';7 G @7 k9 X/ ?4 R4 x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 M, c6 X5 n( g+ ]2 |
+ V; Q1 p _ k& v7 b, M- T& p- // Insert the post into the database4 ?' f3 i/ o: q0 J" D# E8 P
- $ret = wp_insert_post( $my_post );
. ^7 s0 Q* G: E1 p. o3 n) ? - echo $ret;4 i7 U; R% N& P7 ^& D' i7 H# s
- ?>3 O/ s, Q' a! a8 K0 @) h, u
复制代码 我自己写的
# o6 T% L3 A. W- \& P插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|