|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 1 T$ S$ \/ e/ ` H' [0 s4 p
. F, ^& q$ o3 ~8 y! k7 ?直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
" x) [# w0 p, n+ ^
7 \& a$ V* F4 k* ~- h7 }% f5 ?我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
& L7 j9 k2 @: I* \5 Y5 w0 }6 f& \3 x
! p1 A4 w' D7 [% U方便实用 简单 何乐而不用呢
! W5 D0 b G; h1 I& p- <?php y; S' i+ V: U: P$ B
$ L- [- G9 V* ^! Q C& z- define( 'ABSPATH', dirname(__FILE__) . '/' );2 G, Z( D3 ] N: `: @# }
- require_once( ABSPATH . 'wp-config.php' );
/ K- m" J' g# Q! W0 V - require_once( ABSPATH . 'wp-settings.php' );
' A# V/ o5 R% Y# e - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 Q# e+ w2 T% u( z& _
- require_once( ABSPATH . 'wp-includes/functions.php' );6 O" K+ L" ~- f5 q+ F% o, |
- require_once( ABSPATH . 'wp-includes/plugin.php' );) j3 {9 ]3 G9 d/ ^$ v. I; B
- $title = $_POST["title"];
2 \. Z& M2 e, |+ r+ a - $content = $_POST["content"];
, W _* f; r" m2 G - $tags = explode("_",$_POST["tags"]);
1 H( T% E* c3 _2 z# q( E8 G - $cate = $_POST["cate"];+ K3 p% {( `. h9 K4 y
- //print_r $tags;( ^- A1 p$ s" L$ f7 [6 G" p! h0 d S% n1 \5 z
- //
& H; G {# N/ S$ T; c2 V - //
* u: j m8 h8 T' I - $wp = new WP();
! ~2 m5 P/ e2 F6 \* U- v! A) \+ u - $wp->main();
) R1 m, n* s0 A$ o0 d* K - //" x/ h" p( [( B/ n W
- $my_post = array();( b( \7 E- x) J: m4 H) `# L4 ^
- $my_post['post_title'] = $title;
2 C0 h! G! S9 O: s8 B2 t7 V% G - $my_post['post_content'] = $content;
; |; K7 l* |" m1 D - $my_post['post_status'] = 'publish';
/ O9 r! Z9 r; g - $my_post['post_author'] = 1;; @5 C( l* M0 \$ x5 {
- $my_post['post_category'] = array($cate);0 c- @' j# I$ ?% F" s3 a/ a: r1 H
- $my_post['tags_input'] = $tags;
0 @' i% M, |# f2 n1 U - //$my_post['tags_input'] = array('tag1', 'tag2');
+ X% ?, F' q/ j0 @5 f# L - //$my_post['post_status'] = 'future';# N L* u2 X/ U( C6 S _
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 {; x: H0 V1 y, P
# W4 ?2 j4 x6 b$ s/ C$ L- // Insert the post into the database, |8 y7 r5 ~. M5 Q& E7 p. k, ?
- $ret = wp_insert_post( $my_post );
: x: n" D; F9 x/ W4 H - echo $ret;
! G9 r2 C& k: |* m: c - ?>
; G3 t2 r9 S- E a$ r' e
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 t' g+ ?* L( }9 }# ?) t) B
- <?php
- y t5 j5 a. ^% P: X0 V, Y - define( 'ABSPATH', dirname(__FILE__) . '/' );9 T0 a. [+ z7 ^) Q5 i3 B0 K
- require_once( ABSPATH . 'wp-config.php' );' `! i& F3 J" r, `1 r/ B
- require_once( ABSPATH . 'wp-settings.php' );
O) u N; B! d3 k - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, t! y+ C1 m6 K# s$ c) Z8 I - require_once( ABSPATH . 'wp-includes/functions.php' );3 w- w: f6 f' p
- require_once( ABSPATH . 'wp-includes/plugin.php' );% j& E- E1 l \9 }: g# \& n% B( c
- $pic_name = $_POST["pic_name"];
) t2 O: \" \6 Q2 n7 k9 g. B' r - $pic = $_POST["pic"];' F7 P b% k' o
- if($pic != "" && $pic_name != "")3 @- \4 @! A9 j9 b) T
- {
' H/ _1 r0 o+ Q8 j! r8 ]( O& [ - $path = "images/";
" Q* ~) F- l+ W$ y, Q - $pic_name = $path.$pic_name;) R) Z: u. R7 `0 D0 @; w
- echo $pic_name;
- o, ^0 p. | V6 N - echo "||";
" n. Q8 y8 ^: e' S/ c% N" o - error_reporting(0);
' e; k) W5 K: v- P( X4 d( A - mkdir("images");# u: Y2 }- V' x: N
- $handle = fopen($pic_name, 'w');! R, @" ]3 y( S1 p
- echo fwrite($handle,file_get_contents($pic)); m* v4 h: Y; `1 V2 b4 Z( ~. `: K! C
- }
. w# m- O1 I& w
B1 R" ]. ]9 s$ ^/ ]) ^- $title = $_POST["title"];
7 `5 S5 l# T4 r" {; Y - $content = $_POST["content"]; e9 J* ^8 @) T) g9 M3 ~
- $tags = explode("_",$_POST["tags"]);# Q# C7 L( X. _* N0 D6 {) z; u o8 G
- $cate = $_POST["cate"];9 ^9 R3 k. E; t* M. y* l) C
- //print_r $tags;7 H2 ]& Z! ^1 r! W# N
- //
" S3 ]! N2 ?( Y+ I - //0 u$ n7 K$ q# f; N7 v" c8 [
- $wp = new WP();
/ N ?+ ]& k9 m - $wp->main(); N* ]1 [( Z8 _5 M% p: p9 M+ N
- //
& T. f% w. M$ o d' L; [ - $my_post = array();
8 n- v# f& r: }; \6 q - $my_post['post_title'] = $title;; M* D8 _+ A" w! r) G- i( n* v
- $my_post['post_content'] = $content;
/ @* Y" c, h6 Y% _ - $my_post['post_status'] = 'publish';( h+ R* |3 V8 ~% x0 p$ K. u: W. }
- $my_post['post_author'] = 1;( G6 K1 w- v* G
- $my_post['post_category'] = array($cate);
3 o9 G( n: H" T - $my_post['tags_input'] = $tags;) \* k; j7 `. {1 t) }( e
- //$my_post['tags_input'] = array('tag1', 'tag2');6 Z/ u; S; {) @% @; n
- //$my_post['post_status'] = 'future';
7 W' p" u3 s% {( b/ M - ////$my_post['post_date'] = '2010-07-04 16:20:03';1 ` K. T# E( D1 _9 d
- / a% y' C5 S/ L# R& H
- // Insert the post into the database9 g2 H: } o+ |, i# W
- $ret = wp_insert_post( $my_post );
! O/ Y2 a1 c& Z$ n# d7 N, r - echo $ret;1 h, Q0 C/ P/ e" i& O
- ?>
% X( g8 _8 M8 ?
复制代码 我自己写的8 s$ `' H" [+ [. }: t& w' g
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|