|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
C' g3 G. P, E3 ]3 S( n8 S" E2 c
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持( V' U1 W ^. ]- { B- N
& G' f, X6 r; F% }# P我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: J/ ~. i% d' K& k5 ~2 F2 j* ?. c# S+ ^1 F$ ?- ~$ D
方便实用 简单 何乐而不用呢
[: m$ `3 s9 B) O% ~( p- <?php
; _. t/ @0 ~9 U: v& \. S - + J+ N9 @" U' x# T( X2 \
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: E+ o2 l) K$ k6 y) c7 | - require_once( ABSPATH . 'wp-config.php' );
4 z5 _6 h: B- N2 a - require_once( ABSPATH . 'wp-settings.php' );/ `% x( u( P, G; {5 Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
' I6 R& q5 a+ P g; c& H - require_once( ABSPATH . 'wp-includes/functions.php' );0 n% w) k. X m8 }3 h
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! g6 @' N$ u& h - $title = $_POST["title"];+ `: s8 ]6 _) K! }6 C) O
- $content = $_POST["content"];
: ^5 S" e7 M3 e. e& G5 V - $tags = explode("_",$_POST["tags"]);+ `) Z, g/ o9 c. `
- $cate = $_POST["cate"]; I9 U" d3 d7 q- o: x% M ~ v4 {
- //print_r $tags;
, C( y# N- _# o r& y+ f - //2 e |5 L1 [8 } S1 `7 L _
- //8 d- y( ? x" n H8 L
- $wp = new WP();
- ^2 Q" {3 D, h& e% ]4 r9 z$ g" b - $wp->main();
3 Z) v) z3 B1 Z+ ?% C. r3 t# i! H1 s; } - //
3 y( | I; K# h! d. U- J - $my_post = array();+ a6 h; U; U3 @4 q9 }0 P' z1 z
- $my_post['post_title'] = $title;8 T9 \, e0 y# L& e1 Y& r. l7 s
- $my_post['post_content'] = $content;
* e8 h' u2 W5 z | - $my_post['post_status'] = 'publish';, f E2 j# L, g9 T; ~5 o$ V
- $my_post['post_author'] = 1;
& g( T) o3 A/ T9 S) P - $my_post['post_category'] = array($cate);9 c1 B0 F) u' d3 b; T/ l
- $my_post['tags_input'] = $tags;9 N- p# ~4 J3 i* O" T' m
- //$my_post['tags_input'] = array('tag1', 'tag2');" M. j/ z* {/ H, Z+ \5 b
- //$my_post['post_status'] = 'future';
2 a" w$ X5 x/ h) \ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
! i# p5 ~% g9 S( R
& g3 @: g2 i$ S0 F$ X- // Insert the post into the database E; c& S& F J5 I
- $ret = wp_insert_post( $my_post );2 h' }1 u! t6 {2 b% } V- _
- echo $ret;
: A4 ~! e" `* n% q# Q - ?>
; [3 T5 Z9 `2 v+ J3 h) g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- / A' y8 k% B! }7 x9 R5 K- i9 M
- <?php
0 b) f T1 E' Y( N/ M - define( 'ABSPATH', dirname(__FILE__) . '/' );( N, B- {# F" c5 R$ Q+ Q+ p7 k
- require_once( ABSPATH . 'wp-config.php' );/ _7 j0 D& p! j4 h- s3 k
- require_once( ABSPATH . 'wp-settings.php' );
6 A/ J& |, V/ n( D2 T$ Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );
' x+ [" n+ S5 n+ t" L - require_once( ABSPATH . 'wp-includes/functions.php' );
* X2 e e* N6 T5 s - require_once( ABSPATH . 'wp-includes/plugin.php' );) w8 z9 M3 F5 l6 b+ _
- $pic_name = $_POST["pic_name"];
7 R' ~4 ^, q" |- B/ U" w! T: w - $pic = $_POST["pic"];3 M3 O" ~( C, R) c- Y: D
- if($pic != "" && $pic_name != "")/ ~) \ }% f+ E% \8 L" F; L( J
- {( i9 P/ F) { c6 D, Y5 h2 M( b
- $path = "images/";4 O5 ?* R/ ]1 ^0 ~6 M& I
- $pic_name = $path.$pic_name;
, e9 }" F, T1 G9 I0 Q7 H - echo $pic_name;
7 M' S2 P+ @1 |; ^5 b - echo "||";
% S- G- C. Z v) e2 _. T - error_reporting(0);6 p! Z5 T7 I% Y/ s) i" _" X
- mkdir("images");
: V! A, n- p! {7 ~ - $handle = fopen($pic_name, 'w');
2 q9 h A& i! c- ^ - echo fwrite($handle,file_get_contents($pic));
) T5 ]* R1 {; l' l - }
& @# J" ~: K' m' W. I% H3 }
+ J, w& @' P6 t' k3 B- $title = $_POST["title"];
3 K+ e9 n! V/ L) d: d9 ? - $content = $_POST["content"];
1 f& q8 b0 I$ E) C" g7 D; V - $tags = explode("_",$_POST["tags"]);
. ^6 N7 t: d: I+ O: S- J3 [9 ? - $cate = $_POST["cate"];: m7 F' ?& H+ c8 y1 C
- //print_r $tags;
( @" b$ M4 A% ^* {/ c( y, a9 w - //
1 Z# M" X/ b0 \- \/ ]9 U% V - //0 P. _+ A2 W% _& Z4 o, M
- $wp = new WP();8 `, V8 R' w1 B) S
- $wp->main();( m* h$ v- Z; D" N3 @
- //
3 Q# P! X0 w# `6 O, F5 t - $my_post = array();
! g$ ^! i5 ]. N/ M& \$ l - $my_post['post_title'] = $title;- A4 H5 F# Q |. }
- $my_post['post_content'] = $content;0 k3 S: g+ [1 P5 T/ J
- $my_post['post_status'] = 'publish';
: f6 |& E ~! M - $my_post['post_author'] = 1;
/ l* @+ q, P( o( h- [ - $my_post['post_category'] = array($cate);
G. e& s; m7 h4 t - $my_post['tags_input'] = $tags;- C( n1 n5 y1 H) j
- //$my_post['tags_input'] = array('tag1', 'tag2');1 c5 d7 U5 L4 }1 H
- //$my_post['post_status'] = 'future';: y& F! c8 Z3 Z1 f% r: }2 z4 C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 K! Y% r+ u4 Z" n: j
% Q/ H, a5 \2 d% `% `* g- // Insert the post into the database
3 s C0 [. w9 q+ B1 p, O - $ret = wp_insert_post( $my_post );' r, {; o8 U/ I& U+ u' E* b
- echo $ret;8 b, z' w* o: b2 v9 k0 j
- ?>4 h2 [0 s( E3 n7 n
复制代码 我自己写的
" M2 A& F: B9 S; y6 w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|