|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' H( d1 _% {) |7 e5 A: ~4 g, W* a4 F. y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
4 i/ M+ E2 v7 Z1 ]
' e2 l5 ^" X$ T' _6 ~9 N5 a我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ x2 D. ^' S' f6 `/ o3 P0 d" ]
' N4 `, n0 ~$ D6 N% M- _# P方便实用 简单 何乐而不用呢
. L% P6 F+ A5 }: s- <?php
% f9 z& R4 f: T1 p0 k) T+ M - . d1 X2 y, W* Z9 l" r8 r
- define( 'ABSPATH', dirname(__FILE__) . '/' ); }. F! v; r& x' l6 F5 K' O" }
- require_once( ABSPATH . 'wp-config.php' );
6 A/ Q+ |' S. L4 u* h- O" i$ {, L$ [ - require_once( ABSPATH . 'wp-settings.php' );
8 b" v9 I8 x) \% |, t# a3 r - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: J$ E2 I! P# d1 x" a. Q3 k# D% @# ?8 O% V - require_once( ABSPATH . 'wp-includes/functions.php' );
$ g; T* t$ A& h2 p' ^& }* q" i - require_once( ABSPATH . 'wp-includes/plugin.php' );
+ X. B; M* I0 {/ e - $title = $_POST["title"];
{6 i' b, F# q5 |; v9 e' H - $content = $_POST["content"];
4 U9 u/ \& M" ~- O* u) C; e i/ d- K - $tags = explode("_",$_POST["tags"]);8 C$ U1 @& W8 e$ y0 n6 g) Z
- $cate = $_POST["cate"];: M8 O& a% U" s( r# ]( _- ]9 J! S
- //print_r $tags;
4 ^; j' v3 G# V - //
. P6 g8 l4 M$ O1 P* d @ - //
- ^0 r9 S# W$ L0 k! n( c( J - $wp = new WP();
3 M# f# p$ j: } T8 n) x - $wp->main();
: ?# |% k4 K0 N# p( d c/ v - //8 I; c3 a; L( B6 E
- $my_post = array();0 V. ^, R% r- A
- $my_post['post_title'] = $title;
" H2 }, {7 x/ z% s5 [2 _( X7 h2 B - $my_post['post_content'] = $content;0 |8 I$ N$ r) ?" U- _7 N
- $my_post['post_status'] = 'publish';% N- q) V' ~$ I# t3 e& z1 }: P3 n4 e
- $my_post['post_author'] = 1;. I+ Z$ j9 [7 G# [& `* X# r/ |
- $my_post['post_category'] = array($cate);
" S' y& B8 H" w- ]4 {+ Z - $my_post['tags_input'] = $tags;2 `+ q* l% u6 T
- //$my_post['tags_input'] = array('tag1', 'tag2');
! Z3 ?( U- a4 w6 s1 ?' H9 k - //$my_post['post_status'] = 'future';
U/ E+ @3 ^: H& R% T4 u4 k6 ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';
' Z% X9 ^6 n: ?1 v
4 O2 m$ N, D# X5 p- // Insert the post into the database: E" `& B, r8 c0 Z. I- c
- $ret = wp_insert_post( $my_post );4 |6 i% V6 p/ P- q/ m! N
- echo $ret;8 g( _6 w* x% _# N6 H Z; D
- ?>
" P+ v2 j- S) \% b5 _
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 P/ m0 G- M }+ \$ w* {- <?php
1 K. ^3 n, T9 v) p% \* X - define( 'ABSPATH', dirname(__FILE__) . '/' );
! \8 N& U! t. f6 G - require_once( ABSPATH . 'wp-config.php' );; x& N9 u- J+ y5 O, }$ X/ g7 e
- require_once( ABSPATH . 'wp-settings.php' );* B: V4 D2 a# t* H
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ r- l X; x& M$ p1 S - require_once( ABSPATH . 'wp-includes/functions.php' );
0 f- W' p2 _9 D# K& q [ - require_once( ABSPATH . 'wp-includes/plugin.php' );4 Y- \9 l7 d/ g, Q
- $pic_name = $_POST["pic_name"];
+ x, z. u: R( ~, a - $pic = $_POST["pic"];* m. l: D! u, g+ g4 c5 U0 |" c3 K
- if($pic != "" && $pic_name != "")$ i1 V8 m; N3 ]: @; W
- {. T! y# A5 l0 Y! _2 w
- $path = "images/";
+ {& R* g( V7 s* Z1 P6 ~" G J - $pic_name = $path.$pic_name;: P" c# B _# B/ i: g% F1 D
- echo $pic_name;
0 T& G5 q1 B4 y! Q1 T0 C- e% m - echo "||";5 \- p" K' q @7 k+ Z
- error_reporting(0);* b! b, E5 W0 B1 L2 I; |, P
- mkdir("images");
! i# D# n2 \ P X s& Z - $handle = fopen($pic_name, 'w');
5 ~& J6 l( v% A6 e+ \4 v+ u0 y7 u - echo fwrite($handle,file_get_contents($pic));0 g8 Y0 e, `$ i) ^4 \+ V
- }* H9 a4 G* T: X3 s! G
" X9 u) U3 i7 Z: J" U2 y- $title = $_POST["title"];
5 Q; t8 _1 K; ~" @* j2 l - $content = $_POST["content"];
% p7 K. e& g @8 ~& a. x: s - $tags = explode("_",$_POST["tags"]);9 X5 }& N6 A% d# K# y$ I8 G7 A3 o
- $cate = $_POST["cate"];
$ q6 {( c# W# v! G4 u/ q% L, i - //print_r $tags;
$ `( E: `7 }( y) H) ~1 l - //
1 e: Y9 r4 K( Q8 z, K. G& G - //1 f0 r A: O) y s, c
- $wp = new WP();
. q$ V& s) y/ ]4 h/ I - $wp->main();
' O+ t1 D6 w* `; ~' Y/ H2 d- t) y - //4 t* x6 c! D- s. t; s
- $my_post = array();
\. g7 j0 W$ i, R, L6 `6 O- O - $my_post['post_title'] = $title;! B9 J4 Y7 v7 M/ w+ E
- $my_post['post_content'] = $content;- z$ F; I8 |# K, r, w5 K5 O
- $my_post['post_status'] = 'publish';" X& R- @: r# w& ~) r. m% g
- $my_post['post_author'] = 1;! z& @, g0 I6 B8 M
- $my_post['post_category'] = array($cate);* j9 l( I" Y; p; o
- $my_post['tags_input'] = $tags;
$ {- S& s7 T$ h" I+ d - //$my_post['tags_input'] = array('tag1', 'tag2');8 h. z+ Z$ E8 z. P8 }8 t. Z
- //$my_post['post_status'] = 'future';/ u$ Y* f, z! {4 I- T$ s
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 o1 `' R/ h( W( ~4 p @$ `2 o
- ! J; Y3 Q: _3 k" Q
- // Insert the post into the database& m& `6 d ]0 p" o3 R
- $ret = wp_insert_post( $my_post );
S1 ?9 H: g2 g. B) r - echo $ret;) ^/ Y0 @& j `5 O) N) w
- ?>4 A# }- A Z6 e7 u4 \: p; @' A& \
复制代码 我自己写的) w- e* x4 V% ^1 F( H
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|