|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 # P5 v) n, w/ K% Z! y
0 D# m. @& d S2 u$ ^9 h5 @$ I
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. c0 h4 `: g/ Z3 N3 k' B- s( q5 r6 [5 L
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了1 U& y2 \4 Z$ H* C9 D
( g- S+ y$ ^+ G/ Q方便实用 简单 何乐而不用呢
6 E1 d9 A7 J4 ?. f0 F1 }- <?php# a+ K7 x: N& T. _' b
7 G9 ~5 h" `7 L ^: ]/ M- define( 'ABSPATH', dirname(__FILE__) . '/' );
" A6 U" i$ ?6 e# b. R9 G* q. Z4 A - require_once( ABSPATH . 'wp-config.php' );9 i! r! k: Q) A' Y0 `2 `0 I
- require_once( ABSPATH . 'wp-settings.php' );( a5 ?1 @- m1 `, f0 O
- require_once( ABSPATH . 'wp-includes/class-wp.php' ); a' @/ x7 I: \. v! K* y& x
- require_once( ABSPATH . 'wp-includes/functions.php' );
0 I* k. P: n4 b# c8 |- X - require_once( ABSPATH . 'wp-includes/plugin.php' );
* {7 V3 D: o; @/ l - $title = $_POST["title"];5 Z- c0 G' E# B8 L- [- B1 l' \
- $content = $_POST["content"];
1 i+ \9 ?. ~2 B7 W: d) M0 n, {! p - $tags = explode("_",$_POST["tags"]);0 ~( Y: A! K: }+ o8 C) _. o
- $cate = $_POST["cate"];
' M0 }) c |9 w( E - //print_r $tags;
8 c3 G! V5 x" S1 M" m - //
( P' }; E) [1 `! b8 S - //" v1 l1 ^; a0 L& L% s2 p
- $wp = new WP();# p" s# j9 L0 ~5 I
- $wp->main();
& S2 k$ A+ z& h X4 C3 Z2 R1 G - //' k6 D7 T8 q M1 e" F3 d
- $my_post = array();$ @/ c! A7 E4 a# N' T
- $my_post['post_title'] = $title;0 A; T7 R( `9 a2 u; ?
- $my_post['post_content'] = $content;& d% x7 w+ u! F. Q, p
- $my_post['post_status'] = 'publish';
9 `0 ^7 g% F) s0 i$ C6 Z' | - $my_post['post_author'] = 1;! E& U: [% E" |9 Z" v$ k2 Z
- $my_post['post_category'] = array($cate);$ L1 x! b7 e, g4 @' E4 U
- $my_post['tags_input'] = $tags;
0 S0 \( \; q' B2 R! s. q" u - //$my_post['tags_input'] = array('tag1', 'tag2');
9 i% h1 X( p; T( l. r - //$my_post['post_status'] = 'future';
" ^) p% V: D1 p* P0 V1 e - ////$my_post['post_date'] = '2010-07-04 16:20:03';6 s! A0 l0 B$ c* d
- 5 `! f$ O; i# f: ~
- // Insert the post into the database4 I3 i8 Z" }7 S1 N# N
- $ret = wp_insert_post( $my_post );
( o8 k# X, n, Y8 ]+ l# r* N - echo $ret;" s+ ]1 a# o6 r+ I' ]9 e1 Z8 s2 S
- ?>" ]% c: h2 C% M3 v0 l
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 X* v5 h- u6 [) W( l- z- <?php1 Z& }! @4 @6 T3 {; o. _1 N
- define( 'ABSPATH', dirname(__FILE__) . '/' );
* F& B/ [7 o+ A* @3 J& s( B - require_once( ABSPATH . 'wp-config.php' );) |& V7 m$ Z: L( ~" }) }: C
- require_once( ABSPATH . 'wp-settings.php' );3 y5 F% ^8 R d( O* }
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
. {; L4 ^6 b; X; Z! Y: U) A - require_once( ABSPATH . 'wp-includes/functions.php' );
' d% ]3 _% U8 D - require_once( ABSPATH . 'wp-includes/plugin.php' );4 I" A. c( N3 E
- $pic_name = $_POST["pic_name"];
; b; ]5 K, X( }- `1 ~0 b9 |* d - $pic = $_POST["pic"];
: c; u% B; f& v: w3 z6 r2 ], ~% S - if($pic != "" && $pic_name != "")" v* R- h8 ~2 T5 o: s* j Z$ y3 V
- {
& G9 E) e, B: `. z - $path = "images/";: |6 W+ I* C* Y# [: c! d
- $pic_name = $path.$pic_name;3 w$ Q* H& H/ Q8 s' M
- echo $pic_name;
: y- H9 b, N) _) ? ` - echo "||";
# ?" X3 {, P& w5 R( t5 h* M - error_reporting(0);
1 ~& w! c2 l' V% j - mkdir("images");
4 Z+ _( l1 M( U: U$ B- M - $handle = fopen($pic_name, 'w');7 p& f f7 C, B1 E8 y) u* W
- echo fwrite($handle,file_get_contents($pic));
2 ~. L+ G' w. d5 E g - }
* M' x7 I0 m& `3 v8 K: n R; H - * Z8 \ M0 t( q0 S/ e4 {4 j
- $title = $_POST["title"];
$ N2 H1 d' _* {( B g9 o. ~4 p - $content = $_POST["content"];" Z8 d4 M: v7 y. _
- $tags = explode("_",$_POST["tags"]);
7 K7 C3 F- j5 r: O' J. N- X3 G - $cate = $_POST["cate"];
, _& K- e, ~, R# _( f- r - //print_r $tags;5 R `! R( o, d3 w4 @ t6 g! B4 m+ L
- //0 R% R4 ~- S+ [7 i7 W; s
- //3 O! H* b J5 `; x% X
- $wp = new WP();
. M6 r2 d8 q$ P - $wp->main();
( g5 w) k/ R! {, w5 }& o0 A3 \ - //4 b: {+ P( o4 C6 c
- $my_post = array();3 g- S' y* j* s
- $my_post['post_title'] = $title;
( ]) e u9 \0 g$ U" Z5 x" h - $my_post['post_content'] = $content;
; ^! K) p" B" n. X! y* v; s8 u6 q) K - $my_post['post_status'] = 'publish';
! N# d% B8 U& y6 { - $my_post['post_author'] = 1;
4 {0 F% `3 F' q8 @$ C - $my_post['post_category'] = array($cate);
1 q7 @( f+ q; {( {# g - $my_post['tags_input'] = $tags;
/ p1 N& s: r. n9 I - //$my_post['tags_input'] = array('tag1', 'tag2');" t6 \- R) F( ^% @$ o5 e
- //$my_post['post_status'] = 'future';
# L; K! u7 q+ \9 T- N - ////$my_post['post_date'] = '2010-07-04 16:20:03';
! i' e1 R( R% G5 c4 Y - . ~- o) e# a8 a
- // Insert the post into the database( v) o m0 l: {" T
- $ret = wp_insert_post( $my_post );
" r7 K$ d2 k+ f - echo $ret;7 {9 y: p% U$ t+ g
- ?>
" y/ j- X0 }: ^" Y; z" [/ t2 r
复制代码 我自己写的7 f- _; ]$ h; d* y9 I- e
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|