|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & B3 B2 ~+ `% B& p6 B# H5 B
2 e5 o" J1 c |8 M6 q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持3 w$ e2 `, g) Z* `
8 `4 Q; o; h& a1 F% n
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了* t3 i! R/ x7 ^8 c, e# k+ q( J0 Q
( l& {% r3 x+ M7 c/ W方便实用 简单 何乐而不用呢- , Z4 |3 }/ c9 U$ M. N: Z. K0 {7 a
- <?php
+ Y9 m3 f8 x8 s& F2 t* m8 M8 M
, e6 @) M' |* z1 h3 t- define( 'ABSPATH', dirname(__FILE__) . '/' );( O! j2 X- Z8 L
- require_once( ABSPATH . 'wp-config.php' );
& g6 ?& @, _. ^# w+ k4 A, H - require_once( ABSPATH . 'wp-settings.php' );1 N, ~0 `" j+ [3 R
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ n& |3 Q) O+ I% d) U1 w4 K - require_once( ABSPATH . 'wp-includes/functions.php' );
8 C) P; t$ x# Z$ @% W; q1 f - require_once( ABSPATH . 'wp-includes/plugin.php' );
1 S- y! Y Y% _$ @6 Y - $title = $_POST["title"];- _' _- q( @) \4 K$ Z- l3 C
- $content = $_POST["content"];
" o! H! o- ~% C - $tags = explode("_",$_POST["tags"]);" ], [' `1 J Y8 P2 i/ s' U9 g
- $cate = $_POST["cate"];, k% U' H# y+ E R$ t) N8 A0 U7 i. }
- //print_r $tags;
( {; x1 \" F! S - //) V% C$ f' V! ]2 f; d
- //6 ]1 w9 K3 F* \2 n4 |
- $wp = new WP();
0 E& B$ h1 \, D- z0 h1 Q - $wp->main();6 O8 z, S. n5 N
- //1 Q' ]& v+ v- ^- ~& o, G7 z q
- $my_post = array();4 M, n( U" J* B* b, p
- $my_post['post_title'] = $title;; K p2 Y9 b0 S: s9 d& F
- $my_post['post_content'] = $content;& G+ j! b6 e' b) ?7 d+ r
- $my_post['post_status'] = 'publish';
, c3 x0 l/ |; W( E- Q - $my_post['post_author'] = 1;7 s! z# Y7 Y; ^9 r, c# K2 y& l8 q
- $my_post['post_category'] = array($cate);
9 l, u$ g6 p3 K1 X4 q9 m - $my_post['tags_input'] = $tags;' |' X5 j0 @2 q& ]0 g- { H+ l
- //$my_post['tags_input'] = array('tag1', 'tag2');
- K+ A0 A& U k" a- `4 \ - //$my_post['post_status'] = 'future';
* }6 g' y: |# W' `+ ~+ d - ////$my_post['post_date'] = '2010-07-04 16:20:03';. U, M s% R, U/ u& o- F; ?
! C: p# \: X; J% [* q1 q0 P/ \% ?- // Insert the post into the database9 `! j+ a1 U4 W! e4 I4 v* A1 D
- $ret = wp_insert_post( $my_post );% L6 X9 z" t9 c. E4 Y
- echo $ret;- w3 e+ V4 m. ^! j
- ?>" ~. e5 q1 _; f$ c* @5 x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- " ~, p) k! {" R% ]$ n8 k- ~3 J: A! t
- <?php1 X$ j4 W0 w5 k) J+ j c
- define( 'ABSPATH', dirname(__FILE__) . '/' );
( D$ i6 e5 ^" E; x) u# `# f - require_once( ABSPATH . 'wp-config.php' );! |) B, Y5 p/ q# s- [2 ?0 _
- require_once( ABSPATH . 'wp-settings.php' );
- k8 @: S/ z# v2 ~ - require_once( ABSPATH . 'wp-includes/class-wp.php' );, |( F9 s/ o8 ^( T
- require_once( ABSPATH . 'wp-includes/functions.php' );
. H, u5 M1 V h! t/ F* y# T6 V4 h - require_once( ABSPATH . 'wp-includes/plugin.php' );; g( v" G) G: A' w1 K w
- $pic_name = $_POST["pic_name"];2 k. N$ u) u X; ?0 N4 t8 {, z8 c7 S
- $pic = $_POST["pic"]; L) C8 A% u* {0 m, Y/ k3 n. e
- if($pic != "" && $pic_name != "")
, j7 {) {3 O4 t( e' c# w - {' O7 R# K7 ~# d! q( i8 m
- $path = "images/";
' L5 f7 n5 @' f9 } - $pic_name = $path.$pic_name;
4 `+ Y" l" d1 E# q6 w- J4 d2 H - echo $pic_name;
- N O" f. f; w4 V8 }1 C - echo "||";) C3 C) Q7 c3 {/ ?: ?$ Y1 w+ [0 e
- error_reporting(0);
8 s* [6 P- j0 P3 @; d3 ]6 k; _7 l2 Q - mkdir("images");
) V% G% @3 [% z4 H- X R# p - $handle = fopen($pic_name, 'w');
# C: ?/ ?/ z* C& X - echo fwrite($handle,file_get_contents($pic));& t A/ Y$ Z/ C+ K* ~7 p4 G; t6 {( a
- }0 S0 ~, D4 |9 p2 ]
- ; c9 M! B- U1 [2 l0 E$ {# U( J
- $title = $_POST["title"];; a4 Q% C, I3 a
- $content = $_POST["content"];
. N, d; {5 `$ {8 ^- B; \! t - $tags = explode("_",$_POST["tags"]);. {2 D2 o. L2 N% w( T
- $cate = $_POST["cate"];; s& ?+ V P6 l9 r: Q5 q
- //print_r $tags;: s! v3 Y6 M/ _" y. L: V- C
- //! g8 M/ B/ Z3 x& b! [0 p6 M
- //. ]& F& J& g* `" x4 V! ]: c/ o
- $wp = new WP();* ~8 v! b% q) v% J& B+ @4 }# G
- $wp->main();. s4 E" d/ y- }8 o0 l
- //
& j% e; U/ E5 B6 F - $my_post = array();
7 [3 K- U1 r; g& C8 l; Y: m - $my_post['post_title'] = $title;
0 P6 X6 }) j) Y) ]& f5 } - $my_post['post_content'] = $content;
* v% Z& j+ B9 y. w* ~8 j0 i - $my_post['post_status'] = 'publish';
M7 W/ F/ a3 F H1 l" ^! \ - $my_post['post_author'] = 1;
$ @# a/ N% ?0 p6 p - $my_post['post_category'] = array($cate);
& ]/ U& y9 [8 d- T - $my_post['tags_input'] = $tags;. d# q6 l% s! W k
- //$my_post['tags_input'] = array('tag1', 'tag2');
' N7 S Q U, X* `! c1 \ - //$my_post['post_status'] = 'future';
# P" I+ a1 W& B' M1 R6 L - ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 w5 ]; B- ?+ i; v
* S, [0 X# G8 @; {/ r# q- // Insert the post into the database
& @) ^ s4 u+ K! s - $ret = wp_insert_post( $my_post );
6 U5 f) @/ w/ {! l! X0 S - echo $ret;
# z6 N. y* _7 O: \9 @7 T+ a& @ - ?>
- u, q* x# E4 l8 `$ }7 M5 L, L
复制代码 我自己写的7 r' z# Y& ]1 f1 w# o8 V8 G) W7 U. l( S
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|