|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 4 T; n S( d& J7 K
8 p% w/ B5 G9 n. }/ e: L4 N5 ~直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 q) W9 ?0 {# n
) k: E( Q9 ?1 o+ c( A* v: Z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了5 ~! X+ u7 J% U) I$ J' n, v+ d
9 C1 r# U$ {; k: X7 |1 k方便实用 简单 何乐而不用呢- % u8 C$ y; y/ X$ R4 D K2 k
- <?php
, k: g. G( l; J( W. M* q# L - 3 v& w6 G8 `* L. Y+ ~
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ b6 K6 }. X1 g) Z6 }
- require_once( ABSPATH . 'wp-config.php' );1 h: k9 y, Q$ ^& `% l. ~/ b6 E- |0 k
- require_once( ABSPATH . 'wp-settings.php' );
- K" t; l/ t l5 U/ I' Z/ w - require_once( ABSPATH . 'wp-includes/class-wp.php' );9 s9 x. ]. D$ ]
- require_once( ABSPATH . 'wp-includes/functions.php' );
: B% T6 Y9 m( U0 E7 N, @3 t - require_once( ABSPATH . 'wp-includes/plugin.php' );! _8 I; w: G( |6 i
- $title = $_POST["title"];+ Q, n/ I# \2 g, S0 [! l. u. u. m
- $content = $_POST["content"];) J1 P4 P, h( v# R: I
- $tags = explode("_",$_POST["tags"]);! K% J2 n6 x: j
- $cate = $_POST["cate"];& x. @0 K8 `1 G3 T% g6 |) H
- //print_r $tags;
: f, h0 F. _, m0 ~! d+ \6 H - //
# J+ ~* a' N6 n9 h - //! ]) J3 X1 x W' Y5 d X2 z7 [
- $wp = new WP();
$ W! H/ f: e8 X) W/ a1 P - $wp->main();
4 J; n& }& \! h) y% ? - //+ L- E! q d. i3 O5 B
- $my_post = array();
, \* h6 o/ L1 V) t - $my_post['post_title'] = $title;
& G$ b7 @5 ]+ T& a5 ? - $my_post['post_content'] = $content;
, v, L; U }" V% \2 C - $my_post['post_status'] = 'publish';
/ ^9 [8 l# E+ h, Y8 S/ @ - $my_post['post_author'] = 1;
& X8 z0 R" `: I" W - $my_post['post_category'] = array($cate);
: G2 B: K- A0 J# z2 o* A8 g [( C - $my_post['tags_input'] = $tags;9 o# I) n3 x% T, L6 X4 N
- //$my_post['tags_input'] = array('tag1', 'tag2');
; F; ?1 E+ A a9 k3 I - //$my_post['post_status'] = 'future';
5 u4 T- ?4 i4 T, a - ////$my_post['post_date'] = '2010-07-04 16:20:03'; C4 `) e: `; R; M _8 w9 o
- , Z: n0 O& h# J" W' j$ v, }% Y7 b
- // Insert the post into the database
; k2 D P, {3 W7 n3 ? - $ret = wp_insert_post( $my_post );
! h7 \' ^) j& r3 n8 R1 y5 [ ~ - echo $ret;
6 u9 Q6 ^1 _0 M3 S - ?>& s, Q4 l0 X) g% m( O: l8 E; V5 S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
$ C& ^( X: ^% {% @/ b& U- <?php0 V/ Y0 a9 O# X# k4 P
- define( 'ABSPATH', dirname(__FILE__) . '/' );+ }. b+ Y5 Y ` z* `
- require_once( ABSPATH . 'wp-config.php' );7 k b$ C! E1 S. B) j0 D
- require_once( ABSPATH . 'wp-settings.php' );
4 Z8 f5 i* V- M: Z- B* o' V3 F( o - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 U# o1 [5 O9 C R2 S+ x' [" u
- require_once( ABSPATH . 'wp-includes/functions.php' );
. L" s* ?5 f- ]8 j. U7 @ - require_once( ABSPATH . 'wp-includes/plugin.php' );
# h0 m3 I! H3 n - $pic_name = $_POST["pic_name"];
# o n: g5 |8 ]% ?$ F - $pic = $_POST["pic"];8 P8 i9 S- ^% \ z B
- if($pic != "" && $pic_name != "")
& O8 T [" P$ E, M - {
+ |0 K( y* D4 n' j$ } k - $path = "images/";. ?- w; t$ y6 n) H* i$ y0 j
- $pic_name = $path.$pic_name;- F! N7 `3 l0 \9 v% K% J
- echo $pic_name;
W2 t4 _4 @+ H8 ~ - echo "||";4 s; w; w' w4 [" O& W9 j3 x
- error_reporting(0);
1 M) a: x# {3 D - mkdir("images");* E* R- |7 [, |" `8 t. t! P
- $handle = fopen($pic_name, 'w');
. E2 y0 P3 k" b- h1 J& N - echo fwrite($handle,file_get_contents($pic));1 f9 E$ S5 c0 S& l0 V
- }
8 t% V* M y2 I, I4 O, }* c - 6 B' W( z) D) \' M* O3 J! p
- $title = $_POST["title"];4 [* e3 r9 w, e# c
- $content = $_POST["content"];! o2 c" C* ~7 w, K; E& W
- $tags = explode("_",$_POST["tags"]);
6 k8 T9 v7 l3 K9 ]# h - $cate = $_POST["cate"];
" c, k* B- s$ |4 _3 j - //print_r $tags;
, X0 J6 _# l) [/ e' A, s. q - //
; g" u) | @9 P- x, S6 g - //
$ W( }5 U3 o" Y2 p - $wp = new WP();9 y* D9 X. q O- n/ A7 {
- $wp->main();4 O! Z& z0 h% r
- //4 \9 Y8 q7 r) G$ R
- $my_post = array();
$ _$ `( d* ?1 ^" V8 u9 B - $my_post['post_title'] = $title;
2 `, E+ ]; U1 T4 P5 n2 i9 u - $my_post['post_content'] = $content;
- b% H0 F" |. L7 \6 G - $my_post['post_status'] = 'publish';! A3 }- y2 B* B2 x- a. V2 h
- $my_post['post_author'] = 1;$ y3 ?- D- n; j0 l4 d- e y" V3 o
- $my_post['post_category'] = array($cate);/ b: _/ S% Y$ e2 S$ k/ t/ I3 R
- $my_post['tags_input'] = $tags;) j" `/ A# M# F7 J
- //$my_post['tags_input'] = array('tag1', 'tag2');
* G6 l2 D2 H9 O3 c! c" f& [ - //$my_post['post_status'] = 'future';
9 w# G2 j% R- M8 t0 f) X: c - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( c( ]- } ?8 o% i; X
6 x* f( S( A3 u; W* b& S- // Insert the post into the database
1 k: G3 ^4 ?) w2 x: _9 P - $ret = wp_insert_post( $my_post );
/ C# U( K; r- G: d5 N- w - echo $ret;# M9 E' z( o# _( p2 D( l
- ?>" ~# w: I# Z5 E: Q
复制代码 我自己写的
3 ? w* H. U0 [% S/ v插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|