|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 B# N. v3 i- h; N& o
1 m2 u! t Z: K5 ~( q1 y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持 P# T8 Z7 M( Y+ Y6 W) {$ Z: C1 M: B
+ a `( I1 K! n( p: x9 ^! {
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了$ H) l v7 ?) o+ ?7 k) h6 x: D* C
( ?" n3 x, T0 g方便实用 简单 何乐而不用呢- 7 m% U. A( P1 y0 k4 D6 X8 V' k
- <?php
: j+ }8 G. j$ P5 C. m0 o4 _
. y% O$ [" a0 V% H" R5 t- define( 'ABSPATH', dirname(__FILE__) . '/' );/ k, k6 X( N; ]+ m
- require_once( ABSPATH . 'wp-config.php' );8 D% r! }2 F1 n' O
- require_once( ABSPATH . 'wp-settings.php' );1 o. L& Y% {, W5 v/ _/ T+ C: v
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 d2 W0 X& _. Q: H6 `! j9 v
- require_once( ABSPATH . 'wp-includes/functions.php' );
) Q" O; ~3 b j$ z/ I - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 \) B: X& ]" W; _7 ~ - $title = $_POST["title"];3 w1 D; U# s& k+ z4 C: s) c1 Q; }
- $content = $_POST["content"];
3 q+ B, |- y7 A8 G' E - $tags = explode("_",$_POST["tags"]);
% J8 x6 m. T( j5 L( h9 u - $cate = $_POST["cate"];
9 I- W: P8 F1 Q: n - //print_r $tags;
7 S' I1 y% Q3 U+ a2 E - //
# L7 }% P8 y0 }1 p; y - //
s! u8 u- [6 Q6 E/ K5 F( K8 W - $wp = new WP();, a( n: r R5 s/ ~8 x4 l
- $wp->main();3 r" Z8 R( J* [7 R9 L6 i8 Y
- //
4 l" e" ?- B- R9 `1 [# ? - $my_post = array();3 Q; Q6 h/ j* g: c
- $my_post['post_title'] = $title;- F( ]# C* \# f5 U, D2 d
- $my_post['post_content'] = $content;
+ Z" \2 |' h/ [# M - $my_post['post_status'] = 'publish';
9 }, D2 s; o2 r5 E% b8 C5 W - $my_post['post_author'] = 1;
: |. b$ J/ W% B$ u; n - $my_post['post_category'] = array($cate);8 U7 Y' M& h$ J+ \' V6 l5 ^
- $my_post['tags_input'] = $tags;
3 M2 U+ C! M! A) R' I- q - //$my_post['tags_input'] = array('tag1', 'tag2');
6 o# ~* Z" m1 W* j - //$my_post['post_status'] = 'future';
5 S$ d+ C. B M: H - ////$my_post['post_date'] = '2010-07-04 16:20:03';
) ?# A, c/ } O2 V7 U$ W
/ X O( N" S) V6 c+ Y4 P- // Insert the post into the database
# O: P4 j0 K3 P+ H - $ret = wp_insert_post( $my_post );! P4 W: ]" G. K* G$ d' K
- echo $ret;5 x- R9 a/ K6 r7 T) S2 o g
- ?>
4 G: H# i; N& a$ Y5 m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! A# N& q7 H7 T6 M2 T! W- <?php# W7 A3 x9 j/ Q- R
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 ]) R, p5 }7 k, x4 p) N* o* a - require_once( ABSPATH . 'wp-config.php' );0 f D% s6 Q; S( b
- require_once( ABSPATH . 'wp-settings.php' );
" P/ v8 k! b+ s( x+ C& n - require_once( ABSPATH . 'wp-includes/class-wp.php' );) l W& b; D E
- require_once( ABSPATH . 'wp-includes/functions.php' );
) k. P; E2 h- {1 |# o - require_once( ABSPATH . 'wp-includes/plugin.php' );8 a# \8 t0 L% H% j5 r: m& m
- $pic_name = $_POST["pic_name"];6 i! C0 X* p8 ]
- $pic = $_POST["pic"];
' L! R, ^7 f1 ]+ w$ w% n - if($pic != "" && $pic_name != "")
6 K, u7 o: K4 N% f' ~/ q, e0 ^ - {5 B& a- e+ ^3 o: a/ m6 }4 N
- $path = "images/";8 O% g& M% v8 A7 V0 Y
- $pic_name = $path.$pic_name;3 S" n' H v8 ?% u
- echo $pic_name;4 I& {1 M2 l! O- d! x
- echo "||";, u8 \ C7 ]& Y; g2 P, v+ z
- error_reporting(0);; E( k) |5 d6 C# r
- mkdir("images");
# X( x5 O/ q5 @5 b1 B- d0 W( n - $handle = fopen($pic_name, 'w');! |. [& B0 e3 H' ]2 c6 s, T* d
- echo fwrite($handle,file_get_contents($pic));
: G( [$ w% ~; K, |1 T# g( P7 p - }. D+ S7 U9 d. Z- a+ \; x
% X! `* c8 D4 b- $title = $_POST["title"];
3 J0 Q4 \6 K D# r% Y/ J; u - $content = $_POST["content"];& ~1 N* Y2 T2 b0 z
- $tags = explode("_",$_POST["tags"]);
4 r8 z* u( K) J - $cate = $_POST["cate"];9 t7 Y/ x x& V9 e
- //print_r $tags;
6 E$ _ K+ @1 i, s+ [ - //
. i, n- A. y* G ~ w: B: s - //- P# p# z* |2 \! _
- $wp = new WP();
: s: }8 W5 U/ `" {5 V7 x" q - $wp->main();
; h; `! R) D" n7 N - //2 L& M# t2 S# J* v7 G0 |8 c! G) {
- $my_post = array();( M3 \1 |! p. E! b- C
- $my_post['post_title'] = $title;
0 I, n) g) \1 w! A/ \2 b, ]2 h - $my_post['post_content'] = $content; I# ?5 J$ q% D5 x1 n" A" {) f
- $my_post['post_status'] = 'publish';
. [5 x* W# @1 f - $my_post['post_author'] = 1;
7 o. P9 R7 c/ E/ T, ` - $my_post['post_category'] = array($cate);
' N1 X9 d$ x R2 P X - $my_post['tags_input'] = $tags;
* j3 L% ~4 R0 `8 s' Y; s, V k - //$my_post['tags_input'] = array('tag1', 'tag2');! n' i5 x2 e9 W6 M2 e; v
- //$my_post['post_status'] = 'future';
* z, L) M* }& U: z3 | - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 ?# C$ D! B. T
2 `6 |/ F* Z. W7 A( u- // Insert the post into the database
+ j. Y- O* v6 c2 |: a2 O - $ret = wp_insert_post( $my_post );
Z; q$ c: L7 F2 h - echo $ret;
( x- u. p' `, G8 M - ?>* U( x! E5 [3 B9 p
复制代码 我自己写的/ T+ I. [! d1 y' Q2 H" [
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|