|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 % e3 e$ Q! n1 X& q" h( Z, d( c2 n3 Z4 p5 \
& ]4 U9 @6 q# r5 \4 e0 U+ b
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, b- C/ J8 n' @9 g* ]) m' A0 E
* q3 k/ H. k& j1 V% M/ V我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( m6 x6 `/ S% K
$ Q8 Q8 U( v9 b8 f方便实用 简单 何乐而不用呢
Z# k0 l, y& Z- <?php
|2 d* E% m) N# `5 `9 ~& l - # q8 l' j+ C- w \
- define( 'ABSPATH', dirname(__FILE__) . '/' );' U# Y& H0 F* e, r) a4 E v# l
- require_once( ABSPATH . 'wp-config.php' );, q. I, A* g. t' s. s5 }
- require_once( ABSPATH . 'wp-settings.php' );3 @, J& F: t) g0 @ _2 v( H
- require_once( ABSPATH . 'wp-includes/class-wp.php' );! g: |" c5 W* t" |. C
- require_once( ABSPATH . 'wp-includes/functions.php' );! N9 s, Z. p$ Z6 t! }, M: l
- require_once( ABSPATH . 'wp-includes/plugin.php' );2 ~) _" l F1 e4 z# E1 `
- $title = $_POST["title"];1 ~! V+ _; ~6 f
- $content = $_POST["content"];
" h- P i! S% m& K6 V - $tags = explode("_",$_POST["tags"]);0 l( c8 c. }8 V) ]) {0 T9 V* }
- $cate = $_POST["cate"];
D3 S; O- i; P" q9 j3 a - //print_r $tags;
$ q9 f' S/ I; N& x4 ` - //
# I8 x. E/ @1 g, I5 F2 u - //
" \! H1 e! ~- v3 J% f! s - $wp = new WP();* X0 @; [9 v/ ]' A
- $wp->main();8 c/ o0 O3 ~" B
- //$ t, Y& {7 w. V) @
- $my_post = array();
3 |9 V* [! v9 e7 g+ x5 y - $my_post['post_title'] = $title;& N" U5 W4 n+ E- g8 N+ G( w
- $my_post['post_content'] = $content;/ ~' s7 G- P4 j' U
- $my_post['post_status'] = 'publish';8 F I) v0 ^8 I& z2 m- T- F
- $my_post['post_author'] = 1;
; r+ D, ~/ X7 v4 e - $my_post['post_category'] = array($cate);
+ S+ g: I" I4 l N# V- K - $my_post['tags_input'] = $tags;* p9 q2 {. L# k0 g" ?
- //$my_post['tags_input'] = array('tag1', 'tag2');$ o3 R( H, ^5 c$ [. ~0 G' ^- t/ r
- //$my_post['post_status'] = 'future';
. i; A' ^5 ?" \% m9 I- C0 \" \ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
! a% x- k3 g! y1 {1 \6 O& S5 A1 I - ) |! m3 m+ z7 J
- // Insert the post into the database
/ i( R3 C$ t" T - $ret = wp_insert_post( $my_post );) j7 u4 ^; g) n6 p# H
- echo $ret;. w& B7 U! u3 [. Y% ?
- ?>" D) a; O' x; b* ]9 M! r2 X
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- * T' G: D% d, E$ j9 o
- <?php6 z- ?. ~* _5 v# b- @/ `
- define( 'ABSPATH', dirname(__FILE__) . '/' );7 V# G$ q8 ~9 \) X, T5 t5 O+ y
- require_once( ABSPATH . 'wp-config.php' );
+ v) S' m7 Y6 F: M4 n% H+ h - require_once( ABSPATH . 'wp-settings.php' );
7 p* y" P9 \" \, M" l - require_once( ABSPATH . 'wp-includes/class-wp.php' );: C. x4 N6 e: e, T9 t
- require_once( ABSPATH . 'wp-includes/functions.php' );
6 ^2 m! T7 B* @5 | - require_once( ABSPATH . 'wp-includes/plugin.php' );9 R3 P R% ~& q1 V* u
- $pic_name = $_POST["pic_name"];
0 x- v2 D% R5 P4 m - $pic = $_POST["pic"];, E+ K8 D! S* Q
- if($pic != "" && $pic_name != ""); h/ I6 X0 D( D' M& F( d( O' i) D" u
- {
) v4 `: _+ g8 `* e% O$ Q - $path = "images/";
3 z0 N7 A, {! Q- l - $pic_name = $path.$pic_name;! m9 c+ e' i% v6 j+ g
- echo $pic_name;
- M" F! z; r& w$ b: Z) B: | - echo "||";
" t2 c3 p# ~% d8 {5 A - error_reporting(0);4 k! w( @# Y. d1 \6 m
- mkdir("images");
: w! \: e$ h! O) `& v* @ - $handle = fopen($pic_name, 'w');
& }, k/ W$ I) E7 ?3 }6 X1 T, j% d - echo fwrite($handle,file_get_contents($pic));
% `6 v" O0 n* ]8 `4 D0 l2 A- x. z: L0 F" n - }
, l5 W) S3 R, I9 C) d2 e6 I - ' p) T2 O, z" x6 E1 n
- $title = $_POST["title"];
7 \. z- u- D \! r+ [- ]1 ~ [6 \ - $content = $_POST["content"];
" {& L: P h* K) d9 f1 I* l - $tags = explode("_",$_POST["tags"]);
9 Y, ]3 P& l6 J, |+ d/ d - $cate = $_POST["cate"];
& e. z0 m0 ?+ h" D0 m" j, Q - //print_r $tags;
+ t* R4 ?0 p; n, m% w) g - //
9 ?: t5 U4 C7 L# [$ m3 V( Q2 \ - //
9 T c2 D2 f- m- r- I: X - $wp = new WP();
5 ~# A, c+ |' y; d4 _0 Z A3 ] - $wp->main();
, Z6 W$ f9 U3 M" B0 H) g - //
( y8 L. J* z v8 ?7 j7 F7 Y+ A h8 B - $my_post = array();
: U/ w7 c+ d4 q4 U' S - $my_post['post_title'] = $title;6 l8 c3 n( W. t$ X8 ^
- $my_post['post_content'] = $content;
4 t4 [& ]' q! J( H0 ]( J, ?2 N Y - $my_post['post_status'] = 'publish';5 M! ?; f" P# N4 n; s: v
- $my_post['post_author'] = 1;& S" g7 o2 o& Z$ ?3 {1 C! P, A
- $my_post['post_category'] = array($cate);
! t. k' \0 M. z/ c4 Y: | - $my_post['tags_input'] = $tags;
* W3 z3 m: V8 u* X% m - //$my_post['tags_input'] = array('tag1', 'tag2');$ B4 w- n. }2 R2 h, W
- //$my_post['post_status'] = 'future';
% M2 a: {* w s) E5 e, V6 Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 M$ J' c" E+ H/ Y - ! X4 }2 i7 y* L8 \8 _
- // Insert the post into the database1 I" E& \& p ~5 K" t
- $ret = wp_insert_post( $my_post );
! C$ m; a' Q# l; w, w - echo $ret;7 G' L. _: F+ E
- ?>0 X: m$ ?4 ]( k$ B0 Z! ?! G
复制代码 我自己写的4 s# W" u: C1 U) a; M! \) s: K
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|