|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
i4 m, M# Z1 y- u$ t. z' L% ^8 ^. q" P+ V( N
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* ]3 |" G9 S+ z: @2 F
8 \5 ?% u3 `: }8 s我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
* d4 L( \- T# N/ D) ~) o& l5 D
# n+ g. w% o0 `0 X1 @方便实用 简单 何乐而不用呢- # N+ h7 l5 a8 z' W0 |5 ]
- <?php C( p/ N/ e& Z: z* P3 k2 X
7 f4 W, N ]# C( s C- define( 'ABSPATH', dirname(__FILE__) . '/' );; G* P0 }9 Q/ U5 j0 \
- require_once( ABSPATH . 'wp-config.php' );3 @$ }% u( i, j/ J
- require_once( ABSPATH . 'wp-settings.php' );
0 O y" s) O2 z$ F( X# e - require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 I5 v) k; R7 Q0 H1 A! q" T; a$ F" G - require_once( ABSPATH . 'wp-includes/functions.php' );
% Y3 j( [( J+ n* B$ b6 Y6 Z% O - require_once( ABSPATH . 'wp-includes/plugin.php' );& [6 F/ k+ w3 P5 o
- $title = $_POST["title"];
! W7 S4 e b- o/ C - $content = $_POST["content"];: {8 k9 n$ V: w, r/ ^9 k, x
- $tags = explode("_",$_POST["tags"]);
7 g. j$ w& W- x V9 S, x/ ~ - $cate = $_POST["cate"];
: z0 h: ]1 W! [6 s - //print_r $tags;
6 \ Z2 P( \- c: L! y0 t/ Q" l - // h) C; F- n* P/ }& d
- //+ t2 h, ~; y. ~. l8 F/ P
- $wp = new WP();
* N! _ ]% A6 k/ {4 W# @% E - $wp->main();/ c; l5 C8 }6 J6 x3 f
- // j$ }' v! e% L1 f
- $my_post = array();. m% \( K+ ?% L2 X4 M( f
- $my_post['post_title'] = $title; {, s/ @/ O! L, z
- $my_post['post_content'] = $content;! R! A s: w' @
- $my_post['post_status'] = 'publish';
' c2 E% l2 x: d, Q - $my_post['post_author'] = 1;+ n* t B7 a u1 l4 R' r; ?
- $my_post['post_category'] = array($cate);
( ^9 q6 U T6 A1 W - $my_post['tags_input'] = $tags;0 h3 t- L4 F: |( h% Y
- //$my_post['tags_input'] = array('tag1', 'tag2');
7 q( O$ b% c4 o4 N! r8 l) z) J - //$my_post['post_status'] = 'future';
- t2 M+ [7 ]- k5 A# u% y0 I' k - ////$my_post['post_date'] = '2010-07-04 16:20:03';
" r9 r( V! O: z- O4 c# F
2 Q. t, [9 K7 b2 u/ f5 ~- // Insert the post into the database, n: v6 q! w7 B* o% }- t }
- $ret = wp_insert_post( $my_post );
! V2 M2 }. U( ? |9 W$ Q- S - echo $ret;
0 v5 y& q' g# M3 x3 q7 T - ?>
/ o* [5 k, q% w) q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
7 f- U* ?) U0 z6 P- <?php; ?4 I! M# i/ z! v$ }8 M
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 p) @4 ?5 w' l
- require_once( ABSPATH . 'wp-config.php' );
W- k1 n2 X. a: ^4 i @. x - require_once( ABSPATH . 'wp-settings.php' );
& ~5 f# i$ w7 T; I! [ Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 t2 X' u1 o: H- S - require_once( ABSPATH . 'wp-includes/functions.php' );
4 U' _4 O5 `+ a3 u0 c - require_once( ABSPATH . 'wp-includes/plugin.php' );
' d& |5 I6 `- E4 _- ^3 y! I - $pic_name = $_POST["pic_name"];1 f! i2 }0 K; R) K
- $pic = $_POST["pic"];
7 {$ Y2 l. \# W$ @ - if($pic != "" && $pic_name != "")
# c# V4 h3 V$ d - {" O2 {/ p/ g& d: w- e- y8 q
- $path = "images/";- P( B- ^; s% U# N7 O3 y
- $pic_name = $path.$pic_name;
, I: B$ b6 R, ?! U - echo $pic_name;
$ ^+ y+ i9 ~9 L+ ~7 A, V' V - echo "||";
0 j" M) ^' s; `" [! x' }; f2 K - error_reporting(0);
( p1 B2 _) h& y5 ~ - mkdir("images");; r8 L- B0 h/ d2 |6 |& m1 ~, L% [$ L
- $handle = fopen($pic_name, 'w');/ v* \/ ?7 g& h& S: s
- echo fwrite($handle,file_get_contents($pic));7 ], N" O( D8 e0 \* F9 q2 x, y
- }
5 l* \5 }! T3 V% _8 i
3 J, ]7 P2 Q" s" A- $title = $_POST["title"];
3 T9 C" g- y* A* o/ W y/ P - $content = $_POST["content"];2 f* c w% z) q7 b# X- M4 v
- $tags = explode("_",$_POST["tags"]);* f0 x# D" l1 }, R
- $cate = $_POST["cate"];1 e; ^; X% q; u. J) l) t* ]. _
- //print_r $tags;
8 H+ |6 W1 a& y t- u - //
3 j' ^2 u+ W0 m - //
4 O5 ]6 N5 f2 d3 Z, l1 @0 J+ z - $wp = new WP();
( l/ D9 y7 S2 r6 i. P" Q6 z - $wp->main();
& g" c! C: I9 Q - //
- \ z2 m$ L5 Y7 X - $my_post = array();/ k8 C1 c I; w! c3 j4 T) ~
- $my_post['post_title'] = $title;
+ D9 s- d0 m& n. c - $my_post['post_content'] = $content;9 g9 A# c- `9 L( V3 |2 F# K
- $my_post['post_status'] = 'publish';- n+ I/ y8 K9 b! a
- $my_post['post_author'] = 1;
' f/ b+ Q7 j2 x- z# k5 u: F - $my_post['post_category'] = array($cate);
& [2 ^0 U6 W9 k$ F; \ - $my_post['tags_input'] = $tags;
$ N+ H6 O" b) h( M$ \ - //$my_post['tags_input'] = array('tag1', 'tag2');4 ^# `. t7 ]& o
- //$my_post['post_status'] = 'future';0 L+ o$ t' o3 `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 j$ f: R- w4 q( L! h
- " @; }2 G9 N; h3 M' o
- // Insert the post into the database& B+ o/ U6 K* j/ J; V+ h
- $ret = wp_insert_post( $my_post );5 I m3 L c9 x. o& I- x* j
- echo $ret;
7 \. k9 _7 }; c7 l - ?>8 a1 z# M0 {+ M2 ? @
复制代码 我自己写的
" Y8 [1 q7 h( u, [8 b' `. M插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|