|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
P) U8 {! t0 o6 ?4 A
2 F) x& k q8 y4 |8 ~* ]6 v" g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% L! p9 N% |7 \7 n3 W8 j5 L
+ H. H0 r$ O0 N% G+ v, X# |我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了+ }! d8 ~0 U5 B$ T# S3 U) x: s5 T
8 f( s" [( u1 S) i7 |
方便实用 简单 何乐而不用呢- 2 E4 @) H# g! q1 x# {/ s
- <?php
3 w; b8 H9 e! T4 k - . L0 M$ g6 c$ t
- define( 'ABSPATH', dirname(__FILE__) . '/' );9 l, q$ R! |; t, ]
- require_once( ABSPATH . 'wp-config.php' ); L! F0 V- q" x% H
- require_once( ABSPATH . 'wp-settings.php' );' N, Z5 t% l9 C. A; V. V% W
- require_once( ABSPATH . 'wp-includes/class-wp.php' );. f3 m) [' m' W; _8 D- k! C- [( A
- require_once( ABSPATH . 'wp-includes/functions.php' );
6 V9 `( a( }; C* S3 u" s - require_once( ABSPATH . 'wp-includes/plugin.php' );, j# R7 a- r% Z2 T
- $title = $_POST["title"];
# s; }" b1 L4 H' x; g0 w - $content = $_POST["content"];( \! J, V" n3 K7 N
- $tags = explode("_",$_POST["tags"]);; w( W( H# j) [* P
- $cate = $_POST["cate"];
: Q+ E) R2 Y0 C# E5 I5 r1 U) Q - //print_r $tags; J/ ^7 i9 Z3 w, a8 q' h' R" W9 k$ J* t
- //
# B: o9 O* B! a; e( H4 \! U - //
R9 K8 c% f4 K( a. z+ O( Q - $wp = new WP();
9 y: [) k' Z+ p* D7 X - $wp->main();
" f: |- K5 s- Q* T' u/ U. h - //
- p/ Y+ d, C$ w+ ~2 _" t% C4 T( f - $my_post = array();& o1 x% R t1 R1 y* O! A+ h& j+ R
- $my_post['post_title'] = $title;( P+ g# u) ?8 W! x3 K2 D" `9 z
- $my_post['post_content'] = $content;8 u+ _+ x4 {, \# ]9 z2 M
- $my_post['post_status'] = 'publish';
0 B- o. V+ A# T! t3 W* ]8 @: T4 S - $my_post['post_author'] = 1;9 J0 g+ g" g7 A# V7 c
- $my_post['post_category'] = array($cate);
' K0 w, a/ O* A s7 O3 H h - $my_post['tags_input'] = $tags;
$ c7 c5 o8 }" B9 i$ P$ { - //$my_post['tags_input'] = array('tag1', 'tag2');
/ {2 N6 D# p1 B4 F9 M5 E - //$my_post['post_status'] = 'future';( c& f6 Z2 |! `7 U" ]6 F. y+ c. j
- ////$my_post['post_date'] = '2010-07-04 16:20:03';& z, z9 _3 i) h I
% u" J$ k: w9 i1 V8 u3 S6 w6 G- // Insert the post into the database- \. X6 `! l1 x' `1 t* F
- $ret = wp_insert_post( $my_post );( ^( G9 \1 ?$ E$ c, x; T
- echo $ret;
$ V' c$ Z2 G! g. g/ m - ?>1 l. M( @8 S3 f1 `9 M8 P( h0 s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
$ s/ e$ Y0 P1 J, J/ t4 Y2 L+ V1 |- <?php
4 I' a+ N! A% ]# ~- i - define( 'ABSPATH', dirname(__FILE__) . '/' );# ~* f' o1 A3 S7 M l2 }3 Y
- require_once( ABSPATH . 'wp-config.php' );1 J( [- U1 f5 R6 f
- require_once( ABSPATH . 'wp-settings.php' );4 I7 r9 Y* p) ^8 c/ M+ D
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; W+ Q2 V; \$ y9 M( H4 y - require_once( ABSPATH . 'wp-includes/functions.php' );' x" D- N$ M+ l. b$ {
- require_once( ABSPATH . 'wp-includes/plugin.php' );& b: u0 { }4 E: l9 u1 O+ ~, ~
- $pic_name = $_POST["pic_name"];+ g- _1 M0 p. t
- $pic = $_POST["pic"];
3 J6 F" b3 V, J, d; j8 F' k - if($pic != "" && $pic_name != "")6 G1 a$ c! d" n9 O+ G0 K
- {
! b# j3 i8 b- W$ s9 y- w - $path = "images/";9 U( ~3 C& b4 f2 p- z
- $pic_name = $path.$pic_name;4 _6 G0 h( Z1 {2 s) V; w% @' I; B
- echo $pic_name;; B: e) k! }9 E$ v" f9 @6 z3 q; u& B( M
- echo "||";
' ?/ w. k: o6 U, s - error_reporting(0);$ u5 } N/ n7 ~: J& C7 E4 \
- mkdir("images");0 I2 j8 Q9 [/ q5 F7 ?3 h
- $handle = fopen($pic_name, 'w');
% C+ t$ ^3 f; E+ ^: J6 k4 L - echo fwrite($handle,file_get_contents($pic));
% d3 y }, X+ y7 U# }6 A* Y3 ^ - }
, R% U2 R' { {. @3 [+ @! l
% E% V; u& J# c% ]8 r& M- $title = $_POST["title"];
: J1 c5 k c( d9 E3 B# o/ M) }3 Z - $content = $_POST["content"];, E8 c: ~& r" N4 r1 M0 J3 O! d3 K- H
- $tags = explode("_",$_POST["tags"]);
, w9 l0 t4 T4 n$ c; L - $cate = $_POST["cate"];
0 P& }+ T% i7 b, A - //print_r $tags;
1 m0 s0 \1 y0 U6 M/ b) N - //
3 N4 R; _' e q' t# @ ]# _8 y - //! u# C1 Q4 @ k
- $wp = new WP();
8 m' e% o- O6 Q1 L, O8 A& D - $wp->main();
* o# h( O( K# f! X& N0 l - //" v0 a7 _$ j1 M
- $my_post = array();& m9 G9 J1 U2 g7 \. x& L7 l
- $my_post['post_title'] = $title;
' c7 y1 Q$ P* I2 ^. z - $my_post['post_content'] = $content;
7 T0 D ~+ Z0 i! @ - $my_post['post_status'] = 'publish';
h! c" g$ o) s - $my_post['post_author'] = 1;
; S8 L$ L+ O: ] - $my_post['post_category'] = array($cate);
& g3 H7 _) M' ` - $my_post['tags_input'] = $tags;
9 e0 A0 S! ~" }. C6 P1 I9 d - //$my_post['tags_input'] = array('tag1', 'tag2');
. v& h" N5 @" N - //$my_post['post_status'] = 'future';% ~) e1 A3 `4 u! }
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 [) j9 m8 M1 ], Y; v
; _2 g$ M, J$ \4 Y0 ^" P- // Insert the post into the database% b3 A& m) T& o3 A0 y' @- l9 r
- $ret = wp_insert_post( $my_post );1 L# ?9 k$ g4 U! y! K
- echo $ret;1 _ C/ Y; d% g7 C
- ?>) G7 m+ U% P3 R1 P5 j# _' H
复制代码 我自己写的$ l! _4 r6 o: h) ]% }- p8 x
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|