|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 7 Z, t6 z3 N" j1 `3 q' |, l$ n+ C
5 \( @% P- w# N" B0 t4 x1 S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, q2 [: R* G' m% \# K3 l! ` x1 W! b6 L% `9 K
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
* J# }" N- x/ C
+ r) g U ^8 s- X" M/ p, i* M8 T方便实用 简单 何乐而不用呢- ! p# U2 B5 y: w: o0 A4 I" g1 H
- <?php" X4 G! v% B; o' w
6 A; @+ e9 R, W. H1 G, `- define( 'ABSPATH', dirname(__FILE__) . '/' );) K9 L' [) n& W* P$ X( c
- require_once( ABSPATH . 'wp-config.php' );7 B& Y% `% A- j+ n+ f% | E8 E
- require_once( ABSPATH . 'wp-settings.php' );$ \- X7 q5 V' N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; t6 H+ U& [( F' D+ t$ N7 f$ e& u G - require_once( ABSPATH . 'wp-includes/functions.php' );. D$ {# A/ j( K# ^- q# a t" h9 p
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 P1 q b5 T2 T4 a
- $title = $_POST["title"];
4 Y$ u1 a7 C! E/ B9 \! Y* g - $content = $_POST["content"];; g J& ^( s$ m' M* k+ k- P9 O' e
- $tags = explode("_",$_POST["tags"]);( \9 u- [0 X/ [2 I
- $cate = $_POST["cate"];
! i: _7 e2 M+ s# W1 e& i$ S) t0 L - //print_r $tags;
# d5 U1 q, ]! K# \1 v - //
; J; c+ t! b( b - //
4 i" X4 P. y4 S5 C$ y1 f - $wp = new WP();) K, k; k0 q- E: s% u; d- u3 P
- $wp->main();1 s/ a8 Y' [' A/ ?. I
- //2 j$ [8 B' {4 Z& t- h2 ?/ z
- $my_post = array();( B' F. D8 X) z+ n8 t$ J
- $my_post['post_title'] = $title;
5 c3 ?2 n$ `/ O9 @ - $my_post['post_content'] = $content;
7 z# @5 u" s% k2 N: [& l5 K - $my_post['post_status'] = 'publish'; M3 m8 n! h# w, _& K' O8 t1 W
- $my_post['post_author'] = 1;" p* f$ g6 n9 W2 v& G2 k; J
- $my_post['post_category'] = array($cate);2 E- v& ]7 n- F8 I
- $my_post['tags_input'] = $tags;
: o( K4 E) R7 }# H6 U - //$my_post['tags_input'] = array('tag1', 'tag2');
* w+ _' e2 s N: d% t F3 b - //$my_post['post_status'] = 'future';
" _1 v; N4 ^9 m; Y( H* q! B) [4 l9 ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';% L; ]# P6 G- A k6 I
- 3 T$ x! L7 z; ?- Q D( j+ _% ^
- // Insert the post into the database
2 p$ a$ k! n2 R) ~( f - $ret = wp_insert_post( $my_post );
9 _$ T0 u) z* J+ Y- F: V - echo $ret;
' i5 w2 H9 w$ R - ?>
7 r- T6 ]+ F/ m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
@4 W" T2 M8 o- n P6 T. J- <?php
- ]" o% Q# V9 S, A# O! `, |! i - define( 'ABSPATH', dirname(__FILE__) . '/' );6 y! }& N, `1 _! `% a+ t
- require_once( ABSPATH . 'wp-config.php' );6 W9 B( ], X, W4 H
- require_once( ABSPATH . 'wp-settings.php' );
' f' {0 S0 h& k1 ~6 O) s+ z) f3 n - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ w( I6 _! M* z0 z1 l( i1 |. g - require_once( ABSPATH . 'wp-includes/functions.php' );6 g7 ~* \( |& f6 f4 X- P
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 m u) x" B! J, {+ W4 |/ e - $pic_name = $_POST["pic_name"];5 m d$ n/ ]- |) i% X3 ~
- $pic = $_POST["pic"];
5 p4 p; u9 ]- M5 i/ W - if($pic != "" && $pic_name != ""); q; L5 @' p4 |" l+ v! M0 L6 G
- {
7 R- t3 ^; }6 N, t) p* U - $path = "images/";
. U# u: w# ~3 M) z) U) k1 A - $pic_name = $path.$pic_name;# o8 V; k" i$ O5 T
- echo $pic_name;
2 l( _3 C6 q/ T) X' X. e4 c - echo "||";% B- W& }' S2 F- |
- error_reporting(0);/ L. Q3 Y$ G# R# n- ^+ {& |
- mkdir("images");
3 {1 C- l: M: W+ y - $handle = fopen($pic_name, 'w');
% l% }/ Q& `2 W+ K( d - echo fwrite($handle,file_get_contents($pic));/ w, o+ X1 Q# {: n
- }/ k- A. M* s0 ?3 ^" `4 b9 y6 C5 {
- 9 V7 K! I) d- @/ x+ o- D Q
- $title = $_POST["title"];+ O0 `+ P7 H6 @- c+ D _
- $content = $_POST["content"];& {; L0 H+ Q( V2 b# `
- $tags = explode("_",$_POST["tags"]);" g* e0 K8 o3 f* j, x
- $cate = $_POST["cate"];7 H5 V. ^9 K5 b. C: t1 n
- //print_r $tags;
; y Q" E+ l( D( V$ l, B0 a7 o - //. x' i) A3 @9 U
- //
* Q$ z9 i x& M7 T* ^9 h$ a' ` - $wp = new WP();
. w4 L" j7 x$ w- l7 o% A - $wp->main();1 E% b4 _4 m% @ S# \1 ]
- //
0 b+ T# j: ]- e; S - $my_post = array();6 X& c& z" [% m* p
- $my_post['post_title'] = $title;
# [ [/ Y$ c N a - $my_post['post_content'] = $content;
3 u" _) K/ I: }- H3 Q - $my_post['post_status'] = 'publish';& w- y5 w6 b6 \$ _, p7 H$ [5 s
- $my_post['post_author'] = 1;
3 d: C1 o( Q. K) p - $my_post['post_category'] = array($cate);
8 D4 B& U8 }5 u/ x3 g& y* z - $my_post['tags_input'] = $tags;
" s# `: t4 Q5 i3 T v% b - //$my_post['tags_input'] = array('tag1', 'tag2');7 Z! R/ n7 Z6 y# [
- //$my_post['post_status'] = 'future';
q& y6 {$ v; y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 g6 n% p# Y* D - , f/ ^9 \1 f. Y" t" `* @
- // Insert the post into the database
9 w { e+ u6 P% {+ j - $ret = wp_insert_post( $my_post );7 @0 R& e- k5 j+ M) D
- echo $ret;7 E6 _! h5 q: {( W4 ?
- ?>
- v4 I5 D w$ Y. u. b! e4 \
复制代码 我自己写的
: W, B3 e8 H, _8 y% i( u7 `) a插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|