|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / O& p! K& c3 S8 d* T
- ^/ W Y, D5 h1 v直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持) p# W! x0 o& G! B) S- A
) C( T' G4 A# a4 q( V我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 \! u) ^ D7 H+ B- @# W9 l" D* l
0 w4 n& A, n! ^0 p. @方便实用 简单 何乐而不用呢- ' k7 ~+ _$ s$ _, W4 u; x( F
- <?php
* M. b& U0 Q; E
, w! T* K+ }6 ]% N5 u% C- define( 'ABSPATH', dirname(__FILE__) . '/' );) P" c$ k2 N6 A
- require_once( ABSPATH . 'wp-config.php' );
8 h/ b7 @- e" O7 i( D) n - require_once( ABSPATH . 'wp-settings.php' );
( h. B+ \1 W1 U' @4 n - require_once( ABSPATH . 'wp-includes/class-wp.php' );
* x% A5 r& m7 M6 p9 f0 E& P7 w - require_once( ABSPATH . 'wp-includes/functions.php' );! n* u9 k/ ]' J
- require_once( ABSPATH . 'wp-includes/plugin.php' );. f g" D6 L) [5 @# g2 K# F- `
- $title = $_POST["title"];
$ E. F( n7 o5 l; B - $content = $_POST["content"];3 M& w6 U( G4 g; F. r7 y0 I
- $tags = explode("_",$_POST["tags"]);
- l- q' ?0 ~/ m# C8 B, Y; z - $cate = $_POST["cate"];
5 _. q' P* Q* T7 a: N3 E# p8 } - //print_r $tags;) F/ M/ d5 w/ A$ @7 P f
- //$ i( Y T# q, F" ~8 J2 y* Z. ?5 [% V
- //
) `/ z# c! i X - $wp = new WP();
1 Y% M. R. w: G6 O5 g! d: h# G - $wp->main();
9 x5 H+ Y: a1 v; l: \3 E - //3 A( Q* Z2 Q% r q
- $my_post = array();
9 M$ y8 I; E& W$ i2 d - $my_post['post_title'] = $title;8 O' P, [- D4 ]+ ?; ` K
- $my_post['post_content'] = $content;
: f# J/ x* C; A8 [ - $my_post['post_status'] = 'publish';
2 s, W7 `/ y$ W" ?; u+ w - $my_post['post_author'] = 1;3 o I! w" ]* R' V0 Z
- $my_post['post_category'] = array($cate);. L: P! i& Y9 | ^/ O8 G/ j
- $my_post['tags_input'] = $tags;1 {+ B1 ^: h- x# V7 r
- //$my_post['tags_input'] = array('tag1', 'tag2');
. a( V! v0 r+ Y J; _ - //$my_post['post_status'] = 'future';5 D* Y- L0 Z0 W3 h J- m
- ////$my_post['post_date'] = '2010-07-04 16:20:03';5 t0 H1 c2 Q1 f0 M6 @4 O ?
- + f0 T6 B# d! q V0 l
- // Insert the post into the database- H7 V! t8 Z$ E& W
- $ret = wp_insert_post( $my_post );
/ x$ t& w- ]! O% o) _ - echo $ret;
, @* P+ Z& A# ?2 L, z; n+ K% V: T - ?>* B3 I+ _" r& d( D1 X2 C" U
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
7 Y+ V$ m3 f2 S5 }5 v5 | Y* ^- <?php
) z' V7 C( D h! D1 C- R - define( 'ABSPATH', dirname(__FILE__) . '/' );
6 ]" O7 R( D! l0 ^6 x4 k4 F - require_once( ABSPATH . 'wp-config.php' );) O. }- R- k! J0 M8 R( n) {
- require_once( ABSPATH . 'wp-settings.php' );
5 G* l9 F5 p0 C, t% n3 h - require_once( ABSPATH . 'wp-includes/class-wp.php' );" u# T* t6 Q) q2 _' r
- require_once( ABSPATH . 'wp-includes/functions.php' );; m# u: n2 x$ `8 [. v" f9 C
- require_once( ABSPATH . 'wp-includes/plugin.php' );
* B( ?8 R+ u, [& k/ ` - $pic_name = $_POST["pic_name"];( M: P$ n3 N4 @, v7 k
- $pic = $_POST["pic"];( k% C# E9 i2 J/ G* Y/ }
- if($pic != "" && $pic_name != "")
' _6 o5 o5 |- _5 f7 U - {% n- o" z3 d4 @( v$ P
- $path = "images/";
3 @6 ?/ Q4 x' c+ d- q" G' J! P( f - $pic_name = $path.$pic_name;5 I [. M9 S1 t2 P3 `/ p/ p S4 K
- echo $pic_name;
9 u ^+ n0 l- P - echo "||";
9 L- R+ [; j% J- Y - error_reporting(0);
: [* N, @+ X! b - mkdir("images");' A2 X) j! Y! N/ t& K1 \
- $handle = fopen($pic_name, 'w');* B, d' Q9 C; l, C9 Y. B! P& A
- echo fwrite($handle,file_get_contents($pic));
4 D2 u- h5 H! q! N: f - }
0 h6 A, t. U9 ~4 @ - 2 z- [# y7 B% \. N* p
- $title = $_POST["title"];: w+ v$ `" _1 f2 E/ N
- $content = $_POST["content"];* {- t5 M/ m" r7 |
- $tags = explode("_",$_POST["tags"]);6 a2 A# o7 n' Z1 n! f8 G
- $cate = $_POST["cate"];1 c3 k0 ]( |2 n! T/ x
- //print_r $tags;
& X4 a+ {3 B' b& L - //
, z6 b" O# d' t' U2 b3 J9 G/ o+ X7 p7 b0 J - // t( X. P% M3 o$ u: o! {( t
- $wp = new WP();
# S2 `7 S$ t- \0 ]' b; X/ G - $wp->main();
. o& r% Y" Q5 L, C/ f/ X+ y g - //# v; |1 S% L4 L6 [8 ~1 z
- $my_post = array(); ~" e1 \9 o& h
- $my_post['post_title'] = $title;
* o- ?% T0 ~2 W3 n - $my_post['post_content'] = $content;
, L2 s q$ A' z/ X - $my_post['post_status'] = 'publish';
1 ^9 ~2 \' x3 A( Q/ N$ ~ - $my_post['post_author'] = 1;
- @* k$ Q) u1 N - $my_post['post_category'] = array($cate);: B& h/ q) l7 @( g/ U
- $my_post['tags_input'] = $tags;
! ^& J8 E) A6 N2 R% V1 |/ H$ \ y - //$my_post['tags_input'] = array('tag1', 'tag2');
6 e- e3 y* |9 D1 D - //$my_post['post_status'] = 'future';3 D4 I, J1 M2 V9 ^8 W* w9 C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 r0 T2 R' G) W1 [9 ] - " @# Y- T9 I/ U9 N. M9 i q
- // Insert the post into the database
+ j; H4 Z$ \; A0 ~ - $ret = wp_insert_post( $my_post );3 O+ w# R, R- C+ O. ~
- echo $ret;
" `! q( ^4 ~, N. y/ \7 } - ?>
# x6 Q2 x5 {9 h7 [$ g( Q' `
复制代码 我自己写的
; g% I5 w2 M; ?! n3 U2 O9 ~( R插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|