|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
" o) V: J8 A6 Q; ^; e" j. M
6 k& O& p# U% s2 a+ B1 \直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持/ T: b& o# Z* \: P4 Z/ u
% D9 R* |( h/ l8 v. w8 z
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ C5 A5 ^" D8 t7 f/ y7 t" o8 l2 u1 ?( ]
方便实用 简单 何乐而不用呢- @2 u% f, c( I/ {0 p. F
- <?php0 j$ M+ I; Y F. d/ _& L k1 }, h+ o
/ Z9 l9 e5 O" R: u( d- define( 'ABSPATH', dirname(__FILE__) . '/' );
( K8 ^6 {; I' T) A2 Q - require_once( ABSPATH . 'wp-config.php' );
% v" B9 s% h3 P/ E1 C - require_once( ABSPATH . 'wp-settings.php' );# J" f$ s8 @' Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );( _1 b" Z6 I: Z0 o, o1 l
- require_once( ABSPATH . 'wp-includes/functions.php' );
& ]$ h/ I+ n" r+ Q5 o - require_once( ABSPATH . 'wp-includes/plugin.php' );1 B7 W$ Z/ l/ H% t- ]
- $title = $_POST["title"];
* K9 s% Z+ k) {5 G' }' o# a* n - $content = $_POST["content"];
) C3 |: j* h9 j1 Q' M; t - $tags = explode("_",$_POST["tags"]);
" d# K# H5 U2 Q - $cate = $_POST["cate"];; X; y9 {4 K) Z8 y; W: C- i' [
- //print_r $tags;
( H# X1 i7 y* m: q6 s+ y: f9 @ - //
7 o0 m! ~! [ _% ~' j5 D0 e! S - //
& l( e0 x2 N' }& K( g& ` - $wp = new WP();
! @9 z. i- j8 _2 c - $wp->main();
' l& |" l R- P3 L$ a - //
3 R S3 L8 O! x f. Q% j - $my_post = array();* j2 P3 w% X6 V
- $my_post['post_title'] = $title;
( M; I a4 T) b - $my_post['post_content'] = $content;
( o4 G3 n% l6 f% J6 c+ @6 z - $my_post['post_status'] = 'publish';
, D/ a/ u% j' C! H( P - $my_post['post_author'] = 1;. r7 q6 ]" k; B3 c
- $my_post['post_category'] = array($cate);
2 l" h! ~! i* |) S - $my_post['tags_input'] = $tags;
( {" } Q) l8 x6 C$ g' Y. c, r - //$my_post['tags_input'] = array('tag1', 'tag2');
) I/ p* P5 {, v8 P - //$my_post['post_status'] = 'future';
. ?. s/ p; s- n8 u2 S& X# u4 Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: ]) d6 d: D$ X- S3 j8 K& ] - 3 |: Z4 x- @/ E! _( A' x
- // Insert the post into the database
8 R, V9 Z+ j4 Y& Q1 _- } - $ret = wp_insert_post( $my_post );9 o9 p( w2 J5 q/ P5 s9 n
- echo $ret;
, z0 d3 I+ J. ]9 [" @2 J. @! `% E - ?>; s7 y4 Y& e% v5 z9 h
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 5 V9 G- m& `6 {! M$ A7 _
- <?php
& f7 k& I: A: ~- t V9 [ - define( 'ABSPATH', dirname(__FILE__) . '/' );
) u7 d: Q0 Q* [* A - require_once( ABSPATH . 'wp-config.php' );
7 A, N `/ ^+ R8 S8 z. Y - require_once( ABSPATH . 'wp-settings.php' );- z! t' w) f/ O$ N8 t3 G* W/ }
- require_once( ABSPATH . 'wp-includes/class-wp.php' );8 |+ f# l) q1 m; \
- require_once( ABSPATH . 'wp-includes/functions.php' );
6 y& l" l$ P: z3 a1 q) R3 y- r - require_once( ABSPATH . 'wp-includes/plugin.php' );
& T. ~- ? ?5 d4 w - $pic_name = $_POST["pic_name"];: s b, Z; o$ \$ h v
- $pic = $_POST["pic"];
) l% p& i/ G& ] - if($pic != "" && $pic_name != "")
# Q f- c! Y# c0 O& P. f - {3 W9 m& |( x I5 h* I( v1 \' b
- $path = "images/";
" Y2 |' _+ q- \3 P - $pic_name = $path.$pic_name;
* P) q( h. W3 D& }9 E' s2 x. n7 K" x - echo $pic_name;
- V" h: _& v% T! i3 Y' h - echo "||";
' x x2 a" Q. H% z3 G - error_reporting(0);
5 Y5 O$ m6 b8 `6 a - mkdir("images");6 c) ^! ?6 Z5 c( y' q( g' f
- $handle = fopen($pic_name, 'w');+ n9 d$ n9 B% B9 m
- echo fwrite($handle,file_get_contents($pic));& h5 r1 i2 a6 V* F) [9 x6 R
- }! `/ M8 R% q; D* Y" B
( G% m/ m& J* i# p8 ~/ p2 X- $title = $_POST["title"];
! K. R+ Z r6 e: w- i2 t* ~6 j - $content = $_POST["content"];
6 Y2 a! Y# u- s$ p& ^& M: Z7 I - $tags = explode("_",$_POST["tags"]);
6 @% U2 W/ G5 M- C: ]3 P' `4 K - $cate = $_POST["cate"];
. q0 T X4 F q. O) G- Q, w - //print_r $tags;
0 O5 h: M8 a3 ^7 {! P) o- Z - //, X+ e" C: h& y/ z: C
- //& U! j$ t% A/ `6 w D8 T. H8 k
- $wp = new WP();* {5 ]% ]/ i2 x0 A0 C8 L
- $wp->main();) a$ j* c4 D) q
- //
' M V$ D7 Z# `- }5 j4 b5 |/ w3 { - $my_post = array();$ d4 f; R7 c: m
- $my_post['post_title'] = $title;1 k0 p% y+ R. P. m: A$ U
- $my_post['post_content'] = $content;
1 H2 v0 P0 E, U4 A* R0 K - $my_post['post_status'] = 'publish';2 G) y# S5 N( G2 S4 y: G; l; S
- $my_post['post_author'] = 1;
" K& y* X5 ]; b9 Z5 g - $my_post['post_category'] = array($cate);
5 }8 [& K6 D4 z5 K - $my_post['tags_input'] = $tags;$ E' P! s9 i9 a7 @2 ^2 W
- //$my_post['tags_input'] = array('tag1', 'tag2');6 m" x+ C- ^ g$ ?+ y2 m. j) h
- //$my_post['post_status'] = 'future';4 i" m% ]; C' v( { W, s3 l; F/ Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 Y8 t; I1 \4 J! ^$ C/ _, o
% a+ W! @) t4 g+ @! A% V- // Insert the post into the database
& q* I9 r7 T, M1 Z R; s% h5 Y( e, r - $ret = wp_insert_post( $my_post );
6 D, z, j9 @ l - echo $ret;0 G$ ^8 y, ~2 i; Q b* {' X
- ?>4 L$ ~0 `! ~/ b, ^5 X8 e
复制代码 我自己写的: K* k4 ^8 q6 q0 C+ h4 @4 H6 X% K
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|