|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 7 z, ? y2 W+ B( i# W) U
; `0 o) z x: Q- M$ T) E
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, F2 x I* |- o9 e+ x/ d1 S! |" Y, P: U9 b* M* ~5 h
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
) \" B$ e+ D- i6 z- F8 ?$ a. H! q; t* b; {( h
方便实用 简单 何乐而不用呢
. n: t9 J' K8 x- k' d; \- <?php
* k0 b) m7 w6 N% ^9 C$ L" {
! p: N5 [ g$ t% |1 l) A- define( 'ABSPATH', dirname(__FILE__) . '/' );1 d" ?3 t: E T) n$ x, o( a* L
- require_once( ABSPATH . 'wp-config.php' );( v8 J; W3 A+ r
- require_once( ABSPATH . 'wp-settings.php' );$ W! `2 e# g0 S) m4 h1 L# y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 f+ q7 M' ^6 y( ` - require_once( ABSPATH . 'wp-includes/functions.php' );: k9 V! Z4 }$ J4 {8 ^& M- N
- require_once( ABSPATH . 'wp-includes/plugin.php' );; Z1 d, V: l" {7 T
- $title = $_POST["title"];1 x2 O8 M: D% k0 I7 a
- $content = $_POST["content"];
' Q" N3 z2 o @# I2 F- m - $tags = explode("_",$_POST["tags"]);
& j. V9 i6 ^3 G+ B ` - $cate = $_POST["cate"];+ c3 P3 c$ L, S
- //print_r $tags;
. {( f7 ~! D% |+ t4 ] - //6 l# u/ s" K+ i3 R, b
- //) p! u$ ~6 f6 W0 b
- $wp = new WP();
. ?- c8 H0 @$ {# |1 J- @4 w - $wp->main();
/ Y5 @9 E8 [& v L - //
0 A1 x% I4 c' D: x& r! v% Z - $my_post = array();. t0 s5 ^3 F# k3 } ]) t
- $my_post['post_title'] = $title;
4 d, F- H: w% s4 a - $my_post['post_content'] = $content;/ P" y( ?- L n0 w
- $my_post['post_status'] = 'publish';
! G- e- w) u: I; x7 X - $my_post['post_author'] = 1;
, l- c; W7 s% u; X, ^/ m) J$ g - $my_post['post_category'] = array($cate);
" n2 c3 [* d; j0 T1 t - $my_post['tags_input'] = $tags;
& L% z* i, a9 m {( {+ Y$ B - //$my_post['tags_input'] = array('tag1', 'tag2');
. m) G" z3 z/ P6 a3 D - //$my_post['post_status'] = 'future';- M) |3 c: d/ M$ j* X
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* r0 y# ~; U! y2 I" J2 N3 B1 `
- 0 Z: h3 ~' z P* U( E$ S
- // Insert the post into the database" M, s0 r# y, ~# A$ W
- $ret = wp_insert_post( $my_post );
C. k- n) [: @' A; j - echo $ret;( i' [; l0 U M9 S4 t. S/ ~ t
- ?>
% R% e1 k' W H; V! ^0 N# U1 y4 P" }
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
. K' i; ?/ W3 u5 K6 {- <?php8 A" m) |2 u8 r; L) H* L
- define( 'ABSPATH', dirname(__FILE__) . '/' );- y! ^4 C( C9 ~4 E
- require_once( ABSPATH . 'wp-config.php' );" }. J/ u# q# H" K- @- J% ]
- require_once( ABSPATH . 'wp-settings.php' );5 Y& ?* I+ y# S" M J* s& T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 S# s1 I# a; W6 W- P - require_once( ABSPATH . 'wp-includes/functions.php' );; Z+ s: [: o" G1 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );8 ~2 [) @$ s" ^ x
- $pic_name = $_POST["pic_name"];
' r5 M- {9 [% s% U - $pic = $_POST["pic"]; I7 t: b! n* \4 j
- if($pic != "" && $pic_name != "")" s5 L3 M/ V' a% i+ I: d
- {* h# z4 G# i, h9 ]7 g
- $path = "images/";
* J; {; H( p1 w4 P* ?2 ^% k( k - $pic_name = $path.$pic_name;
5 m+ ]5 m' h! ] - echo $pic_name;
& Q5 d K# n" f1 m# q& f2 ] - echo "||";& h* q W" c2 y$ t( s
- error_reporting(0);: q$ V/ s0 \1 V( P( A5 D
- mkdir("images");
9 B K* n8 o$ o, t: @ - $handle = fopen($pic_name, 'w');
( K8 E% V# [; K) Y1 J1 r7 m4 w - echo fwrite($handle,file_get_contents($pic));$ G5 x' X# v* p. a
- }
6 C% R6 T" e2 z# v8 m - ' W, D9 f1 Q, c. j; D
- $title = $_POST["title"];
) k! `7 W& M% x( [' P - $content = $_POST["content"];& b- k* s1 n. K% X% o$ g; _
- $tags = explode("_",$_POST["tags"]); |; j# E5 |$ X/ `" ^- C
- $cate = $_POST["cate"];
' i: X7 p- D- x, l: q7 B9 @& e - //print_r $tags;
) \/ u7 q6 ~. g - //& L1 h: z& U; Q5 K
- //$ s" Y L2 A) m- o
- $wp = new WP();: y1 ] Z" ?# D! M) r, H
- $wp->main();; G) k8 u7 o4 m7 p: n _/ x' i {) B
- //
! q" O3 e& \5 R$ S - $my_post = array();
4 T& A8 d3 R$ A" r" C - $my_post['post_title'] = $title;8 t$ D, j$ k* @* V! v: C+ h. `/ @0 e
- $my_post['post_content'] = $content;
3 u9 k" E. H6 b$ f7 U% L( @7 { - $my_post['post_status'] = 'publish';
# K( D& V- ]* y* u) u0 u+ m+ X - $my_post['post_author'] = 1;6 ]2 p- i) Z/ b) n5 j+ N
- $my_post['post_category'] = array($cate);/ x; n; {, \% Y& x. f5 s: [
- $my_post['tags_input'] = $tags;
. h( f. ^3 R$ e5 h" T - //$my_post['tags_input'] = array('tag1', 'tag2');) b8 c3 t, |5 F) J
- //$my_post['post_status'] = 'future';/ r- N/ L; x% p+ W- D* U
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 _" Z1 O( ^ L* z1 R) B* D - , Q# y- X L& k, R# P. P& r
- // Insert the post into the database1 T0 y' s9 u0 Z+ `, i
- $ret = wp_insert_post( $my_post );( L* K7 `( ~, w$ d
- echo $ret;
4 m: W% k0 K6 E - ?>1 t4 G6 P/ ~! @& ? H
复制代码 我自己写的6 K7 y! w. o$ d) m$ z$ w
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|