|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 G$ X5 F1 h, g! j0 [5 A" z3 Q4 h4 s5 _/ }* {+ M, p
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
" l2 c- j9 O0 ~ v; l$ P4 O g( H3 z9 B2 m7 M
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了0 _4 b2 r% [5 C0 G- P b' Z
# p G# B/ A& n# \/ |
方便实用 简单 何乐而不用呢- 1 z; L2 _* ]& ~/ i" v0 B
- <?php
- M& i' i& f @+ {' I5 \/ p - s4 e. W5 x" i M3 X' }5 ]4 ^
- define( 'ABSPATH', dirname(__FILE__) . '/' );" i' U5 k- ?/ U/ `
- require_once( ABSPATH . 'wp-config.php' );
4 ]2 {( y3 Z( Z4 M5 E - require_once( ABSPATH . 'wp-settings.php' );
- `0 D% S }# M) L/ Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );, u+ L4 ]# b5 y3 P
- require_once( ABSPATH . 'wp-includes/functions.php' );5 D4 D9 }/ G. D5 e8 k
- require_once( ABSPATH . 'wp-includes/plugin.php' );
/ N- z& _& @) Y2 a6 m$ S - $title = $_POST["title"];
" X$ ?# F" p/ R9 H8 Y' S! \ - $content = $_POST["content"];/ `7 @" e, N. C: v( F3 k3 a3 @! {
- $tags = explode("_",$_POST["tags"]);7 U4 o- e& @1 s! i' J- Q8 S! {
- $cate = $_POST["cate"];$ B+ _7 \9 `8 ~' j2 I% E9 B) j
- //print_r $tags;% ?$ s6 [! q% v G A+ N- T5 R
- //
0 G* Z. e* w e% ^# w& r. y - //
7 |# \ h# e% t8 c4 M2 `4 d" m1 { - $wp = new WP();! M) Z9 O7 E9 c
- $wp->main();
4 u n. C3 Z& C# C4 Y - //0 s; ~6 m$ |3 P6 v8 ~, ]' W9 M) ^
- $my_post = array();$ T3 e; j* I3 a% s) a, W
- $my_post['post_title'] = $title;3 U" _" l# K2 d; I7 D
- $my_post['post_content'] = $content;
3 `. t: ^% m- c2 s - $my_post['post_status'] = 'publish';1 `" K- R9 g6 u' v
- $my_post['post_author'] = 1;
* [1 ?/ ?7 f& G) ]/ x+ Z3 O; h; A - $my_post['post_category'] = array($cate);1 h3 N. V* R* D c
- $my_post['tags_input'] = $tags;
: y0 L+ [( W3 F/ F - //$my_post['tags_input'] = array('tag1', 'tag2');. \$ S& Q L& x* I8 t
- //$my_post['post_status'] = 'future';9 ?4 E3 @& q/ G( O) q* w
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 K' F3 q. o: F1 n) \$ t! `6 T
) M5 ~( d. L5 j4 E3 t% }+ c- // Insert the post into the database
* o7 Y! g3 T9 C& `" s: Q2 o - $ret = wp_insert_post( $my_post );" f' w# I* P' v/ v6 o
- echo $ret;+ R2 F" T! M% w2 N& g( O
- ?>/ g# {& ?; w5 V( x" `1 g. J
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , W' H; m2 ~, O& Y( b/ R9 J
- <?php. T9 b# m- n3 J$ R! k
- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 C2 c6 F- F; b, }! E, r8 i - require_once( ABSPATH . 'wp-config.php' );
% Z( M* z7 X- h( D8 M% c - require_once( ABSPATH . 'wp-settings.php' );; l' _6 v& b) L4 m' x
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! l3 T1 R* Y: o( N& h+ n( c( G - require_once( ABSPATH . 'wp-includes/functions.php' );8 z& S1 `1 t. l2 f0 ?
- require_once( ABSPATH . 'wp-includes/plugin.php' ); s6 m6 v" O: E$ x/ b5 ^
- $pic_name = $_POST["pic_name"];
7 ?; y7 B9 h# c( z J' F* K - $pic = $_POST["pic"];2 p0 E' ~; o* E Z! K8 u( Q
- if($pic != "" && $pic_name != "")
9 W( T4 s1 P4 A7 p1 c: J/ F - {
8 W# `: d6 ^( @" d J$ @ - $path = "images/";
+ J+ Q2 Z$ |, {6 t$ I. I4 F+ g4 _: N - $pic_name = $path.$pic_name;1 A# u5 t2 I/ V7 {; c5 V
- echo $pic_name;
1 \2 K! j1 j& {1 I! `- { - echo "||";" D+ G+ F+ U/ \: }" M% y0 S
- error_reporting(0);! {' ~; ~1 A( X; y$ y& t; @
- mkdir("images");# \( S5 T6 ]; U' D1 B
- $handle = fopen($pic_name, 'w');
* e) `" T; D% i, b - echo fwrite($handle,file_get_contents($pic));; q% s. K" o5 N0 V7 Y/ I l1 C
- }) J: e* o+ d- p7 l# k" o; G& }
- . ~5 q' H; \- t$ u7 x
- $title = $_POST["title"];6 C' k1 n& n* {; D+ F
- $content = $_POST["content"];$ x9 q1 T! Y( |8 E3 g
- $tags = explode("_",$_POST["tags"]);
/ h1 d* c( I# m7 H9 p; D - $cate = $_POST["cate"];0 l% Y& m+ [& N2 E) k/ p0 ?' k
- //print_r $tags;
6 ?& o" z2 k8 P2 N2 _* T - //3 s, V9 [& h: Z& b& b
- //; `2 w6 J: X- z3 {, l% q
- $wp = new WP();2 z' h; I# c" z% b4 Y' g
- $wp->main();
p/ a2 ~% |9 I1 w8 O0 h - //8 h& E/ b8 g7 I/ V! U6 y
- $my_post = array();1 G, {3 d. [7 H7 `; Y
- $my_post['post_title'] = $title;
: ?8 b/ u$ D# } - $my_post['post_content'] = $content;2 S! k* n" [" r% p! y
- $my_post['post_status'] = 'publish';; H( H) {, h. r; {
- $my_post['post_author'] = 1;
& E, M+ v8 r5 S& p9 M$ R - $my_post['post_category'] = array($cate);
) F# I0 o; L$ _3 V - $my_post['tags_input'] = $tags;
5 V6 u9 B2 U$ C% E9 [, p* w - //$my_post['tags_input'] = array('tag1', 'tag2'); k1 i& R# j" e: n; r4 [4 r
- //$my_post['post_status'] = 'future';
- Y. ]7 N" _$ G* Z) n - ////$my_post['post_date'] = '2010-07-04 16:20:03';
# t, H4 U/ w' H/ K. | ^
! Y0 L. T* X% W J/ |- // Insert the post into the database
; ^# l) r' r4 `2 v( Z7 @# g - $ret = wp_insert_post( $my_post );4 T# n" \7 S6 U/ t" o' e# p. S9 v( `/ g
- echo $ret;
" J7 J* {% P, p0 O& H" m9 m6 t - ?>1 c0 g1 R: @; L5 s5 c0 U
复制代码 我自己写的: O9 H% j! ^8 d. |! i2 I8 p$ K
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|