|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
0 c; n- n8 S* s+ S2 Z% p7 r! l0 C1 `- C& o6 |* K0 G: @
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
/ K7 c0 C6 t' y% h; W7 G% J
" ?, A9 r6 M) D+ W: n! f }我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 H6 p9 E$ u7 h) s- Q; n9 b4 [
( r: q: _% q% W# R! t方便实用 简单 何乐而不用呢
8 f1 f8 q3 s) k& \ z- <?php
. y ?4 P, A4 }! W$ G" A
) d# \% y$ h- g) E+ U- o- define( 'ABSPATH', dirname(__FILE__) . '/' );: Y+ O' Y z2 \" L( |9 B$ P H
- require_once( ABSPATH . 'wp-config.php' );& z7 t3 w. j: ?) {0 D
- require_once( ABSPATH . 'wp-settings.php' );
3 J k. |# R3 I0 W6 w! L - require_once( ABSPATH . 'wp-includes/class-wp.php' );- N/ x+ W, ^5 Y
- require_once( ABSPATH . 'wp-includes/functions.php' );% x/ k5 q5 Z1 q5 x' q
- require_once( ABSPATH . 'wp-includes/plugin.php' );; F+ Y" ]: x7 Z; F" t X% l
- $title = $_POST["title"];; a; c1 L8 u/ h0 x9 c; E. d
- $content = $_POST["content"];
3 z, L8 B8 m7 ]/ M+ ? - $tags = explode("_",$_POST["tags"]);. c' @/ V. ^1 P: w9 R
- $cate = $_POST["cate"];! {7 _+ m3 O5 ^/ t* e
- //print_r $tags;$ M2 F* ~% r z0 U1 e
- //
/ H0 {/ P) H' s3 }/ W - //8 v% Y. R0 ~! s. F# {
- $wp = new WP();; N2 i0 n, Y& p* m/ ^, j9 L
- $wp->main();
8 W. g( F9 j9 s: c D, }9 Y4 X - //& X' u3 T3 j/ V# B( S6 K! m
- $my_post = array();
, |$ z6 ? |! B' J - $my_post['post_title'] = $title;% ~+ x$ w% R. `9 B0 z
- $my_post['post_content'] = $content;
k8 k5 f! j6 v3 f1 O7 V - $my_post['post_status'] = 'publish';
4 J9 f8 l* ? f! C5 K - $my_post['post_author'] = 1;
( z4 R5 ` B3 ^" F( I - $my_post['post_category'] = array($cate);
1 K+ T3 a$ [( F( v, X - $my_post['tags_input'] = $tags;! ]( k% [4 p6 V# b) d) f- ^# G
- //$my_post['tags_input'] = array('tag1', 'tag2');1 ]5 H( I |/ h
- //$my_post['post_status'] = 'future';
( M+ A" W A4 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';- g. q, X/ {3 ]0 u, T! o9 ^) L
- : y3 H7 p9 G) W4 o' m
- // Insert the post into the database
) m3 @6 y8 |, A/ o9 \ - $ret = wp_insert_post( $my_post );0 G z; F( b _' r% @. r
- echo $ret;
% _2 ` l2 U( R4 N) z& S+ W - ?>
_" ?. g. \5 J% a; Q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
5 c( A; _; b z& A/ M- <?php2 Q7 q6 M) \$ t; ]% ?; q) S
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 Q ^- e0 C- k& i - require_once( ABSPATH . 'wp-config.php' );
) @3 {" m9 U- K - require_once( ABSPATH . 'wp-settings.php' );
6 B! X9 C9 @7 O* ?/ t( a* M - require_once( ABSPATH . 'wp-includes/class-wp.php' );6 E# X9 f- a! q( X& Y
- require_once( ABSPATH . 'wp-includes/functions.php' );+ L7 O+ W+ P8 g P
- require_once( ABSPATH . 'wp-includes/plugin.php' );1 p. w6 V1 V$ t1 u- Q i! f% b" K
- $pic_name = $_POST["pic_name"];( x- ^! n* P" N# H0 l
- $pic = $_POST["pic"];
) _+ H' B+ S- Y$ Y$ A) J - if($pic != "" && $pic_name != "")
1 L# E7 m9 A8 G. c5 ~) s - {
; C9 _7 a$ Z9 I& R; f" U- |$ Q/ ] - $path = "images/";3 N/ ^* L7 L7 {- N- a, A, d+ S. K
- $pic_name = $path.$pic_name;
# k2 M( q2 K# d) f( n+ j3 t - echo $pic_name;5 j6 y) e* {, X4 N; E
- echo "||";
* P- f- F; S! ]" e8 e3 D - error_reporting(0);
3 b$ Z8 s0 w% ~3 f' }0 k - mkdir("images");
1 ]+ ^/ M: ?8 g$ Z) A - $handle = fopen($pic_name, 'w');+ j' \ N% c& f, u+ Q& R- ~$ f0 M
- echo fwrite($handle,file_get_contents($pic));6 K4 e4 |; I+ r7 |& s8 F
- }. w% ^8 Z8 G( v$ o9 T
% q( f) H! h [- $title = $_POST["title"];8 e" F3 w/ y/ e% r W; Q7 O# s
- $content = $_POST["content"];% B1 s! O" n K. r) ]; j4 o
- $tags = explode("_",$_POST["tags"]);, X+ F8 w" r) r; W# o$ Y8 }
- $cate = $_POST["cate"];
7 H/ l' L z' h& i - //print_r $tags;3 g/ @8 \7 ~( C
- //( w7 @+ A1 q+ ^
- //* Q$ i" P; w" g! {/ S
- $wp = new WP();( L! a# ^+ O1 @: |4 l) A' l
- $wp->main();
# \+ h" ]- q( O4 n/ m a - //
5 l+ |3 z# e9 m+ X. f" y - $my_post = array();) q' `5 I9 U! T% n7 n" }% @ J- J; P
- $my_post['post_title'] = $title;
! |: j4 d' ~1 b7 w5 Q - $my_post['post_content'] = $content;
9 c1 L0 ]' P+ n8 A3 k, d/ i - $my_post['post_status'] = 'publish';* X' v3 {2 W) N6 `8 N
- $my_post['post_author'] = 1;
$ c* K& }( L* j# q - $my_post['post_category'] = array($cate);
# A2 X/ }* ]- N - $my_post['tags_input'] = $tags;% g; \/ W5 k2 E7 G: f# b; ^
- //$my_post['tags_input'] = array('tag1', 'tag2');$ K; I' L1 A, j N5 s, z5 A
- //$my_post['post_status'] = 'future';
# r# b+ b2 H) B( Q4 E! R# G - ////$my_post['post_date'] = '2010-07-04 16:20:03';* e0 L* m4 R$ b1 q
9 z2 r; _& C; O0 W6 O# l- // Insert the post into the database
% Z2 Z: J. u& z2 x9 Q6 D1 Z - $ret = wp_insert_post( $my_post );: n, j, F( E8 H5 v0 N' Z+ p
- echo $ret;+ Y, Q& `2 ~0 N4 d
- ?>
_/ F- M5 c: L2 ~" r
复制代码 我自己写的
2 |+ w. N: C, f9 _ g插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|