|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' o0 I, ]) T! V' m4 l
, ~: s6 g6 T9 p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 u+ h. _" [7 y- O9 v
* i! i) Q/ t" i3 S; ]( k2 m我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
& E) [3 S; f0 s5 z; d' z# k; P+ \. O
方便实用 简单 何乐而不用呢
6 t, F4 H6 T0 s/ ~- E- <?php
% s2 z P1 [8 c6 V - ; z/ N% U8 w% B& ]$ q
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 K! K6 ]2 z# {) d" K( \/ H# z* U - require_once( ABSPATH . 'wp-config.php' );
: v- k \ ]7 _! x9 v5 H1 M! b0 V& V! g - require_once( ABSPATH . 'wp-settings.php' );
6 x0 U0 y' `8 H$ k d0 A( u# e- I - require_once( ABSPATH . 'wp-includes/class-wp.php' ); x, ^, {9 l5 M0 H* J1 X
- require_once( ABSPATH . 'wp-includes/functions.php' );
! v" V! h2 ^) | - require_once( ABSPATH . 'wp-includes/plugin.php' );* ]% K5 u6 B# G( x/ j8 ?5 x
- $title = $_POST["title"];
$ x7 X' F4 K [/ j3 i1 k' d - $content = $_POST["content"];
' w1 t; n1 J( g- [/ K: N - $tags = explode("_",$_POST["tags"]);2 I9 f+ X" \4 g* B: l
- $cate = $_POST["cate"];& o3 C# z! S5 I0 n4 r
- //print_r $tags;. i0 I" t- s7 M: y, B) X
- //
$ `4 J) O$ c# j/ S8 T. A - //) o/ F, t* r- E7 }% m) J
- $wp = new WP();
) X8 s- J3 d/ W$ U, j: C - $wp->main();8 `7 t( b' Z9 O& X. h9 N- |/ T
- //
2 Z$ t0 y9 e2 z5 w8 n - $my_post = array();4 n6 y' g6 P' ^5 ^% O* t' e' }: V
- $my_post['post_title'] = $title;1 [/ v4 Q5 E9 ]9 ]
- $my_post['post_content'] = $content;
7 z w. }) f4 a2 H8 x3 [( k' `. N - $my_post['post_status'] = 'publish';4 {( G& l7 L: y& w9 ^7 W
- $my_post['post_author'] = 1;
' `+ ?3 \! S6 a0 D3 d - $my_post['post_category'] = array($cate);
' T1 O$ I8 ^0 Y- g - $my_post['tags_input'] = $tags;# ?- l8 H5 F& G9 L" j
- //$my_post['tags_input'] = array('tag1', 'tag2');5 I8 d$ M# G' z8 R
- //$my_post['post_status'] = 'future';
, L; K& d* B/ M3 W - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. u+ F& i8 W; p3 l( X - & z# P& Z& c1 q! b7 o- X9 s2 D
- // Insert the post into the database
" O: `' H8 v4 M. @8 I7 z - $ret = wp_insert_post( $my_post );
2 l& x6 ]& A: K6 \ - echo $ret;
! ?- @3 W4 E9 q. [ - ?>+ z9 {* k# e9 B6 V
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 2 Z. i" ?' _( J5 v1 ~' q& w
- <?php
( {. q1 p- j8 f! r - define( 'ABSPATH', dirname(__FILE__) . '/' );
% Z: K9 G, \, r - require_once( ABSPATH . 'wp-config.php' );
, L/ M" g& Y( p+ i" j - require_once( ABSPATH . 'wp-settings.php' );
( G/ n8 [4 M1 n/ C) k3 W& c - require_once( ABSPATH . 'wp-includes/class-wp.php' );
! `" o+ z0 N$ p& M0 r - require_once( ABSPATH . 'wp-includes/functions.php' );! c8 B7 V# E7 {
- require_once( ABSPATH . 'wp-includes/plugin.php' );2 `- u+ q/ e# W- A( e1 S
- $pic_name = $_POST["pic_name"];4 o$ }# B' |) v, r8 j; k9 z. b
- $pic = $_POST["pic"];
0 b3 c$ [; |1 | |0 M' x - if($pic != "" && $pic_name != "")
* m2 F+ o4 o. r3 d9 l: P - {( C/ @/ `7 a* L8 ?) @
- $path = "images/";
/ n- \: q6 o. @6 i$ S3 N% Y - $pic_name = $path.$pic_name;4 D0 c8 M& b2 \1 Z+ ]: W
- echo $pic_name;( Y7 j9 N4 I# B8 E' l
- echo "||";
( X( n7 V: e+ R# t& c0 Y - error_reporting(0);
# ^& Q, K. N5 c, b" | - mkdir("images");
) \- n' w! `) q: z - $handle = fopen($pic_name, 'w');
% P/ M$ ?, o% D9 S9 h9 o - echo fwrite($handle,file_get_contents($pic));
0 w2 V. h: f* f - }
( r) y) F9 V0 C" b+ `. f% {9 [+ h
8 ]3 d7 ?. n1 Z) q# X' d- $title = $_POST["title"];
5 a9 M( o) U4 m - $content = $_POST["content"];" g& G4 i! G- g, K
- $tags = explode("_",$_POST["tags"]);0 E Z/ Q6 W( e5 x" w
- $cate = $_POST["cate"];$ U% z/ B- G# x6 {0 {3 B
- //print_r $tags;
, P9 `) K/ B+ A4 N. t8 F - //
. F# X% T6 c5 Z2 s4 t3 v, n4 L - //7 [ r! X" v# Q4 O0 l
- $wp = new WP();" I" e( e" ` ]5 n9 ^: i( @5 Z
- $wp->main();
0 i/ y v: s* H) R' ^; d- H0 s - //
- I" y- D; I9 ]" k: }5 m - $my_post = array();- }+ A* X$ ]$ U
- $my_post['post_title'] = $title;3 ?, ^1 V/ z! a2 H4 I
- $my_post['post_content'] = $content;
/ v! n# v+ h6 g6 B( g% T8 e - $my_post['post_status'] = 'publish';7 H+ z; a4 O* [; K
- $my_post['post_author'] = 1;- a. F% t1 r, Q; N8 X
- $my_post['post_category'] = array($cate);4 J- l6 X1 l6 I) Y6 e
- $my_post['tags_input'] = $tags;
8 X+ z* D, w( \1 k# t0 D% P+ S - //$my_post['tags_input'] = array('tag1', 'tag2');/ B' v: o: V' g& z
- //$my_post['post_status'] = 'future';
8 Y% J5 \0 W E% n7 V - ////$my_post['post_date'] = '2010-07-04 16:20:03';6 q8 o4 L- ^5 P8 I! s/ O5 T0 e* q
, D. I# H1 ?8 L+ R- // Insert the post into the database) M8 ~; A1 t$ v$ F% _* c( @
- $ret = wp_insert_post( $my_post );
, \7 ^7 g q4 A( F3 t: I' p3 V3 E - echo $ret;" x+ x; `/ f, l+ U
- ?>
( B1 }, k2 B* Q9 _
复制代码 我自己写的7 Z9 g, i# U( X0 A2 w
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|