|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 9 [4 e& N# v8 p' G( a1 M
& I' n: Q$ k. I1 X" O4 q% X
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, h& Y" ^ f% n: T* E# M( C3 P& u0 s. k2 K; [5 C
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了! L* B4 q2 q* f1 t
, N1 R A& ?4 k! b3 z5 H7 u方便实用 简单 何乐而不用呢- ; A3 q( n4 O, Z) o" k
- <?php
. X( i' b2 x* q+ L( B - 0 h8 [' Q% M6 R0 K# }7 K
- define( 'ABSPATH', dirname(__FILE__) . '/' );5 \. s; E3 k6 r$ z- L
- require_once( ABSPATH . 'wp-config.php' );
# H2 H6 @9 z- [ - require_once( ABSPATH . 'wp-settings.php' );1 [! o$ O5 j* [; e
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ I7 z- Z! p0 c6 K' M% O' r* U
- require_once( ABSPATH . 'wp-includes/functions.php' );9 [: ?3 R! @3 r3 r* j* ^7 B
- require_once( ABSPATH . 'wp-includes/plugin.php' );1 R' t9 q; ]& a% ?# `
- $title = $_POST["title"];
" u: a$ r. d) u - $content = $_POST["content"];
' n& w0 G$ x; q5 c/ k2 S - $tags = explode("_",$_POST["tags"]);
# Z# w* w5 a8 b# o4 h - $cate = $_POST["cate"];
; p; D1 b: K) L( k - //print_r $tags;
5 G% Q6 O$ t( @; A- x - //2 ]! T( o+ V! B& x7 u+ C2 A- @0 a0 K( j! T
- //6 n) ^% B4 Y N/ x M
- $wp = new WP();, f% Y0 H# g9 _. J7 H
- $wp->main();; Y# F- p4 i) i6 W- `9 L; Z
- //% e% z4 m& _3 E
- $my_post = array();
5 A: [) X6 T- b - $my_post['post_title'] = $title;+ X- l* q! g9 c4 u5 t
- $my_post['post_content'] = $content;
9 c5 k T/ D* [ - $my_post['post_status'] = 'publish';) t/ s# Q3 C8 a! C
- $my_post['post_author'] = 1;
* Y% u- @. y% }, s - $my_post['post_category'] = array($cate);
- H6 j8 v8 K! P. b/ Z$ D - $my_post['tags_input'] = $tags;
4 h. z* ]+ b7 F9 C6 M& q+ n* q - //$my_post['tags_input'] = array('tag1', 'tag2');
) d! `. v* p7 ]/ k& c& A1 C+ c - //$my_post['post_status'] = 'future';
# Z, j; j) d- h - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 g' f8 i* {8 O( p - $ u: e- M! b$ H j! f) B2 N
- // Insert the post into the database. O- G* u0 P7 r# H- u; u! ~$ s
- $ret = wp_insert_post( $my_post );
P5 u; I9 _+ e8 u W - echo $ret;) o) w" E6 X; r$ s
- ?># B. G7 T2 } E5 U5 ?7 T, A' ]; l, F
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- F8 A' a7 K' g( V1 E- <?php/ ?5 r0 I, P, Q1 j( A& W# i4 \( Q
- define( 'ABSPATH', dirname(__FILE__) . '/' );9 x* t5 i& w% E. }9 ^: i
- require_once( ABSPATH . 'wp-config.php' );
f- b5 M$ ?: [% _) D - require_once( ABSPATH . 'wp-settings.php' );6 @1 @( }' ~6 o; e) s
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 q1 v4 b2 ^' c2 [; Z# {: n& \
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ l" f, Q$ g! h, j# r9 d - require_once( ABSPATH . 'wp-includes/plugin.php' );
9 e/ N( \/ u9 K( F4 X - $pic_name = $_POST["pic_name"];
) d, F# W9 Z$ `, E5 e2 K - $pic = $_POST["pic"];) {# _3 K7 s; E; ~. y
- if($pic != "" && $pic_name != "")
4 q" u5 E9 h" W8 k3 l, j# H7 m - {
% M, j. b* i' u - $path = "images/";
* n- c# W# |% e9 \3 c/ u2 ~ - $pic_name = $path.$pic_name;) B7 [; f# ?' O2 ?% d" m8 L" Z
- echo $pic_name;+ E9 H9 E. |$ |' v
- echo "||";
; b8 h, k" s1 T. K" u - error_reporting(0);- j% U: C: x* d ?
- mkdir("images");
# Z1 j& q- h; H: W7 [. Q - $handle = fopen($pic_name, 'w');$ w8 N( J: T7 I9 I3 a
- echo fwrite($handle,file_get_contents($pic));6 W4 ?6 E: g4 G$ t) a" x% p
- }( W! o, R) M) X
# g- d6 ~* \' V) ]8 R. Z- $title = $_POST["title"];
1 Y- S5 A7 |4 n0 Q W7 O2 D - $content = $_POST["content"];, [! d( F N; V, o
- $tags = explode("_",$_POST["tags"]);" Y' e) P, N3 O, I/ n( I0 d, S
- $cate = $_POST["cate"];. h' |2 K4 c+ t
- //print_r $tags;& ~3 s9 {! l+ r+ D: E# \; e
- //
+ c0 @7 w- m6 z" l - //
a' {! x- m* _/ N3 b( X9 c; L1 M - $wp = new WP();
, j& a7 o: [. ]0 Q( L, R3 o - $wp->main();
* i! J F3 l7 K$ b - //
- Z9 D& {5 u- z0 V3 x6 u# q. w+ f - $my_post = array();
7 c. U r: n' w' O1 f - $my_post['post_title'] = $title;
- }+ M# f! q. [+ }# q. K3 ` - $my_post['post_content'] = $content;! M+ w' G5 t9 W. h- \9 r
- $my_post['post_status'] = 'publish';$ l/ G" O. z! Q A5 {- I" f" @
- $my_post['post_author'] = 1;
6 g0 ~1 J+ G' j1 { - $my_post['post_category'] = array($cate);8 P6 Q" M8 Q% U1 L3 j
- $my_post['tags_input'] = $tags;
( o8 w2 D2 [3 L5 r - //$my_post['tags_input'] = array('tag1', 'tag2');9 v2 _7 a6 T3 i% L! f9 T" |9 z
- //$my_post['post_status'] = 'future';$ T0 R) t. E4 ^5 o! X! N
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, t4 ^8 D2 \# I- K* K( u" E: @- W - * a' [& M) |) [: y5 v9 n5 R
- // Insert the post into the database
1 k2 g+ f2 ]( V - $ret = wp_insert_post( $my_post );
0 K5 Y3 K( P5 ]4 ?; f - echo $ret;
6 T) l4 n7 u% f* b& s - ?>
' s$ H3 s- N3 E
复制代码 我自己写的3 M6 ]1 A: T9 K9 F# C
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|