|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / U; k) d& l* e. d5 z) D
5 S+ d- Q7 c* E x+ D a直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 c, p/ ?8 m7 a$ L
. c! j. k$ m' s0 d8 f* J我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; x) R1 d6 Z9 \; H
% |' Q$ Z4 _( ?7 L3 ]5 ^方便实用 简单 何乐而不用呢- $ l! n, x+ k% y; Z s+ T
- <?php
+ [$ @% T3 ^1 a, Q: ]7 J, D
; |1 q0 x4 {7 v" d) J, m- define( 'ABSPATH', dirname(__FILE__) . '/' );2 _) c& M4 g0 ?& ^* l' o
- require_once( ABSPATH . 'wp-config.php' );" b* ~2 R+ Z/ N1 [
- require_once( ABSPATH . 'wp-settings.php' );
8 x. R0 {8 s3 z% ? - require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 `+ g3 E0 z: u5 H' @ - require_once( ABSPATH . 'wp-includes/functions.php' );
2 g" g. F# P K6 X+ U' Z; A - require_once( ABSPATH . 'wp-includes/plugin.php' );
; d; y& |8 |4 f3 w7 G2 } - $title = $_POST["title"];3 b z8 i* F7 Z6 p0 g
- $content = $_POST["content"];2 u1 n. i) O9 m
- $tags = explode("_",$_POST["tags"]);0 Z' S5 d6 _& a" N
- $cate = $_POST["cate"];; K- O, P, [/ Q R% f* x/ T
- //print_r $tags;' x8 j5 h' j( @" i( V. } J
- //( u I2 e4 S a' Z8 ^* R" k8 K
- //3 X- L# k6 p6 S- R! n6 x: C4 b
- $wp = new WP();! p/ R0 j3 [5 A8 a' u; \
- $wp->main();% T6 B1 @4 [% o% l. Z; ]
- //
- b& i; M' X( O - $my_post = array();/ k: j' X k+ `3 ?& s, C
- $my_post['post_title'] = $title;/ F3 p/ d8 U% r
- $my_post['post_content'] = $content;: E$ U6 F' e3 ]: p- s
- $my_post['post_status'] = 'publish';" j4 \4 j3 M) S! x% l( W
- $my_post['post_author'] = 1;
5 {# U5 l! x8 `0 B - $my_post['post_category'] = array($cate);1 F+ I! F) x4 j9 ?1 Z" [
- $my_post['tags_input'] = $tags;0 W! R$ d2 R$ Q$ v! J- {
- //$my_post['tags_input'] = array('tag1', 'tag2');
- R$ Y: q7 q- i% I* Z& m9 ^ - //$my_post['post_status'] = 'future';( U% u+ I$ [3 G( y& }: n* l* X
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 k5 U) l% }* D7 t/ V2 x - 7 ~ C: Y: f; i0 p
- // Insert the post into the database
" w+ k- [- V( [& q' Q$ n4 q1 P - $ret = wp_insert_post( $my_post );/ ~2 b3 J* {+ ^) q
- echo $ret;+ h6 c. R) ]0 j) }
- ?>
3 p4 a6 n5 N. Z2 ]0 v8 ]2 o6 ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 ?# [# X$ }) Z% E1 e' m- <?php& \! Y+ `! @7 i3 p2 w& t
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 l6 \ C# m, m( M - require_once( ABSPATH . 'wp-config.php' );
: g5 C# N9 j2 X! M B. M - require_once( ABSPATH . 'wp-settings.php' );- P+ F4 ~' B6 N8 v
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 \- b7 Q2 F$ Y" s! o) w B - require_once( ABSPATH . 'wp-includes/functions.php' );
, M3 S& v3 D. j - require_once( ABSPATH . 'wp-includes/plugin.php' );; I% F$ L E0 `6 |) W5 x, G
- $pic_name = $_POST["pic_name"];( F9 K" p5 z% E2 M
- $pic = $_POST["pic"];
4 O; g; D5 k- x' x$ e# @8 c$ E" ^ - if($pic != "" && $pic_name != "")
$ _& K. w: J5 b: B0 ^# U - {
6 r% R! q* y) z. j - $path = "images/";
! V J, N2 {: s5 N) r( T) P - $pic_name = $path.$pic_name;
: `- R" f1 i; f4 t7 o# o - echo $pic_name;
' C* ^5 T7 i! c1 h+ G5 s4 u - echo "||";* |7 Y/ @6 Q" s7 T: v7 T; I7 P; [$ C
- error_reporting(0);. i: Q4 y. U) J3 }/ W/ p- Q
- mkdir("images");
6 C- Y6 {' l' w1 g: v4 z - $handle = fopen($pic_name, 'w');# H6 r" O( y8 Y8 A: B5 K, L' b
- echo fwrite($handle,file_get_contents($pic));
6 A8 H* W/ E* q$ W - }# i$ q" L" H, T7 v6 `2 [% p$ x
- / v3 P( ?+ K# W8 _7 @1 l
- $title = $_POST["title"];! Y; G( w: z8 x+ m4 Y8 x
- $content = $_POST["content"];
9 a. w; y# ?9 R3 ~( P# }$ Q - $tags = explode("_",$_POST["tags"]);3 q) L" t( L5 g
- $cate = $_POST["cate"];
$ |4 [+ D0 Y7 @ b1 C - //print_r $tags;" x/ R2 w. h3 \: I
- //
; e. `) w: b2 c: ` - //
; S5 x1 X l2 B1 d! _3 `- m - $wp = new WP();
G4 Q k9 r$ N, V - $wp->main();
8 c) a: g: G6 Y0 O+ [5 S - //
, Q. g0 E' ^* E5 ?3 `1 O/ n - $my_post = array();
$ L9 |' d) r) r1 s' A, R, S - $my_post['post_title'] = $title;
- A$ _6 L3 E, J" ~4 v' U - $my_post['post_content'] = $content;. K/ ^; R0 j# }$ c9 p" b9 p4 E8 B
- $my_post['post_status'] = 'publish';
$ g) {9 p+ ?- `" m# D - $my_post['post_author'] = 1;$ l1 C2 R2 n8 n# E" E. |5 V
- $my_post['post_category'] = array($cate);
) M9 R$ P; V C2 A; m - $my_post['tags_input'] = $tags;
0 T) r# a" H) Q5 {. }) a - //$my_post['tags_input'] = array('tag1', 'tag2');
* ^! F3 c0 u, Y- ~5 x7 l - //$my_post['post_status'] = 'future';" H& k7 ^0 S* l4 k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';9 G: p0 ? X. `( e e
- + b7 W/ V* ?. z; ]0 x: V3 `/ `
- // Insert the post into the database
( ^; w$ H6 {/ c& Y - $ret = wp_insert_post( $my_post );1 G" {5 z5 a- \/ p; I& E" J+ C! l
- echo $ret;
* b! e; S" i6 {! Y- J i8 f - ?>
0 e2 E4 a. o$ f0 Q; e$ e; t
复制代码 我自己写的
3 G( C% S. X! j9 I5 V. p, \$ ^插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|