|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 $ D- N/ Y* Y4 X% T0 L' B! ?8 P
) ?. T) R% `$ i+ P: E) j" s直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
6 r9 Y% Y6 q8 w8 p7 }, R
' D& e1 A; P, F/ d5 c: [我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ R- u ?9 b+ p$ A% i* v
{* h7 O: X* j R3 K Y: a方便实用 简单 何乐而不用呢
# p. t: I7 K. `6 q) ^7 h- <?php
+ `! ]0 `; y. q4 V+ X
! H; {$ O! S6 ?2 _- define( 'ABSPATH', dirname(__FILE__) . '/' );: S. ^6 {3 V: o* S. F- O3 Q5 b
- require_once( ABSPATH . 'wp-config.php' );
! B5 E3 l' Z+ S! u* c - require_once( ABSPATH . 'wp-settings.php' );
* x" z7 g+ H; c. [3 [ - require_once( ABSPATH . 'wp-includes/class-wp.php' );: a; O3 K! I1 S( H% Y* P* t) z
- require_once( ABSPATH . 'wp-includes/functions.php' );9 r/ r4 o- {2 e
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: c" c6 z/ L3 d, P/ _( \ - $title = $_POST["title"];
" s4 c2 r8 v3 C4 B8 C ~ - $content = $_POST["content"];/ V1 Z/ f: |2 b9 K* E+ X$ a
- $tags = explode("_",$_POST["tags"]);
+ H5 V( [5 {9 i& j: d# T - $cate = $_POST["cate"];
3 f) d. _0 ~$ ?6 u1 S# E - //print_r $tags;
- |2 M; o( N6 q( o - //
2 O3 K' N/ `) Y3 r2 z9 Y - //
) J5 D' H9 s. n - $wp = new WP();0 N6 W5 Y, M% a
- $wp->main();
' A3 a# u, P9 `7 ~" f - //
. [/ `/ {, l8 d3 y! j, c. w' h - $my_post = array();% v+ \1 i, u3 k! n
- $my_post['post_title'] = $title;
6 Y) Y* Y3 K1 a X6 q2 M) ^% ` V - $my_post['post_content'] = $content;
# X5 ?4 ^( V' e& S% i |- [, Z - $my_post['post_status'] = 'publish';
! N S; ^: y4 `4 x6 t, d - $my_post['post_author'] = 1;8 w5 H8 C7 L+ | O
- $my_post['post_category'] = array($cate);
& G. }' O/ p- M* k/ `* A - $my_post['tags_input'] = $tags;8 g/ E k( \2 e) t; F
- //$my_post['tags_input'] = array('tag1', 'tag2');
; D* k. c, i) W1 P1 J) K - //$my_post['post_status'] = 'future';# W4 n% A2 ~6 O# y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 f; F3 n3 G: o) E, E! i# h# n @ - ' n1 @( w8 Q; d- Q# X
- // Insert the post into the database
5 T! I* R8 S& S! ]: S+ ~, j - $ret = wp_insert_post( $my_post );
4 L9 x# x* c( @, U- Y( Y; o: [ - echo $ret;
4 [( s! p V# Q$ | @$ e) H8 ~ - ?>
( n+ Y1 B% l% F f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 Q" D* U5 r' ^% L9 m& R6 j( i
- <?php, \! F; g6 F/ [3 z
- define( 'ABSPATH', dirname(__FILE__) . '/' );
% ^ g S) E3 J3 S - require_once( ABSPATH . 'wp-config.php' );3 _: c) N! _& q5 Q
- require_once( ABSPATH . 'wp-settings.php' );7 W7 e- o0 a7 y9 j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! j: w2 J* G# p( E0 J# y& _% z - require_once( ABSPATH . 'wp-includes/functions.php' );& U1 o& b& c b/ I" ~8 y+ W3 V0 _* h
- require_once( ABSPATH . 'wp-includes/plugin.php' ); \/ e- u! c: {2 P* a
- $pic_name = $_POST["pic_name"];9 e: o0 x/ {; i; a4 x
- $pic = $_POST["pic"];( b4 d0 Q: Z% x7 x" y7 z9 {# C+ N. M
- if($pic != "" && $pic_name != "")6 r2 X* ^/ ], B, A0 l) g6 O
- {$ K9 {1 S9 d$ d! q' d9 u3 Z$ I
- $path = "images/";
1 c. N; B" ]* t: p - $pic_name = $path.$pic_name;
! r ~/ N% n& C4 X+ c! } - echo $pic_name;
& H5 G4 y, g6 o - echo "||";
8 B/ d _: G& ]: e( T - error_reporting(0);7 j9 Q9 p* ^( F& ^
- mkdir("images");
/ k3 H4 z2 M+ V( C8 }) B - $handle = fopen($pic_name, 'w');. \; }1 H# _6 Q' T
- echo fwrite($handle,file_get_contents($pic));
! ?9 x% a! A3 t. q( c- y4 ^$ m# B - }, y) ~& X3 I& T3 |, C
- 3 U: |; @% L- W- a
- $title = $_POST["title"];# k R3 x! s- \- f+ H. p. Y
- $content = $_POST["content"];
; Q' |: s3 i4 g% Y - $tags = explode("_",$_POST["tags"]);$ o8 a' w# k" _! ~7 I5 Y _% d6 l I7 M
- $cate = $_POST["cate"];
' i) N; i" x: [1 {8 H - //print_r $tags;
! t1 v8 O. W( A; B0 L/ Z - //' w3 I8 R: z# }! I7 q5 n
- //
! s5 T8 l8 d4 g+ y* ~' ^7 f- q0 s5 A) p - $wp = new WP();0 I; `0 l/ |/ Y/ V* e G, A W
- $wp->main();
/ [8 m1 o! S- {- | - //
/ e' `' z. U- o/ i% u - $my_post = array();" E- `' I9 n; f
- $my_post['post_title'] = $title;
1 u3 O( [ j5 y8 z - $my_post['post_content'] = $content;
7 ` a) J8 W* @' U- i7 T - $my_post['post_status'] = 'publish';/ g6 W" l3 C) q3 b, n6 I$ E! K
- $my_post['post_author'] = 1;
4 F0 F" D/ s7 @ - $my_post['post_category'] = array($cate);6 W+ c1 G& ?; B& z$ i3 |
- $my_post['tags_input'] = $tags;
' | D ?& Z! P8 @4 t" @% u% [ - //$my_post['tags_input'] = array('tag1', 'tag2'); T" i. L# v9 v+ Z% d) b
- //$my_post['post_status'] = 'future';
6 E t1 X% F* l! s0 w$ |1 a - ////$my_post['post_date'] = '2010-07-04 16:20:03';9 N- q h& ^5 g/ s3 w! l. M& {* s
2 i: |! Q7 x$ ] z0 k6 Q- // Insert the post into the database
7 G3 |# o N/ n7 _' c, U3 C- } - $ret = wp_insert_post( $my_post );8 r5 H1 X) @! M! [( s
- echo $ret;; E G0 y. U; r0 _* x
- ?>
+ t" y* M9 ?2 u2 m6 P @
复制代码 我自己写的
F0 [2 |. X! c, i, W6 I3 y插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|