|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
9 S7 A' e2 y4 _ k) M8 Q5 U
' s, b! G, K: d+ _# P直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持+ t/ g1 o1 u/ H( i8 X
3 Q7 ]% E1 m }7 L' _( M3 ^ j我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了3 V' S' ^; E2 J) [2 @" }* ]
0 e5 [: \0 F6 R' @6 q: a: W方便实用 简单 何乐而不用呢
! i. N6 {2 i5 `6 U' W+ K- <?php& B& ~4 e+ N) W$ s; F
1 P3 r# b- c5 Y" q7 Q% Z; Z- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 _ S, }7 O+ r- g - require_once( ABSPATH . 'wp-config.php' );
: g0 l9 C# x. ^8 ?4 X4 g+ S! `' t - require_once( ABSPATH . 'wp-settings.php' );# S" m9 G5 E7 q! J7 G! ^7 a
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 Z. w' W. R! k% W7 [# ?
- require_once( ABSPATH . 'wp-includes/functions.php' );
( E- Z' V* P# ^: c Z3 S - require_once( ABSPATH . 'wp-includes/plugin.php' );
3 f9 ^ K- }# G - $title = $_POST["title"];
3 l1 F- d2 f5 u; [, n' A4 {: o! K - $content = $_POST["content"];- z: A( e" f" R9 _ m. ^
- $tags = explode("_",$_POST["tags"]);
9 s& w) r' q+ k1 Y; F - $cate = $_POST["cate"];& \- s, C8 z0 ^* z4 y* R
- //print_r $tags;: ~% D* y3 {# q) J# k6 _% B, U( Y
- //
L @: q( R3 W f0 c - //8 [6 O1 f2 K' R6 b6 r
- $wp = new WP();" ]' e7 p; Y7 P8 t
- $wp->main();! S- B5 ^. H3 ^! h+ F
- //- S- K; E, U# T$ Z! [) z6 L0 p) b
- $my_post = array();
& Z. g$ _0 v; a: w2 G) Q - $my_post['post_title'] = $title;( G, W) w2 B/ ?' o0 {( J/ g
- $my_post['post_content'] = $content;, r9 P% }( z! U: H
- $my_post['post_status'] = 'publish';% k9 F5 C( y8 F8 B
- $my_post['post_author'] = 1;4 m- \( r+ f$ K* V: E, e. p( l
- $my_post['post_category'] = array($cate);& a+ _5 b+ |4 g# P
- $my_post['tags_input'] = $tags;
+ {* ]# ^ r& L; q5 ]" j6 ^ - //$my_post['tags_input'] = array('tag1', 'tag2');/ d4 Y: U" M0 U n0 a* I! l2 e
- //$my_post['post_status'] = 'future';. i8 H6 b/ q" K2 r& U
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 C8 ?0 ?4 P7 Z! X
* O8 C4 ?/ E" a! L" s- // Insert the post into the database4 y m' @: W1 @, I% g, l4 U( W3 b
- $ret = wp_insert_post( $my_post );, Y* c6 u2 o2 g
- echo $ret; ^+ ~# s1 Q2 J D$ Y! e+ z
- ?>
% l4 _1 n% K; X$ C& v# m* F
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 w0 `) n8 {. h+ |4 K& c- <?php
& u8 M$ k8 U7 Q/ T- L1 Y - define( 'ABSPATH', dirname(__FILE__) . '/' );1 Q4 x$ t- j; `; q4 v
- require_once( ABSPATH . 'wp-config.php' );# C' f1 R& y f$ Q4 t' _
- require_once( ABSPATH . 'wp-settings.php' );$ }- {$ Y4 U9 F y5 x, f) J1 j: A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( @7 Z4 e3 A* i( `# P/ E - require_once( ABSPATH . 'wp-includes/functions.php' );
) b. R4 |: L9 h - require_once( ABSPATH . 'wp-includes/plugin.php' );1 I7 A% j0 R. |3 B m
- $pic_name = $_POST["pic_name"];! y/ n0 V, P$ Y9 \- a
- $pic = $_POST["pic"];
! o- x1 C( i! E$ t4 w3 S - if($pic != "" && $pic_name != "")& t W/ {5 J3 ?
- {% {7 c/ n+ R- R* W' g6 E
- $path = "images/";
5 \2 F1 U9 [4 C2 \2 ^# ~2 g - $pic_name = $path.$pic_name;" k/ H& B! C$ ^# k' L1 k
- echo $pic_name;; C& @: \; `/ z
- echo "||";2 b4 u* Q1 m3 @$ Q) X! l
- error_reporting(0);
( y7 g- r8 n. \2 Q - mkdir("images");
* q! ]2 r0 |( e1 z) e' \ - $handle = fopen($pic_name, 'w');
; _: Z; a7 n1 n B4 s: K; z - echo fwrite($handle,file_get_contents($pic));, c4 l6 V' ]& e" E3 @6 }, U5 b
- }
& p1 w4 f% m) q2 f' W - , V8 I( Q6 x2 L, U# t5 T& v
- $title = $_POST["title"];
1 n/ h& T; v( }% s; J - $content = $_POST["content"];
; Q: d! s" A6 i1 e% x$ ` - $tags = explode("_",$_POST["tags"]);
8 R, y9 L, l# Q, F9 G! W - $cate = $_POST["cate"];7 m1 _9 s, D( C4 u @
- //print_r $tags;
+ P6 t2 p/ ~' f8 Z$ e4 B - /// V( C) A1 ^. M* r. J, `4 N
- //, o7 y9 K$ U4 d1 N
- $wp = new WP();) O4 N5 O I) _1 @5 c( G
- $wp->main();
! P/ v$ ?/ t& k, T6 ]. z& i - //
o* z$ d/ r& l% Y - $my_post = array();
" j Y9 X- H! M - $my_post['post_title'] = $title;0 p8 v7 r2 Y, @( w$ h' _" k
- $my_post['post_content'] = $content;# K) H& y' @4 x& e
- $my_post['post_status'] = 'publish';. P+ c7 G$ i! L: B0 M# s% n
- $my_post['post_author'] = 1;
; X2 G" a0 N% p; m - $my_post['post_category'] = array($cate);/ |3 T4 s$ S0 w) b, f* B
- $my_post['tags_input'] = $tags;
; s! H b+ V1 s. x$ B; L - //$my_post['tags_input'] = array('tag1', 'tag2');
# t' J, Y( ~* @ A9 [& ]# B/ u* m5 y - //$my_post['post_status'] = 'future';# A2 a% `# P" e. W. Z% h `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 a4 [6 _4 h9 `) W5 g - . f1 y( t6 M4 T( j, ?+ E
- // Insert the post into the database
) ^. Q6 p4 E- \. K" X - $ret = wp_insert_post( $my_post );$ E3 n. S) P% L. B- U. P. V2 q
- echo $ret;
5 g# ]% s: L$ J, w7 t2 N - ?>
4 B# K8 a$ C) P8 H/ Y+ h( J7 f
复制代码 我自己写的
3 s, e5 @ D3 J2 z+ E插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|