|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
& b- h. G& m# r1 ]" t9 R' Y" M/ S, t/ q1 h# \; z' w! {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持" u* D* A/ a6 e% C) ~. T1 ]* y
& P" V2 F% D7 J8 h9 e7 J8 m: v我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# v' p0 q. W8 w
7 I/ @* Y( a/ q* f% O方便实用 简单 何乐而不用呢- / p2 D0 Z3 y9 p$ r# {8 Y
- <?php' j! L3 H1 Q& ?, {# I d2 o9 D' Z
% P9 a7 ?' s- L! R$ O2 ?- define( 'ABSPATH', dirname(__FILE__) . '/' );
- e! |/ k3 Z) W [5 m2 d+ p - require_once( ABSPATH . 'wp-config.php' );; q8 v1 i, z8 {, k5 l/ a
- require_once( ABSPATH . 'wp-settings.php' );5 J9 l6 O+ ^0 O& _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );. S2 Z/ f- B8 E5 Z( H$ f9 I
- require_once( ABSPATH . 'wp-includes/functions.php' );5 l5 [* f6 E _. O7 a: e
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" K' `0 n# Q; S) S8 e7 X - $title = $_POST["title"];
* j/ q i' f! A - $content = $_POST["content"];
|4 U: ? ?; R: x# i0 z0 b - $tags = explode("_",$_POST["tags"]);
2 _5 l3 \+ g" P+ c E5 R - $cate = $_POST["cate"];' q2 D$ A1 N. c! W
- //print_r $tags;
: K+ o1 c1 r9 v6 u& q1 ]0 Q6 q - //6 o. \ x D: X2 U: ~
- //
5 [3 c* ~$ K2 n; k T% A& M - $wp = new WP();4 Q; D; y' I( ^6 O# K- ?
- $wp->main();' d6 k8 M% b! @& B
- //" _' u0 Z4 w& @! c" e! N
- $my_post = array();
; B, Q, A2 {5 y4 X( r - $my_post['post_title'] = $title;
5 Q" c2 @+ c% c6 b. M* Z2 v' e4 Q2 z/ { - $my_post['post_content'] = $content;
4 M/ c% ^% O' y1 f' E2 f* | - $my_post['post_status'] = 'publish';
9 C& V, ~5 a ^, q4 j - $my_post['post_author'] = 1;
: Y( `( Z3 g* _5 ^ - $my_post['post_category'] = array($cate);1 z1 F* R+ f( ?% C+ }
- $my_post['tags_input'] = $tags;9 c% X. M& M T) R8 h9 ]% |1 }6 f% W
- //$my_post['tags_input'] = array('tag1', 'tag2');
, s1 W$ W2 B. H/ [( t2 |2 V. E, L - //$my_post['post_status'] = 'future';
. @5 [: G$ M2 s* i( g; h - ////$my_post['post_date'] = '2010-07-04 16:20:03';5 E& m/ c2 z3 E# C/ A9 c3 K
4 c( F% [0 M2 f L% O- // Insert the post into the database, D r3 L: o5 c: D$ B
- $ret = wp_insert_post( $my_post );( @; v! k" y. B# k
- echo $ret;# c# y, b4 }2 i8 k
- ?>
: b" I5 U! B- m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- * p; e* ^/ A* i1 x7 U& @# G% t
- <?php
) w. R6 O' m7 s# t9 s1 k - define( 'ABSPATH', dirname(__FILE__) . '/' );
2 \0 s: I9 S* H' c" h - require_once( ABSPATH . 'wp-config.php' ); }0 q" Y( {% R3 q$ t+ {* |
- require_once( ABSPATH . 'wp-settings.php' );6 ] i- N; G5 p2 j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );3 j0 r' t" J- y' z0 D; L
- require_once( ABSPATH . 'wp-includes/functions.php' );
' i9 Y9 i+ N1 j# b7 V - require_once( ABSPATH . 'wp-includes/plugin.php' );4 E% C+ N$ O+ r
- $pic_name = $_POST["pic_name"];
) ^# G$ y! W& y+ W8 O, d( ^- i - $pic = $_POST["pic"];
* b4 _9 l& D: |: f% Z7 p$ H0 G& T - if($pic != "" && $pic_name != "")1 H' ~( I; X% x) o
- {
9 {' j+ F0 i0 G* v/ b. j - $path = "images/";" C5 G3 M7 _9 A+ u2 Z$ W$ O
- $pic_name = $path.$pic_name;
! A" e0 e+ R" | I - echo $pic_name;
# `- [9 m0 n E - echo "||";
! K/ i$ k. D% V- x; L% p - error_reporting(0);
) y6 s4 W0 X% z* N1 c - mkdir("images");# ^) y) z0 }6 H4 @1 l' R. [+ s
- $handle = fopen($pic_name, 'w');
( H$ m% Z, p6 [' W - echo fwrite($handle,file_get_contents($pic));" ~& u- \ ^. o
- }6 z& K0 ~2 }7 \" t
- 8 r: d- v: t2 P& s* z: F C
- $title = $_POST["title"];$ \- U2 J+ B, w6 X* D* L7 L
- $content = $_POST["content"];
, U2 q5 Y$ u/ U! i7 f0 m - $tags = explode("_",$_POST["tags"]);
; S* _0 v( o* f( l - $cate = $_POST["cate"];/ b1 O0 u3 Q0 R( \- T. c. Q
- //print_r $tags;
0 j6 g! ?+ y1 J( B" X! h3 h8 C% K - //
6 t2 r3 l* d; A0 T - //
/ d$ ?. }! S* Z6 H% | - $wp = new WP();
! g4 D1 z7 `3 e' G3 j% ~ - $wp->main();
5 z2 }" M) ]: C( m - //
0 G5 q! Y0 a* b/ u u4 X - $my_post = array();
" Q6 P+ } R: |8 c5 t, s+ n - $my_post['post_title'] = $title;
& J! o9 }: @0 g* } - $my_post['post_content'] = $content;8 `! D6 S! L+ s( U: @3 h, U7 k
- $my_post['post_status'] = 'publish';
/ |/ O+ U& g9 L - $my_post['post_author'] = 1;
! D- [8 p) w0 k) Q - $my_post['post_category'] = array($cate);& p4 V: Z' X7 s& e# l& r. Z
- $my_post['tags_input'] = $tags;, x% ^+ i1 i" G) W+ O8 \
- //$my_post['tags_input'] = array('tag1', 'tag2');
5 u0 E/ u" v* M: B8 Z) N0 r - //$my_post['post_status'] = 'future';, R5 W: W; {) m# @
- ////$my_post['post_date'] = '2010-07-04 16:20:03';& C% {1 k7 }& {5 W9 |. T4 N7 \, {
- 4 J) R# H# G: D( S3 {
- // Insert the post into the database$ ?) e, A( o, A( X( ^* D! |( ^# D W
- $ret = wp_insert_post( $my_post );( _ z0 t4 L' U. q/ v+ o
- echo $ret;3 c7 {- }' ]" D' Q8 @& s: J- z
- ?>& P; l% H. h( l$ H, D$ o1 f
复制代码 我自己写的
1 U& h" Z: v+ r i插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|