|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 D8 u+ @! I6 Q. i9 g
6 |) K4 i- B. F0 l% n v; L* ]直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
Q9 @* [ }/ \: y0 B5 Q! [! V1 @" W) T
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
* K) W' S# j9 |9 v) ]& w0 n3 M8 p* a) {' { z- J" b/ B* |6 B- M6 U
方便实用 简单 何乐而不用呢- T( j" @; i% ?
- <?php9 S$ w1 x" E3 w6 K9 G; k
- , f; _+ T2 J$ b0 X$ Z
- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 j" @+ [0 i- A7 D - require_once( ABSPATH . 'wp-config.php' );
' J, ~& f5 h2 ^( X0 E - require_once( ABSPATH . 'wp-settings.php' );" s) R F, g0 @3 r( V+ H
- require_once( ABSPATH . 'wp-includes/class-wp.php' );* P9 O- b6 B* l! a4 O9 N
- require_once( ABSPATH . 'wp-includes/functions.php' );. V7 [/ s* j! J( m5 M
- require_once( ABSPATH . 'wp-includes/plugin.php' );
, A% g% S! W: R5 {, h; h* L - $title = $_POST["title"];
5 Q; j) Q0 `) e0 T/ N! X# l/ S" W w - $content = $_POST["content"];
/ S+ f( G( V9 Y$ z - $tags = explode("_",$_POST["tags"]);
; t9 W: d+ s6 [ - $cate = $_POST["cate"];/ Y, g! e; S$ u% Q; ^7 e
- //print_r $tags;
+ k) v! {7 `# ]8 T g1 l - //1 ?7 Y+ X1 s; ^, [" V0 C% x) K* [
- //
2 `9 `6 H/ l& W9 k0 t - $wp = new WP();+ P* a* K# k$ J4 t) _3 w9 N
- $wp->main();
1 n( M9 V! P+ {* ~" q - //
- a( k/ ]3 t1 w) H P - $my_post = array();$ j( m D* A. @/ U/ g4 \
- $my_post['post_title'] = $title;
- c# ^; l; W6 Z1 A' \5 Y - $my_post['post_content'] = $content; D9 _' Q# U8 I2 Z6 I" t* N9 }( ]
- $my_post['post_status'] = 'publish';) q4 m# r0 ]3 k* l" d ]
- $my_post['post_author'] = 1;
4 \: V+ w: {# Y7 e5 E2 ? - $my_post['post_category'] = array($cate);$ l; D/ l$ }' G
- $my_post['tags_input'] = $tags; S0 D6 ^# _, i0 a' z0 B. ^
- //$my_post['tags_input'] = array('tag1', 'tag2');# ?+ c; E* k$ o* R5 b J1 B
- //$my_post['post_status'] = 'future';
% I3 I1 s' ~$ f" Y8 u - ////$my_post['post_date'] = '2010-07-04 16:20:03';$ ~$ a, c7 u) I$ M" f0 X
2 Y; q0 e7 k& m0 {2 \- // Insert the post into the database
# `5 ]+ }% G( p0 T6 E( G - $ret = wp_insert_post( $my_post );# T# f& d c5 J% r+ c: g5 p7 C
- echo $ret;0 e' g. X# G( Y5 p" p, j- ]- U
- ?>
/ e+ Z& i6 i7 H& {
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
# G+ }$ U: d+ T* T, P- <?php
1 V( j* }2 v% J: Q5 Q( n8 N. x - define( 'ABSPATH', dirname(__FILE__) . '/' );' c4 L* \9 ^5 k$ {/ o" Q: x- x7 k# T
- require_once( ABSPATH . 'wp-config.php' );7 e; t1 u- j4 ~0 `. ^
- require_once( ABSPATH . 'wp-settings.php' );
4 \, q$ W- v& K8 F9 x8 ` - require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 z+ K, @( R7 ~- ? - require_once( ABSPATH . 'wp-includes/functions.php' );
K! f, S ~5 L2 E) u$ ?; |/ L2 f - require_once( ABSPATH . 'wp-includes/plugin.php' );
; e/ o. E' i9 l, ^# P - $pic_name = $_POST["pic_name"];& N# L1 h2 F: W
- $pic = $_POST["pic"];
( ]9 S9 g/ O5 t P4 W - if($pic != "" && $pic_name != "")' Y' {" E! V( g# ~4 _
- {
' W0 o6 i0 E, n: o# b3 d" K - $path = "images/";
6 q4 {6 M t* g3 k - $pic_name = $path.$pic_name;- J4 i- J2 g) a( \9 ?& n
- echo $pic_name;. O4 _" a$ M W9 `
- echo "||";
7 \+ q8 n" T, \' |" @ - error_reporting(0);# F' }, Y- y$ w k. X
- mkdir("images");
- ~4 `: l% M$ l* p - $handle = fopen($pic_name, 'w');
0 @6 A2 Q7 o+ A+ H% M7 s0 \' z - echo fwrite($handle,file_get_contents($pic));- E, l1 H' F! c& J) k# u
- }4 G- C$ h6 K' v) L6 u& [
! ]( _* o9 z" f- $title = $_POST["title"];
, c6 \! |* A2 V$ I - $content = $_POST["content"];
2 k; i: V8 j4 U5 c4 p - $tags = explode("_",$_POST["tags"]);
5 g, Q1 C7 V7 t; F+ j, Q/ `" X - $cate = $_POST["cate"];2 m: @" ~- ~" i
- //print_r $tags;
7 Z' Q: F( F! t4 H( t- \ - //
$ C8 z }* U/ ~% |' Y0 v @ - //
5 }: k% p' f" L - $wp = new WP();: @6 y: y0 R" z& \ _
- $wp->main();+ }" R/ {3 }7 V( q
- //
/ p( t R( `' n - $my_post = array();
; {) ?" |3 \ u, z. V+ @, L j& r. D - $my_post['post_title'] = $title;
. v4 n1 \. h$ | - $my_post['post_content'] = $content;
u0 ^% |4 P7 n" F- X- Z( o' h) e - $my_post['post_status'] = 'publish';
: _, a/ r1 r9 e: q - $my_post['post_author'] = 1;
$ e/ R. R$ [/ g: i2 j# y4 f - $my_post['post_category'] = array($cate);% P; w' r5 g1 S% l3 l% `4 |$ h8 d
- $my_post['tags_input'] = $tags;
( r) E3 C% X' O! O+ X - //$my_post['tags_input'] = array('tag1', 'tag2');4 e n% Y+ h. ?4 O
- //$my_post['post_status'] = 'future';/ X6 G/ i; n o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- k" A- E3 R% N+ T" Q
- # k9 ~; D; D/ N' O
- // Insert the post into the database
$ Q$ q- r( q& q" _ - $ret = wp_insert_post( $my_post );
5 _8 f9 P& W% C4 H# R! W' ^4 F; S - echo $ret;
1 O$ Z! R5 b7 R0 ] - ?>
& V |! {7 `0 s
复制代码 我自己写的
, X# \2 }: G7 j/ x: s: U3 D& Z插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|