|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & m+ b3 e( D6 Q; S
* Z. g' L- G, T3 A直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
P% I1 [: W: t; K |2 m# y
3 l3 a; K# _+ E: G4 F4 u我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了) e/ N4 k, Y8 n0 H% o; g
( h. l- |6 V4 J1 K( z2 O+ V* f( t# x方便实用 简单 何乐而不用呢- * f" H5 Y/ W6 `. B( k& m5 S" y
- <?php
! \$ e9 J% c3 G+ c; z0 h0 ~, }
% ^4 t/ \9 @$ O* r ^- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 J+ f3 i1 L2 x* S% D- y - require_once( ABSPATH . 'wp-config.php' );6 q& C+ k% w' a! E& ]+ Y6 v4 ]
- require_once( ABSPATH . 'wp-settings.php' );& ^* f2 Z) S1 W# i8 I2 \5 k
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" @/ Y; W4 O4 F$ ~4 I' o
- require_once( ABSPATH . 'wp-includes/functions.php' );
4 A8 ~0 _& Y7 ~. S) l6 ^, [5 U% _ - require_once( ABSPATH . 'wp-includes/plugin.php' );
4 o5 @6 E2 Z6 ]0 ]9 j - $title = $_POST["title"];6 S( ?8 k5 t& }* P* a# ?+ f E2 H
- $content = $_POST["content"];( P- a% x! ^6 |, a! h
- $tags = explode("_",$_POST["tags"]);2 w" z2 D- s6 _8 u! v3 M* v
- $cate = $_POST["cate"];
6 p& N& A1 v) |4 ? - //print_r $tags;
; B" B1 r8 R+ E# T# o$ E4 d7 n - //) ?5 ] }( p" M1 n
- //
5 C1 g) M9 e+ r( d- X& M - $wp = new WP();/ B* }8 W4 w! c1 g {
- $wp->main();
3 K o5 H! U$ J6 q6 H - //
9 @$ Q- j! [- s+ V6 N6 p O% A - $my_post = array();2 Q; W1 B, U/ j8 q) W6 p3 Z9 P
- $my_post['post_title'] = $title;/ |2 C& ^+ z3 H+ g& l9 O1 m
- $my_post['post_content'] = $content;
. f0 \. i1 [" H6 t& A - $my_post['post_status'] = 'publish';
6 \. T9 w3 v5 c" u. m2 s) y o - $my_post['post_author'] = 1;
1 N, O+ J$ T4 z, K4 v; A" O/ S - $my_post['post_category'] = array($cate);
) U5 Y, X: o( L- ?. S - $my_post['tags_input'] = $tags;* Q8 M: R3 v% D- p" n
- //$my_post['tags_input'] = array('tag1', 'tag2');
- z. m3 |+ Q# M& t. N0 j, d; x - //$my_post['post_status'] = 'future';
) @0 D* W; T5 j- c! {. | - ////$my_post['post_date'] = '2010-07-04 16:20:03';7 f6 t! w+ i% h/ z
g# s: G% n' @5 B- // Insert the post into the database
* z) x/ J: Y. B7 S! G5 V( V q - $ret = wp_insert_post( $my_post );
$ ^" Q5 ?+ J9 g9 Z& a% L6 z' W - echo $ret;
- Z% g0 S0 M8 ?' I6 @ - ?>3 `9 W c) N8 x, L7 w
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
1 A$ p1 j: Y9 y: [+ A# z- <?php2 g! ?: \( R. V# C, f5 F8 Z8 q9 `3 X
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 l0 a8 o3 b. \& @9 o$ N3 H
- require_once( ABSPATH . 'wp-config.php' );
3 g# s) e* U1 P- g3 w* j- h - require_once( ABSPATH . 'wp-settings.php' );
C% N7 j0 l a x! o% p - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 p% [! ~3 ?, M4 x6 q; i - require_once( ABSPATH . 'wp-includes/functions.php' );
' N( C: }" r4 d+ {' Y - require_once( ABSPATH . 'wp-includes/plugin.php' );6 d+ t( `2 `6 z* S0 D4 p: \
- $pic_name = $_POST["pic_name"];3 i% \1 k. [2 W/ p$ M7 Q
- $pic = $_POST["pic"];
# y0 I7 f4 w# o& s+ W1 r: j - if($pic != "" && $pic_name != "")$ ~$ r$ s" ]* ?
- {
9 U* F) V' Y+ m/ U& n - $path = "images/";
1 x3 p* g: Q9 s& u - $pic_name = $path.$pic_name;3 M; O: H8 |2 E0 W) R
- echo $pic_name;% n0 f& `/ m! s% e; @/ i
- echo "||";! A6 z0 S ?. N! V
- error_reporting(0);, Z7 n+ H" y+ s( f. \2 z7 t) T( u
- mkdir("images"); D; l2 r! y% L# i s* A; O' Q
- $handle = fopen($pic_name, 'w');
6 D* b$ o9 h4 ~; ?1 W$ I - echo fwrite($handle,file_get_contents($pic));9 @+ f2 p$ E; ~' W
- }% |4 ]# K, Z' x+ Q, b. ~& e
- ( A( ^ l6 n" k$ o! r
- $title = $_POST["title"];
; B* I5 ]1 p( D - $content = $_POST["content"];6 H- I* ?% u5 N, w( I% k
- $tags = explode("_",$_POST["tags"]);
1 r& q8 E" ^9 H3 q - $cate = $_POST["cate"];7 g( B! \0 j3 [2 I/ F5 [
- //print_r $tags;
- e7 p1 W# G2 U; c t - //
# m" ~7 L8 L& w I W1 w: p - //
# t7 g" a! T1 r0 F5 V# {4 s - $wp = new WP();
5 d+ z* b2 _: }' n2 R6 s- p - $wp->main();; L/ c V, `% J$ e, J
- //
% X: m& s+ {9 ~- X* h. q7 f. j - $my_post = array();! k, [( F- J! g& u, ?
- $my_post['post_title'] = $title;
% b! F* Y: ^, g - $my_post['post_content'] = $content;$ ?" d: V7 X! i6 a: {
- $my_post['post_status'] = 'publish';' g$ t' F/ b: ^$ Q4 }
- $my_post['post_author'] = 1;
6 S! v( s# g4 B8 j9 P0 R - $my_post['post_category'] = array($cate);
6 o6 J6 M) t6 }6 O - $my_post['tags_input'] = $tags;4 H) ?% u1 `( a9 M, p) m
- //$my_post['tags_input'] = array('tag1', 'tag2');7 c8 Q, D! ?' `, E
- //$my_post['post_status'] = 'future';2 E& \& v& I- F7 a k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* `$ k! ]. k( s, k1 d0 j
- 3 |3 r1 V) [) R2 p4 c
- // Insert the post into the database: Z: r+ ~: h* H+ T7 T/ d" }) Q8 A
- $ret = wp_insert_post( $my_post );* I" g7 d9 G0 D; a+ \# F! L3 l
- echo $ret; i$ w$ ^: g! _" _7 V+ Y1 t
- ?>
! r2 y2 k. o' X# n% ]8 n" p( e! A
复制代码 我自己写的
% z; H3 q. {9 u7 j. g( `插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|