|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
* Y6 r* ?# a/ J6 C( w+ Z" g) u0 k" K) ~3 a2 d$ H6 w! k" Q# p: ~9 L' Y8 x
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
" n3 I7 p+ L2 q7 s% i( I/ ]0 ]3 ] U& J `8 J+ }
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
! U, g) D! u% n7 J% @" K$ A, J
$ A; B& m/ d3 a" i6 Q6 q方便实用 简单 何乐而不用呢
) o2 X2 p1 c: ?2 S7 p- <?php. T6 W, z+ |9 I; U
. ^' S+ W" Y$ W2 i6 T, n- define( 'ABSPATH', dirname(__FILE__) . '/' );5 D4 o4 f' s# D5 |% m$ F+ f
- require_once( ABSPATH . 'wp-config.php' );/ ~1 p4 L* V* i5 t; N
- require_once( ABSPATH . 'wp-settings.php' );2 Y8 D' u9 c; x) f/ u, X7 @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" s X. b! d, P7 B+ p
- require_once( ABSPATH . 'wp-includes/functions.php' );
! D4 g; q2 c, _+ r& [) T - require_once( ABSPATH . 'wp-includes/plugin.php' );3 J7 _$ F5 ^$ q# a
- $title = $_POST["title"];
6 G) a% C* P5 Z5 A$ p5 a - $content = $_POST["content"];4 T3 @4 m( ?, a/ ^/ {0 t& K |
- $tags = explode("_",$_POST["tags"]);) ]$ B6 R4 n4 g: f8 d1 D3 Y
- $cate = $_POST["cate"];
% E! Z0 }2 V% Y0 n4 i - //print_r $tags;$ }% O9 f. J. F8 h8 y' [
- //
' r/ e% O, O8 s4 b - //
7 v k* f; a2 _- @' e; t4 { - $wp = new WP();& X* V4 b H6 T) w9 f) _. g0 [
- $wp->main();
5 h$ N8 Y I' S7 C0 W - //- ^7 F9 O4 }$ v% H( ~9 u
- $my_post = array();4 b2 g% C' I. X1 d+ C; z
- $my_post['post_title'] = $title;
1 u- o5 s1 N" G4 S' A" Z% x9 R - $my_post['post_content'] = $content;9 E* k& P9 K: r9 b3 M
- $my_post['post_status'] = 'publish';, {- S N# A7 f+ h7 z3 v
- $my_post['post_author'] = 1;
5 J5 q0 A3 k0 a4 g3 F - $my_post['post_category'] = array($cate);, }$ U( [% w" I5 S' X' m1 U7 I) j
- $my_post['tags_input'] = $tags;
) z: {# {0 P' G/ N1 U - //$my_post['tags_input'] = array('tag1', 'tag2');
6 s9 ^- e* e3 }: w - //$my_post['post_status'] = 'future';
$ T) U' H- n: A4 ?/ g! W - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 t$ Y7 |+ R. B! Y8 g" [
) c! ^, i& O; ?' T9 q- // Insert the post into the database
" H2 W( q/ Q4 `6 w" G - $ret = wp_insert_post( $my_post );
/ `% y" R9 t1 [8 [- B0 @ - echo $ret;
1 k- p0 P' R# p! X8 D" r - ?>
, d" W! X: }6 R* e& E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, @! H% v Z8 X0 I- <?php
$ @, h: L( \- T Y$ ~. y5 {; y5 v - define( 'ABSPATH', dirname(__FILE__) . '/' );! z2 Y" T& |2 w8 U% \
- require_once( ABSPATH . 'wp-config.php' );
% y/ b0 S" u# v0 |6 w! J - require_once( ABSPATH . 'wp-settings.php' ); s* k1 V- G( n% Q5 q; u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );8 |/ ~& v. @5 { ~; T4 j8 _5 V
- require_once( ABSPATH . 'wp-includes/functions.php' );
* y) X% R$ C0 m5 R - require_once( ABSPATH . 'wp-includes/plugin.php' );
$ g/ i, {# E- n/ ` u - $pic_name = $_POST["pic_name"];
) K/ D/ ^2 w7 Z* [- n - $pic = $_POST["pic"];
, S/ w1 N/ s- w7 V3 p8 l, I$ Q/ \9 |* U - if($pic != "" && $pic_name != "")
5 W: ^# V+ u7 I7 ]1 } - {
! x4 I% q2 N) e5 {0 F' o - $path = "images/";8 |4 Z" `, u4 V
- $pic_name = $path.$pic_name;6 R9 @ J3 C5 v: C; i; f4 @
- echo $pic_name;. a4 t% W# q* \: [
- echo "||";
s T4 q' q) r% n ^' F l, C - error_reporting(0);1 N( k" J% n1 w2 A! {1 a p/ h
- mkdir("images");3 k% q/ Z. c5 s) M) c! P
- $handle = fopen($pic_name, 'w');
0 ]5 E0 q- E7 H3 t8 }+ t8 F - echo fwrite($handle,file_get_contents($pic));& P6 }' G4 B/ f
- }. b2 ]) K9 j1 n) l- b( \
- & }! Y/ n1 F8 Q x) U: \8 C% K$ S
- $title = $_POST["title"];
8 ^4 u B! e7 I% P& Q2 Q - $content = $_POST["content"];
% _! `9 X* o" ^( V7 l - $tags = explode("_",$_POST["tags"]);' G$ @8 j; _( Q. B; r4 F
- $cate = $_POST["cate"];# p. O& \9 p9 s8 t2 n
- //print_r $tags;+ {, s. r' `5 b
- //" l0 i$ `% F5 r
- //& X- X# x" i+ p8 T# f
- $wp = new WP();0 q# m+ J1 b& q; E
- $wp->main();9 d: t% R5 y, G4 o/ B
- //8 E% `# _6 ]' \
- $my_post = array();
Q( c- _0 y4 M b' \1 Z: @$ [$ j - $my_post['post_title'] = $title;, L0 O& A, k/ l$ H2 s% U( r
- $my_post['post_content'] = $content;% `/ L2 x: _6 v/ R. Q; j/ w; _
- $my_post['post_status'] = 'publish';% y; i- c) e' |, b/ s! P
- $my_post['post_author'] = 1;
' b7 V% H3 }# |- j$ { - $my_post['post_category'] = array($cate);
+ ]9 t5 E# i7 V% Y# e/ T7 n - $my_post['tags_input'] = $tags;2 J- a! W* x; ^' Q: U- u
- //$my_post['tags_input'] = array('tag1', 'tag2');$ l" [( V# X& r0 A0 H3 e" H4 W+ `0 I
- //$my_post['post_status'] = 'future';+ { C1 t% L( ^! Q& }" \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';' Y4 I4 v: F# r8 O; F
- % \4 s; u5 |3 D; U4 f( \3 Z r: j
- // Insert the post into the database
% z& p6 s! V) R: ] - $ret = wp_insert_post( $my_post );/ i# f; X! g- L8 v9 r/ _9 l
- echo $ret;
! _4 d/ T* [: e+ g. t - ?>4 ^) t- X& O- y
复制代码 我自己写的
+ J4 p$ x9 ~4 K1 b L. Z2 T1 E9 q% j8 ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|