|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
+ v1 S- o3 Z, V1 ]! s# n n4 |, {- k3 ?
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
: h5 o2 I' i# T3 |: J( J7 A
?. M0 e* S( A$ L$ P, s$ }" ~7 I0 ~+ ~我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
1 j& v, E# d% B5 p' \: p
- }3 a; }& B6 J# T: i: @. @# l方便实用 简单 何乐而不用呢
; Q) e1 m* ] P- I4 _; E7 w- <?php
" U6 @* B. C1 P# m( B7 A
# [4 t$ \6 }) V$ N- |! Q( R6 C- define( 'ABSPATH', dirname(__FILE__) . '/' );/ y s; b$ {. w4 S, G
- require_once( ABSPATH . 'wp-config.php' );
' |" b6 w1 w% {2 k8 ^8 ] - require_once( ABSPATH . 'wp-settings.php' );& X* H8 B, j( |) o
- require_once( ABSPATH . 'wp-includes/class-wp.php' );; B# _' T" o8 J t0 ^/ a$ N
- require_once( ABSPATH . 'wp-includes/functions.php' );& y! B. R9 K6 u! ~; \! E% m
- require_once( ABSPATH . 'wp-includes/plugin.php' );) [ ^- Q- T4 U- A2 i8 [
- $title = $_POST["title"];: m, p+ L5 ?6 ]2 e% v2 I
- $content = $_POST["content"];
! g! e6 _$ P- O; W - $tags = explode("_",$_POST["tags"]);; z8 a3 R4 X- Y" ^) r
- $cate = $_POST["cate"];( t3 l& q6 u% F9 R6 |2 D9 C# z
- //print_r $tags;
5 A; _( G9 S2 D - //* a! S) k; ]" f B0 n, c1 g
- //
; ?: a2 B- r5 i: n - $wp = new WP();
( N2 V" }4 ]# E1 h4 U% ^ - $wp->main();
4 l2 `' D: M. n6 W7 h- b8 Z2 |9 L! X0 x( u - //
3 X0 t) @1 e2 ?3 K8 ~( N - $my_post = array();9 K3 g0 B5 t; p
- $my_post['post_title'] = $title;3 J) c( O3 Z+ \4 [$ ?3 s* [" a
- $my_post['post_content'] = $content;( B& y, b% }, T! @5 C0 Y, S
- $my_post['post_status'] = 'publish';; g& R7 x- J2 n/ V7 T8 m5 Y9 ]' r
- $my_post['post_author'] = 1;
& y/ h0 v/ A9 H# m% g3 F' p - $my_post['post_category'] = array($cate);6 `# E: `: F% E1 b# D& t
- $my_post['tags_input'] = $tags;
- o5 g( P( ^2 |* R" v$ r - //$my_post['tags_input'] = array('tag1', 'tag2');' P x; l6 I* G$ v! {1 E# U- W
- //$my_post['post_status'] = 'future';
( V) {; `4 s; X2 q# o+ p - ////$my_post['post_date'] = '2010-07-04 16:20:03';% ^1 `; f- ~4 [2 b% n, D
) W+ Q& A5 s+ R, M% e6 t- // Insert the post into the database1 b6 i* |, g& @9 t' W
- $ret = wp_insert_post( $my_post );
# b s/ [- y) ^0 g( x - echo $ret;
8 m6 C8 N5 K4 n( ^$ ^ - ?>5 u$ J% D- K2 Z, I. x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
& ~2 t% i! a$ }+ ^6 s& d! C- <?php
+ R- |7 }) L0 b( g2 p# [" F& ` - define( 'ABSPATH', dirname(__FILE__) . '/' );
9 J% x p3 R- g9 Z( g6 Z - require_once( ABSPATH . 'wp-config.php' );1 Q. j5 W( i* I' g/ q
- require_once( ABSPATH . 'wp-settings.php' );* W% I9 J, v" ?$ {
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ c) N3 v" N: C - require_once( ABSPATH . 'wp-includes/functions.php' );
" T/ R$ E# A; ^, @ - require_once( ABSPATH . 'wp-includes/plugin.php' );
) M! D! R# W/ T; o7 s) d - $pic_name = $_POST["pic_name"];) I9 ~. K. j- n' M
- $pic = $_POST["pic"];
# y- }- e' i% ]2 W- G2 F. S+ [. ~ - if($pic != "" && $pic_name != "")% u! F% J9 u* l* i+ C2 X
- {
9 [; R% H* x2 Y# n1 g/ e8 g - $path = "images/";
0 j F. H& G+ @" ^: v; N - $pic_name = $path.$pic_name;4 ^# a# V! C/ y
- echo $pic_name;' v6 ~+ F, W7 i0 t' X
- echo "||";# }. X- l" ]7 R: y$ H4 {
- error_reporting(0);, W( D8 O7 }0 d
- mkdir("images");2 i. b/ i* A3 ?6 {* l6 @" o% k( H
- $handle = fopen($pic_name, 'w');
8 S7 J0 M r9 ^3 N9 {2 b |& e - echo fwrite($handle,file_get_contents($pic));
4 V, }6 N. V( |4 V. ]3 s - }
1 {) A$ Z7 [5 v+ P ~) f - % l6 p6 l; h& A0 V( N/ O# L! B
- $title = $_POST["title"];
% u9 G9 L& a2 z& M9 K - $content = $_POST["content"];
% y# } n$ t& n, D c5 v - $tags = explode("_",$_POST["tags"]);; Y! O3 t& q( _7 @( B+ Y3 T3 p4 T1 D
- $cate = $_POST["cate"];
2 x, J5 R- s5 b, {2 H6 P4 ] - //print_r $tags;
: Y" U. S7 ]+ T6 y - //8 g2 a6 g3 e9 C: V
- //
/ y+ k- R: t* ?: h4 Y2 p - $wp = new WP();2 x" ]( V0 R9 k0 v* c) [
- $wp->main();
2 i- ]% y- l! J8 A - //
/ l: ~" c( b2 m4 _ - $my_post = array();
% K6 b3 P0 O2 B2 R K4 m - $my_post['post_title'] = $title;- `+ `1 M( e5 M2 q# R7 B3 X4 ^
- $my_post['post_content'] = $content;
}7 Y& T# M; G1 P. | - $my_post['post_status'] = 'publish';
6 K- i% w& u- [9 L* K - $my_post['post_author'] = 1;% w% }) z- c. U2 f* h6 q; I T
- $my_post['post_category'] = array($cate);% g5 H/ b# a! ]' t1 Z% g
- $my_post['tags_input'] = $tags;( U; _# T- K1 _
- //$my_post['tags_input'] = array('tag1', 'tag2');( `. z) b8 f( F J
- //$my_post['post_status'] = 'future';
$ r( Q9 ~( m& a7 | - ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ H8 v2 I% \' C+ t - % d& T, B1 U4 b: J
- // Insert the post into the database
$ @: y/ M& m2 b) R2 g3 C - $ret = wp_insert_post( $my_post );
/ {5 Q$ G. i% X0 z. @* g% ]$ p# T, S - echo $ret;
+ s6 w" w0 Z9 R3 R) f - ?>0 A* ^' y( ?9 }& C8 j+ q7 z* _
复制代码 我自己写的' F: W4 y: B0 Z
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|