|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
0 [3 b4 B- h2 q, ~1 }+ j$ y3 Y4 }
9 A# d& ~0 H! S$ I5 s直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持( u6 }- x4 ` q' D
& u3 x3 v5 @6 Q1 t我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了/ e: y! b( L) d1 L' b) R. r
% `& G9 @: @9 \) H A
方便实用 简单 何乐而不用呢
& M6 _4 j! A d) k" p1 m- <?php/ _# X3 \: n: y' b- s+ D4 z* @
- 7 L; a/ \! e7 g9 \2 q/ J
- define( 'ABSPATH', dirname(__FILE__) . '/' );2 n* v8 g5 T! f& f5 S
- require_once( ABSPATH . 'wp-config.php' );: ~1 x* i# ]/ ^9 B# R: d6 Q
- require_once( ABSPATH . 'wp-settings.php' );
: ?1 r% m2 O: g# [ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, |8 s( E; d/ J& N! f - require_once( ABSPATH . 'wp-includes/functions.php' );
- N X7 \# r3 a0 n - require_once( ABSPATH . 'wp-includes/plugin.php' );
: V0 t" r( ?" f5 X' Z( q! u" u - $title = $_POST["title"];0 ~: { g- r$ M U7 Z( f
- $content = $_POST["content"];7 T( M& x7 C$ q: l/ ?
- $tags = explode("_",$_POST["tags"]);
% D+ a8 A+ _ v- h7 q - $cate = $_POST["cate"];, x- s9 o5 f6 [- c
- //print_r $tags;. P: N& ~6 i$ Z( a9 J" H
- //
1 c+ t2 p$ e* l - //
]2 l; z) i' H v0 } - $wp = new WP();
/ r5 M* A+ h1 \. m- l$ V - $wp->main();
6 S$ ~- Z$ z4 q W9 s - //
! i. [. t! J3 e* H# ^ u - $my_post = array();
+ W. x U4 k5 t% l! r - $my_post['post_title'] = $title;
7 p" U0 b! h& t) J7 W - $my_post['post_content'] = $content;
$ @& E2 q. b2 }1 I, c - $my_post['post_status'] = 'publish';
! G* c" e. K7 ]$ r5 l; c" y3 I - $my_post['post_author'] = 1;8 U E2 @+ U, q9 {9 r" k+ U
- $my_post['post_category'] = array($cate);3 g% b' c# h9 G# F6 @, n L
- $my_post['tags_input'] = $tags;0 [$ k+ }8 [, d4 C7 ?0 ~# Z- v
- //$my_post['tags_input'] = array('tag1', 'tag2');
1 Z' l* @ b+ N9 t* o, L( n) w" N+ Q - //$my_post['post_status'] = 'future';
2 s0 M9 H7 ~( B- t5 o3 x" G1 C: y - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ I% f1 u8 |7 u% `& c. B3 J
M6 @5 i5 k& |5 d- ?- // Insert the post into the database: n Z" S2 ~3 `0 ]
- $ret = wp_insert_post( $my_post );
' L8 Z% i: L' x1 S - echo $ret;9 Z0 y7 N* h6 |" k
- ?>
: B n- ?; j* A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" k5 { k" x6 R3 [$ R- <?php
" w% ?9 ]# [2 R \ - define( 'ABSPATH', dirname(__FILE__) . '/' );
6 O P8 E* w5 g' ]) @4 m! S - require_once( ABSPATH . 'wp-config.php' );
. e% Y l& b$ `5 V. R1 t - require_once( ABSPATH . 'wp-settings.php' );
2 L( k" V: s; D - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, K, c) ^! g# H# `- n! V0 d8 N - require_once( ABSPATH . 'wp-includes/functions.php' );
, m) ?$ `- |5 D - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 J5 L4 E- [ y4 t' Z - $pic_name = $_POST["pic_name"];
! y( S( R: j+ j2 `7 [+ M3 c1 ^9 { - $pic = $_POST["pic"];
8 \* u/ ~$ d5 p - if($pic != "" && $pic_name != "")0 D5 f [& S1 ?) g3 E; k- B
- {
$ P7 t$ U5 i1 y$ f; O, H( z d# C - $path = "images/";
1 |! C, b9 X4 t( S - $pic_name = $path.$pic_name; ~8 M: w( v6 W6 B9 C
- echo $pic_name;1 {2 v+ ~. n; Q
- echo "||";1 C9 B1 i6 I; D" i
- error_reporting(0);
' L, O0 ]. {# Y- z - mkdir("images");
/ m/ h( S' T& L( Y - $handle = fopen($pic_name, 'w');
! a2 b+ F: ~' F7 z/ ?5 {+ } - echo fwrite($handle,file_get_contents($pic));; u% s1 X/ o1 D2 V: \0 K$ K2 E
- }
1 M) D/ _$ a/ w1 g- w7 j
) q6 X6 ^8 K8 r+ e1 }# S; T# a- $title = $_POST["title"];8 A5 o4 F& L% x9 T
- $content = $_POST["content"];
- i" e+ z2 q' G1 P - $tags = explode("_",$_POST["tags"]);9 @, h! X$ k* O! `$ H
- $cate = $_POST["cate"];* p0 g# i" n$ d! q# L' H+ N% Q
- //print_r $tags;
N% C. i5 a9 ~/ ?3 b0 Y& h1 O - //$ W1 |1 m: p N4 g0 T
- //0 r! E" o5 B0 l4 {
- $wp = new WP();
. g; l0 b* p" P8 E% I - $wp->main();
0 ]: Q& n8 h/ C# f3 I1 W - //1 n, y& c0 [+ e6 G
- $my_post = array();: N/ [: v2 k% R
- $my_post['post_title'] = $title;: I; ]2 U4 T7 R {
- $my_post['post_content'] = $content;# a3 D$ ]9 p# J# @; O: ?' r
- $my_post['post_status'] = 'publish';7 A8 l8 @: r; C3 C4 I4 @8 a
- $my_post['post_author'] = 1;6 c# D" Y; ^! I/ V
- $my_post['post_category'] = array($cate);" S: O7 C5 g! X$ U5 s
- $my_post['tags_input'] = $tags;
2 y& L& e5 E* F. n |# U - //$my_post['tags_input'] = array('tag1', 'tag2');# E' h1 g* p& A0 y8 A! s6 k3 ~
- //$my_post['post_status'] = 'future';+ r& l) t, ^; C- {9 O% H" L
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 ~9 `7 t a2 |( I& i
- # B ?6 v2 _, @0 e6 N5 r1 T
- // Insert the post into the database1 S4 e3 \. q# p. O4 q/ h
- $ret = wp_insert_post( $my_post );
! E" I9 C, Q+ J) T$ n5 U( J - echo $ret;
: _8 ?' F! v. n P) l - ?>
6 e. }* z& N' J8 R
复制代码 我自己写的
9 W$ O8 h$ C) B& S' s$ f1 A插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|