|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 b( n; k9 I. r4 J
0 q( d! x3 a; m' t# b( o \% g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
5 \8 ?: \; `) ?" E
. n$ A0 Z3 m7 `( r% j1 r3 _; {) y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, z# ]$ _ O7 h7 H8 m
: V& k. Q$ j2 p, E' F9 w& v方便实用 简单 何乐而不用呢- 0 a/ ?. w) ~0 P3 V7 Z1 E" ?' }' D' n
- <?php8 K. \( M( ]7 N. Q3 K' B1 W- z
- ) j0 b6 b& w$ M7 O4 ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 X# X N+ F; F/ z6 U; \4 e% T2 M - require_once( ABSPATH . 'wp-config.php' );
( S0 p9 ?9 _$ |6 E& _' |5 w$ r - require_once( ABSPATH . 'wp-settings.php' );
* z: b8 z6 n1 x f - require_once( ABSPATH . 'wp-includes/class-wp.php' );- \; O+ h: F7 E& S. Z
- require_once( ABSPATH . 'wp-includes/functions.php' );$ s& v* T8 g# t H% N: W2 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% M. E, v5 [) \- r" U - $title = $_POST["title"];
- V( D$ A- L. B9 |5 N7 w' d7 ] - $content = $_POST["content"]; K3 ]' i6 G5 `3 ]! R6 H% {
- $tags = explode("_",$_POST["tags"]);
0 C! B' m4 O* h5 C g0 p4 r - $cate = $_POST["cate"];
, F1 R! ]' ?6 H- ~/ e9 r0 [2 l - //print_r $tags;
+ e% q7 a3 ]- G* d3 K+ g - //
8 p6 }" i/ w6 ] - //
9 T- X# t9 Q2 s, \) q- P! L - $wp = new WP();7 l" Q1 b& o' R' E6 Q
- $wp->main();
, n' F8 u# f s4 V - //
* X8 B9 ?( D" V/ [- S }9 x8 ~1 O1 |8 a - $my_post = array();# s0 u+ K9 W Y: P: y! @6 w7 j6 r/ L+ f' r
- $my_post['post_title'] = $title;" W8 s* ]- P9 O
- $my_post['post_content'] = $content;6 T0 k7 j2 ]: S
- $my_post['post_status'] = 'publish';0 g) p$ X4 T$ B! e" ~& P3 B& C) H1 X
- $my_post['post_author'] = 1;7 A6 P6 r0 z+ X/ x6 }; p
- $my_post['post_category'] = array($cate);
+ x+ ^; E1 A0 I& F, ^$ I - $my_post['tags_input'] = $tags;* ], v" {- \5 k* ^3 M
- //$my_post['tags_input'] = array('tag1', 'tag2');6 d G+ @) D# x
- //$my_post['post_status'] = 'future';9 m) H) a( |( m, R+ {
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* i" t3 Z& M, q" F9 v+ j
' b+ @8 D; G/ c6 ?- // Insert the post into the database
4 y& w& v& [# G# I* _- R& j - $ret = wp_insert_post( $my_post );9 K. S! Q/ K R! l# S
- echo $ret;
% }5 g2 u: K7 j2 d. E$ e - ?>2 U8 S* Z. ^, \' h, o/ X
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
* v, p5 q5 k( f; U* j& z- <?php' x @1 T/ O1 U! U4 Z: ]8 ]0 A ?9 a
- define( 'ABSPATH', dirname(__FILE__) . '/' );% y( u$ L4 M. @' n) Y2 b7 [4 ]
- require_once( ABSPATH . 'wp-config.php' );2 Q; M) J' u9 \$ x/ m5 ^" f
- require_once( ABSPATH . 'wp-settings.php' );5 u; l! N! D7 l' y" `4 P
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 `8 }3 Z' W9 x" h* k2 a- c! n# I - require_once( ABSPATH . 'wp-includes/functions.php' );
$ p5 X+ e/ y! B% Q( O& f - require_once( ABSPATH . 'wp-includes/plugin.php' );; B! D" k" B6 B' R; A+ y
- $pic_name = $_POST["pic_name"];: k$ R: Q7 o6 y8 D, s
- $pic = $_POST["pic"];0 Z8 b4 y) h E. S+ t
- if($pic != "" && $pic_name != "")' F$ D1 x9 F j$ g6 I7 R
- {
. d6 y* v9 u0 J; v - $path = "images/";3 T6 p) V- G: g0 |' l% \
- $pic_name = $path.$pic_name;" `% `7 N) _/ P
- echo $pic_name;
1 S, J( x0 i2 R% i0 L - echo "||";3 e, f+ I- _& N
- error_reporting(0);
3 r H. I# m0 R; e( |# P- d - mkdir("images");: R7 J% S7 s$ Q* Z- q P' \4 [* L. g
- $handle = fopen($pic_name, 'w');
' o9 y) N6 ^ r, t - echo fwrite($handle,file_get_contents($pic));
% `4 X! S3 C. A4 U/ _1 l - }7 D5 i8 D0 R! K4 V0 R, a* i, y* }
) |5 U& h X* A( w" Q- $title = $_POST["title"];2 c& E* j/ U: U, i
- $content = $_POST["content"];0 [/ M9 @2 s/ A7 x
- $tags = explode("_",$_POST["tags"]);6 |& p( i, y3 ]* E" c6 e
- $cate = $_POST["cate"];
7 d* B- F" n% ]+ a6 \" E C - //print_r $tags;
7 r( P. A0 w/ [+ a. I+ h - //
0 u0 q: e% X7 r2 o% r( ~/ q: E8 C2 P - //$ }1 M- T' m6 u& M5 H; k5 {
- $wp = new WP();/ U+ f# r# P! O8 I
- $wp->main();
3 z4 D+ {5 p* d- A - //
2 Y, t4 L) E; R+ \+ p6 {9 g3 r+ Z - $my_post = array();
8 _: p$ ]. j8 \- p7 H$ Z - $my_post['post_title'] = $title; k2 A! G& E4 t- ?) w
- $my_post['post_content'] = $content;, q4 l- ?; s! T9 l
- $my_post['post_status'] = 'publish';
+ U* n+ u2 Y! ? g - $my_post['post_author'] = 1;
& n E4 t- [# o# h - $my_post['post_category'] = array($cate);8 r8 l- v1 V6 N+ e4 _: ~4 ~
- $my_post['tags_input'] = $tags;" B+ o# R0 P& V* W# f- ~" W
- //$my_post['tags_input'] = array('tag1', 'tag2');6 m1 _, j l6 a) l: [ W5 b8 J( J
- //$my_post['post_status'] = 'future';* C& \+ r2 t2 A( ~; `9 i1 ~) t) a
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 o- {0 T, X/ H
2 K! r, j" d5 @5 _. H" O- // Insert the post into the database' u$ d/ O) f6 w) f
- $ret = wp_insert_post( $my_post );1 H3 ?4 T+ o/ P. u( Y" ?9 G" n
- echo $ret; g6 x3 M! D h6 R3 G# _0 W
- ?>0 R c; H. ` M+ G9 u; ]
复制代码 我自己写的
% | `# s( [. S+ L ~! [) v' r2 w: F插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|