|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
5 k! X+ R! ?" f: T" I/ s$ \; b w9 c+ {8 f& ?" C
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持8 l# x; N7 `' b/ T' x
. D% j/ {& k+ [* R( r, T& g1 [8 v我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
4 ?, ^ d$ D# b0 R' p: l! Z2 Y) K0 y+ W, [& a" W/ j
方便实用 简单 何乐而不用呢
/ S B2 T2 G( X) i* R% o [- <?php0 U# _7 v" U! _
- 6 d* M. T6 w$ Y0 x: g4 r9 g! c
- define( 'ABSPATH', dirname(__FILE__) . '/' );- l1 a9 _) P1 R/ u
- require_once( ABSPATH . 'wp-config.php' );
( D! b' ?- @2 B9 p) B; F) o - require_once( ABSPATH . 'wp-settings.php' );: v) q3 V. z, b" A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ n N I" Y- E! v
- require_once( ABSPATH . 'wp-includes/functions.php' );- `( D$ e1 Q, ?2 \
- require_once( ABSPATH . 'wp-includes/plugin.php' );8 z" L8 a- J9 }3 T
- $title = $_POST["title"];' y8 h7 Y& T8 E0 G e: J
- $content = $_POST["content"];
/ ?4 r1 ~8 F* Q: _ m. n - $tags = explode("_",$_POST["tags"]);
, F" ?* `" g- r3 k6 a- W) f - $cate = $_POST["cate"];
% `3 ?& U8 _- S. Q' U/ e - //print_r $tags;
- |9 m' N6 Y D+ g) q$ N; i - //
& B8 h5 f" C6 L1 D+ U% a, D - //; q, `+ B8 W* p6 X
- $wp = new WP();
! \( B6 p" l9 D# k l( p - $wp->main();6 I9 V3 A# f/ z" P3 v* s8 P- Z# g
- //
' J" r* W# t: h - $my_post = array();
& h2 X/ Y/ ^+ | - $my_post['post_title'] = $title;6 z% l3 G- V/ C% K* C( Q# g" B3 {
- $my_post['post_content'] = $content;
5 \5 S2 T9 b/ t# H! l - $my_post['post_status'] = 'publish';
+ M! M; Q( Q0 n3 l q0 S+ N. O. m/ ` - $my_post['post_author'] = 1;% G% M, X9 k {% K; |% t
- $my_post['post_category'] = array($cate);
: ]" u1 a) b; C* H r8 n" I - $my_post['tags_input'] = $tags;: h. h7 K5 v/ w! c; o# D U1 |
- //$my_post['tags_input'] = array('tag1', 'tag2');
* W0 M& r* X/ `7 P! ?% b - //$my_post['post_status'] = 'future';& X( j* i# E' g% B, H$ E
- ////$my_post['post_date'] = '2010-07-04 16:20:03';, m/ \, e9 g" o
2 l# t+ y' M, K9 t- S' _- // Insert the post into the database
. M' d' o$ c+ V( o+ i N5 Q - $ret = wp_insert_post( $my_post ); ^( F' y) v; [7 h- E
- echo $ret;. Y0 p/ I Z7 O9 P
- ?>
" P, V) I2 [% p% i6 ?: E a$ g" k
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 4 r+ C( I' E3 `2 U4 f% n: b, g
- <?php
! P: p9 _9 y' N# n0 j - define( 'ABSPATH', dirname(__FILE__) . '/' );
, A1 e4 I; V6 P" u- _' V! ~ D - require_once( ABSPATH . 'wp-config.php' );
7 Y" B2 r2 Q6 z - require_once( ABSPATH . 'wp-settings.php' );
3 `$ ~# d0 D! d8 g' U( } - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ W, B& k+ |2 o" h - require_once( ABSPATH . 'wp-includes/functions.php' );
. X) e1 l' j3 D7 r8 T - require_once( ABSPATH . 'wp-includes/plugin.php' );0 P- g7 E6 _0 W2 n6 v7 U
- $pic_name = $_POST["pic_name"];- Z4 v+ J( |! Y
- $pic = $_POST["pic"];8 J6 ]( |1 B8 v/ o9 U! S1 Y9 |7 X
- if($pic != "" && $pic_name != "")
' D7 M4 S& I# T! p* Q' G; q" g& n - {
3 e7 Q2 ~, n% R0 q1 j9 n I+ G" } - $path = "images/";
6 d. ]; U0 g5 n$ S N4 A - $pic_name = $path.$pic_name;
' v- G2 O( n+ M& F. m J) b - echo $pic_name;3 c( ^! k$ \6 D# w! [( F) ]
- echo "||";
* e. f; m: A! i: d - error_reporting(0);) K+ v; C7 U4 t3 K
- mkdir("images");5 h! g8 O& x R+ w4 i
- $handle = fopen($pic_name, 'w');
3 k' _/ u1 g: J! k* X! R& H - echo fwrite($handle,file_get_contents($pic));
# L' ?' |; ?+ ?4 u8 a9 W6 d3 N - }1 Y( C+ \( r" y4 {
( q# L& K( T. J- K6 l- $title = $_POST["title"];! \( Y- V1 E0 M% W; A" J. P
- $content = $_POST["content"];
( F2 M. d" g; I3 O- \3 m - $tags = explode("_",$_POST["tags"]);
! v3 `: Y0 r O- _0 G5 N - $cate = $_POST["cate"]; v2 \/ X6 w: I, U; b3 q% l) ]
- //print_r $tags;5 J' t; K/ x5 P
- //5 _, q5 }3 v5 K" r& x
- //1 R5 i6 R4 Y5 i2 t
- $wp = new WP();# l. u* `$ X! M5 x& m/ L
- $wp->main();3 f: z( q' Z) m5 Q
- //
" ^5 e% e+ s; c) _7 }4 f: C - $my_post = array();& T- v( E8 s! j/ m2 t
- $my_post['post_title'] = $title;
5 }2 I+ |7 c" }' L2 i' Z* o - $my_post['post_content'] = $content;3 E' V/ |6 d B9 v0 j V9 [( C
- $my_post['post_status'] = 'publish';6 ?4 E% P: S: j
- $my_post['post_author'] = 1;
+ y" g2 s' Z9 M - $my_post['post_category'] = array($cate);/ V8 f& ?/ g% i+ I3 M5 T- d8 |
- $my_post['tags_input'] = $tags; k' o5 J/ A4 N! l1 x6 h& P
- //$my_post['tags_input'] = array('tag1', 'tag2');
: c; A4 @0 c# i( X4 A' K - //$my_post['post_status'] = 'future';
4 S; W ] a1 Z3 L: p - ////$my_post['post_date'] = '2010-07-04 16:20:03';
# j$ S: d }- _9 A: C
- Z8 P. Z4 E% w$ {, B- // Insert the post into the database
$ T8 e* n4 C3 N. z( Z" p! C5 ` - $ret = wp_insert_post( $my_post );, }3 o% f' t+ U6 W
- echo $ret;
9 T# t3 K- E7 H - ?>8 D) ^( U( U- N+ g* J
复制代码 我自己写的 ?1 B1 f2 S" N/ _4 M/ S9 c
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|