|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
4 U/ u! R w! _* K) E& e
4 e( O% [, S" E; [3 @" R o- o直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持/ q- R' _; ~: I6 h; C
4 R) n: w9 L1 V; n! L: Z. Y3 I
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 y/ b( r& Z0 F% {
% I$ _7 F9 F& a( c* F) ]/ _方便实用 简单 何乐而不用呢- % P9 G! A: G' w
- <?php
/ Z$ @* i) j0 g. R2 F# B+ K$ g
0 V* Q+ e' X6 \, ]! Z9 Y- define( 'ABSPATH', dirname(__FILE__) . '/' );/ V( c5 T( n, U( ?5 E2 C6 n8 s
- require_once( ABSPATH . 'wp-config.php' );+ d+ `/ v6 O8 Z+ p
- require_once( ABSPATH . 'wp-settings.php' );
: F& ?5 `& s+ ^7 b - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 D1 ?2 w; K4 r5 }# j" g: N% v - require_once( ABSPATH . 'wp-includes/functions.php' );0 v7 _; S, P7 @. m! |! j/ G
- require_once( ABSPATH . 'wp-includes/plugin.php' ); Q b' A7 h# v: H) ?6 g2 x, w
- $title = $_POST["title"];& L) M0 X" G. {) {1 r& f V0 S
- $content = $_POST["content"];
+ E! b1 P( t ?* G( E2 z - $tags = explode("_",$_POST["tags"]);2 s2 C# \) {9 Y+ R' ^
- $cate = $_POST["cate"];1 @! _. a7 D- s% U/ D6 k; U y
- //print_r $tags;' _; A. G. b- h- ~+ q4 B, R- W
- //6 r2 M2 a, }, C- m) d" s3 a0 E
- //1 G$ s9 ?2 t1 a
- $wp = new WP();9 H' R# V- T N' K
- $wp->main();" Z1 ^! c a3 P+ F: f/ ^
- //
2 f* f# [. q& Y9 g& N! X6 v, T9 u2 k - $my_post = array();7 Q1 E) u; B6 a+ `0 x$ B0 D% G
- $my_post['post_title'] = $title;& l: H: Q( B2 P
- $my_post['post_content'] = $content;
5 u. ^4 H! S$ W% n( Z9 m - $my_post['post_status'] = 'publish';% K: Y, T5 |$ D: m/ F, x1 N/ e
- $my_post['post_author'] = 1;' K1 s, d& O3 @3 v
- $my_post['post_category'] = array($cate);$ W p! ^! X C$ V& S% x; Q
- $my_post['tags_input'] = $tags;
& T$ u! z. _+ i4 `7 _6 C, B/ @' v! } - //$my_post['tags_input'] = array('tag1', 'tag2');
_8 Q; J* K: {' p8 ~8 @0 ?- X+ | - //$my_post['post_status'] = 'future';
1 u9 T4 y' T) P+ O, R$ c$ i - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( |% }: k7 L: v/ m | P8 e1 H
: M1 K' b2 a- R4 X1 S2 w1 }. K- // Insert the post into the database
* N! F# ]: v7 R) q1 I# K3 _' o - $ret = wp_insert_post( $my_post );- v% D; m% X) [! W+ S4 O/ L+ J
- echo $ret;2 ^- u" @/ J- | L7 X
- ?>
: u6 V( \/ ?9 L6 @$ P
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 6 w6 b5 \# i2 L; q; h
- <?php
0 x L k0 W/ h X# k- H4 L - define( 'ABSPATH', dirname(__FILE__) . '/' );9 Z% K J. x$ |' Q% B7 h
- require_once( ABSPATH . 'wp-config.php' );* C. G! L& Z' }; `; U) G
- require_once( ABSPATH . 'wp-settings.php' );
& W) {; Z" u3 Y& [8 T - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 W2 W/ g, i4 j2 ]) u5 ?
- require_once( ABSPATH . 'wp-includes/functions.php' );$ _; N4 H, l' ]/ V( N
- require_once( ABSPATH . 'wp-includes/plugin.php' );
, h. x+ \; b" ~! H2 v7 m: R5 c" N - $pic_name = $_POST["pic_name"];
' b+ ^3 y6 R% y( D7 d# _$ S0 B - $pic = $_POST["pic"];
# \% c1 q* W; o! W6 I - if($pic != "" && $pic_name != "")" J) D. F" F9 p9 A
- {
% w; E0 E+ O$ S; C# U2 z' g6 D8 j - $path = "images/";( S4 Z. K! f5 {. [- t+ }
- $pic_name = $path.$pic_name;
" n: b( N+ W+ a4 q X - echo $pic_name;
6 L7 }/ _" Z, c - echo "||";
: _# I/ b9 u+ ? Y9 V% N _. e - error_reporting(0);! l4 c$ W( v- x' K) p. c3 W
- mkdir("images");; v: B* S- u2 `8 C8 j0 `
- $handle = fopen($pic_name, 'w');0 Y+ T! E1 `2 [: |- Y% ` d5 P
- echo fwrite($handle,file_get_contents($pic));. k- x' A# Q$ G* F& e, e9 a8 V
- }
4 t/ d+ J" E0 P# B9 I! w
* z3 M2 m- _5 z- G/ B- $title = $_POST["title"];
, g, [' S& t3 J/ j - $content = $_POST["content"];
% t/ a4 Y3 k8 O' U7 ?+ p - $tags = explode("_",$_POST["tags"]);
2 r$ \: [* j" |. q - $cate = $_POST["cate"];
" o& d; i( T/ w7 a! d) ? - //print_r $tags;
5 K! b3 W1 I" J- r& @, u - //
3 p8 R, r" ^% Z2 b - //
: |# n4 K/ {; }0 Q7 a- [. o - $wp = new WP();
6 v5 s+ c, Z1 O1 v3 N l0 { - $wp->main();0 `5 G" }; t* L0 c& w
- //* l( Q3 Q# H3 M- ~6 Z/ V
- $my_post = array();0 V6 o/ G8 ]3 s0 G7 f, Y& E- Y
- $my_post['post_title'] = $title;
1 c! u& \! v6 W9 b3 m2 p - $my_post['post_content'] = $content;
- i5 l0 f. C+ ~/ n" M1 ` - $my_post['post_status'] = 'publish';
2 V7 ]6 E3 }8 ]8 \4 l8 a: h, ` - $my_post['post_author'] = 1;) f f* Q/ F7 d/ P. ^7 I' h% ]
- $my_post['post_category'] = array($cate);
) I% l7 V. D: R/ V' h( p$ {3 E7 y - $my_post['tags_input'] = $tags;
T8 L/ S5 P- S+ L, o, e7 h - //$my_post['tags_input'] = array('tag1', 'tag2');
! ?0 E$ t! S" m* a# F: k, F - //$my_post['post_status'] = 'future';- `5 U2 ?$ K. C! _2 w- C7 ^* b4 L/ Y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 y( u% o7 x' \' y: L6 g - / M; C; q* m1 \2 f
- // Insert the post into the database' u% R1 g. V' I" D
- $ret = wp_insert_post( $my_post );! \+ i S, j' |( E. E+ T! O# @
- echo $ret;
7 E5 w' `, _$ t4 l - ?>
* J3 x7 L; k) I- F' U
复制代码 我自己写的
$ K6 F$ q& s0 N2 p8 r. J; p0 u插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|