|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 \( M; y7 P% H8 F F- E R8 N
+ T" P% G& e0 [( F- S) O5 k$ U
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% l" N, X0 C0 c$ z$ T$ G& R8 Y. z I* t- U4 C" _. p! p/ m: d+ [
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了. ^* Q, I7 |& [6 M H# o' ~
! j# S, _# O) E! w# H/ [7 @
方便实用 简单 何乐而不用呢
) Z, ~6 R; G, z) d- <?php
+ U! e' B) q( [, e - ! g6 g# H9 ~; {& X: d
- define( 'ABSPATH', dirname(__FILE__) . '/' );2 L9 @4 S. x& T; I+ w) p
- require_once( ABSPATH . 'wp-config.php' );, n# \1 v$ N4 T( M9 T$ ^
- require_once( ABSPATH . 'wp-settings.php' );8 _; B8 O9 A* \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 T K7 t& H( W; d7 }, { - require_once( ABSPATH . 'wp-includes/functions.php' );5 T Y- t( L z+ w+ s# f- `
- require_once( ABSPATH . 'wp-includes/plugin.php' );: Z. i' \3 V$ R, {5 A$ f6 `
- $title = $_POST["title"];% r+ I& `! x2 a i. d
- $content = $_POST["content"];5 b- Y' N3 a% M# {( t: |
- $tags = explode("_",$_POST["tags"]);! h9 }. P0 [' F( y, g. Y
- $cate = $_POST["cate"];! g4 O/ ~$ O* C u* D
- //print_r $tags;
3 f0 C+ G$ }/ h0 s - //
* y& G- f8 I$ w - //; n) A" z0 a ~3 @3 _
- $wp = new WP();" z$ n8 Z' K3 Q1 a7 V6 |- b! t- O
- $wp->main();2 u! i6 B+ _( _1 \- M0 P% d
- //' I( d4 ~2 n$ I
- $my_post = array();4 w- H1 V* C$ {0 @- P
- $my_post['post_title'] = $title;$ o0 l; x3 F$ Q: P
- $my_post['post_content'] = $content;
2 A2 g# a/ H1 r4 i, J - $my_post['post_status'] = 'publish';
( B+ E: j, x+ H* {* [4 [2 q. r - $my_post['post_author'] = 1;# y$ L8 e" p( a; z2 l
- $my_post['post_category'] = array($cate);) b( E6 u, R- H3 E/ t
- $my_post['tags_input'] = $tags;8 X, L$ W: _; ?/ |# F# i
- //$my_post['tags_input'] = array('tag1', 'tag2');
2 H `* w; W. ?2 \4 p1 [* G - //$my_post['post_status'] = 'future';1 N7 ~! _3 x2 u# R
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ m7 p4 P4 ?( d) D/ W& L4 G6 T: |
- 2 T( U" T- u# |1 ~% i, W
- // Insert the post into the database
3 `+ |- F- X" G* t1 g' g! ]5 ]% ? - $ret = wp_insert_post( $my_post );0 R& x" H3 s, |4 p I0 N
- echo $ret;0 N% o4 ]# r! x- b" c _# q8 c# M$ @
- ?>
9 {% o2 e, H' T# s+ \
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ! Y. D: m& m! g+ X
- <?php
: i1 i; h+ _! _% @! B6 Y: \ - define( 'ABSPATH', dirname(__FILE__) . '/' );
6 g6 s$ ?) E1 E) m' c9 m( z6 u$ _; e - require_once( ABSPATH . 'wp-config.php' );, t' U6 G f- ?4 K7 b8 B3 A
- require_once( ABSPATH . 'wp-settings.php' );5 Q# y$ W% ^1 Y: {6 I
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) F5 U1 Z4 h3 ` - require_once( ABSPATH . 'wp-includes/functions.php' );
* x& O+ @4 Z7 r0 J1 M$ n( {4 k - require_once( ABSPATH . 'wp-includes/plugin.php' );
8 Z# y Q& @) b" N* Q9 P - $pic_name = $_POST["pic_name"];
: z6 R' c7 ?, v! k. G+ f- a - $pic = $_POST["pic"];" ~4 |( K" ^5 s. k: g* D
- if($pic != "" && $pic_name != ""). a8 u8 P2 @4 A9 r" k7 g
- {/ _. ^0 V+ \+ F7 Y
- $path = "images/";
; V) ]3 ~7 P0 [1 Y' l* F2 E3 r* b - $pic_name = $path.$pic_name;; b, K1 f9 I, p. i2 y1 X
- echo $pic_name;
. n7 j2 T; l! {. A$ S/ w - echo "||";
7 M7 M2 i1 Y5 `: h - error_reporting(0);9 f9 M6 K, R! Z! o1 |6 A
- mkdir("images");
/ ~, J! q* P8 W - $handle = fopen($pic_name, 'w');
" l/ S: h& n8 f' i% [6 M - echo fwrite($handle,file_get_contents($pic));3 [+ Z- N! z! a* p X, { b* m
- }; l8 Z, _4 U' B B- \) L1 v" I; H# j
: n x* }: E' z1 h- w- $title = $_POST["title"];
6 o L/ e# @. B - $content = $_POST["content"];
5 P$ q0 ]. q7 A; A - $tags = explode("_",$_POST["tags"]);% z' }8 |( F( B E- V- s' U% ^
- $cate = $_POST["cate"];$ J% g- {+ i+ a$ q" U4 P" g2 e
- //print_r $tags;) V# ^+ Y; _& P6 O$ e
- //( s7 \: f' \4 R- G8 b8 w
- //
, _* J8 x2 H0 a, [4 g - $wp = new WP();0 M, o; P( l7 k
- $wp->main();
1 d4 C$ L! c& z8 r1 p# u - //
9 d7 }6 l8 [7 e' }% X5 o+ U - $my_post = array();2 t5 s+ E/ r; M- c: S
- $my_post['post_title'] = $title;# N1 q6 C t& a' d6 y! Y6 V
- $my_post['post_content'] = $content;5 {) L3 j) h2 g. p
- $my_post['post_status'] = 'publish';1 u' ?$ Z5 ~% c" { {
- $my_post['post_author'] = 1;
; P1 I6 ]* F3 |: f: o - $my_post['post_category'] = array($cate);
$ L1 J3 O* d& D0 R) q - $my_post['tags_input'] = $tags;
$ m: ^1 g, L! ~2 R1 I8 Q) A2 ~ - //$my_post['tags_input'] = array('tag1', 'tag2');7 D) Y: ]1 R, n, p
- //$my_post['post_status'] = 'future';
+ l$ @( a! C7 r: Q6 @ - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ U$ z1 _( F* ] c9 ~
: u4 X9 }- M' y0 a9 J1 N- // Insert the post into the database
( s! P. h3 \# t! u - $ret = wp_insert_post( $my_post );& ~( T) d, P* X: `4 |* G2 }% [
- echo $ret;
8 d1 F. ?) r2 V2 {* |7 H' m - ?>
) `& P& s" H. t2 l% x G
复制代码 我自己写的
/ p7 U$ ? I) s9 \. ]5 N2 l插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|