|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 $ {! {, Y) W& C7 V$ m2 a
# E/ @$ ]5 g: N f
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持- ?3 s" c0 p2 c2 o7 H
1 K0 B" B+ l5 U, z% E$ P我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了% t" S7 N9 i% ^
% Q$ \8 r0 P' [$ A0 g
方便实用 简单 何乐而不用呢- ; f/ n7 m. B+ @" [' Z/ L
- <?php
% Z8 {* ^ j* i2 L$ O/ g, d6 ]- f
: I. W' i' ?( M( z9 @' n+ Z- define( 'ABSPATH', dirname(__FILE__) . '/' );' X2 S7 D' ^ y+ `8 b' p( `
- require_once( ABSPATH . 'wp-config.php' );! M/ o8 q3 D" {4 z3 e
- require_once( ABSPATH . 'wp-settings.php' );
0 Q$ }2 `) v6 N/ ]& e; m7 M; }$ P - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: `4 r/ z$ c; F6 A6 Y& a9 r - require_once( ABSPATH . 'wp-includes/functions.php' );
+ ?3 t4 ~. V7 f! E8 V/ G+ p+ D% R) y - require_once( ABSPATH . 'wp-includes/plugin.php' );( o: ?; h( H2 g6 R2 Z7 t
- $title = $_POST["title"];
" k+ M3 l+ t* D - $content = $_POST["content"];; G# d# c7 `. l$ V! @8 g3 g( o2 E1 K
- $tags = explode("_",$_POST["tags"]);
+ l( n1 u2 s, U) c1 T - $cate = $_POST["cate"];
' [2 ^9 T0 p' r - //print_r $tags;! C" g; k! R; ^" K# V
- //: D& D9 x8 k7 I
- //6 {* H4 w1 o5 ~2 \& [! [
- $wp = new WP();
6 c) _( c! s7 c9 z2 B4 X9 W I - $wp->main();
, m( u/ |' M% h6 r/ ^( O - //2 [- D+ M8 _2 }2 m2 u6 K
- $my_post = array();
* e* i9 z/ o% C) h0 }4 o - $my_post['post_title'] = $title;
& S* C0 a8 p8 R! ?8 `: t - $my_post['post_content'] = $content;
3 |/ D, D9 ]$ x8 N - $my_post['post_status'] = 'publish';
( \: i, P2 g% E! s( E! a8 W. }+ g - $my_post['post_author'] = 1;
# G' f: `3 N% g+ r- V6 b# ? - $my_post['post_category'] = array($cate);
& f6 i! r4 L+ a) j5 I; y - $my_post['tags_input'] = $tags;
. X/ d' J- b* V7 l3 A - //$my_post['tags_input'] = array('tag1', 'tag2');4 q4 z( V: [ p$ q$ L
- //$my_post['post_status'] = 'future';
( J0 O' c8 L7 P - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: f0 o7 Z" C5 A6 h3 S - ' I' J3 r- Y3 x
- // Insert the post into the database
& x$ s6 \' i2 _! [, T4 b2 S - $ret = wp_insert_post( $my_post );
* b+ s6 ~( x, ?# T - echo $ret;
" D9 C3 s% j2 `3 M- D# C - ?>
% i5 Z( O [$ I+ r. K
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; A' ?8 B8 h3 e4 U: ^
- <?php
9 }! u6 w6 Q# S5 G - define( 'ABSPATH', dirname(__FILE__) . '/' );
. l: C2 j+ u! r! p' i - require_once( ABSPATH . 'wp-config.php' );9 |9 |' O8 S: c& ?! N; Z
- require_once( ABSPATH . 'wp-settings.php' );9 F3 ~6 c; |3 F/ [0 ?. L: _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
~6 ~, D9 {& X7 x6 U& P( P - require_once( ABSPATH . 'wp-includes/functions.php' );
) `, c5 z5 X$ Y' _; C - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ M! c9 G6 L- V1 f" b# A - $pic_name = $_POST["pic_name"];0 G7 k: n5 `; B! R3 A8 t7 M
- $pic = $_POST["pic"];( l p5 G+ _5 c: B$ K7 z
- if($pic != "" && $pic_name != "")" |. ~& A2 Q7 D) t# N
- {- t& v8 H' S0 \! I/ _. Y
- $path = "images/";% A. v' P" n9 }* ?+ ?6 ]: }6 C
- $pic_name = $path.$pic_name;
- g( e$ Z0 | {( h: n0 T - echo $pic_name;
5 Y/ H# d- x) D1 M: E$ {& b+ O - echo "||";$ g' j( D% P) W* j5 E& w
- error_reporting(0);, U: r# M9 k+ H2 l
- mkdir("images"); s d2 _1 z; o- E) m- g
- $handle = fopen($pic_name, 'w'); F5 g' a. q! G
- echo fwrite($handle,file_get_contents($pic));
- ~& ^; W3 i& `. D0 N4 r - }2 V- v- P# P h8 [; s" Y
7 j: Q: w8 @, u8 E" G7 P5 d- $title = $_POST["title"];+ u% R& U" R6 K1 g- e3 `
- $content = $_POST["content"];
8 t$ l# `2 t& z1 W' S* j% V7 A - $tags = explode("_",$_POST["tags"]);
4 g/ n2 ~. y0 C, Q# G - $cate = $_POST["cate"];4 U2 U: J" h/ o- F/ |
- //print_r $tags;. R A3 g8 R- `9 E
- //+ ?( L3 B! L+ x4 {/ k) L
- // O! Y4 S1 X$ ]7 v! w& s
- $wp = new WP();
# J |7 p% X7 x5 W0 g - $wp->main();
' {. q6 }3 V7 B - //+ S) c! }/ j* J! C8 p
- $my_post = array();" R* M2 d! b0 h. ?1 D$ ^% E" F, A
- $my_post['post_title'] = $title;
" ^! m1 u* U H - $my_post['post_content'] = $content;9 ~7 `% a( H$ u H
- $my_post['post_status'] = 'publish';% [8 I7 w' t, U0 z3 H8 l" Y
- $my_post['post_author'] = 1;+ [6 ^! Y& s5 a+ V: a
- $my_post['post_category'] = array($cate);
/ T# {$ n* w0 E- C, L8 T K - $my_post['tags_input'] = $tags;/ z* i! b; l9 f7 R! I7 J6 K# M
- //$my_post['tags_input'] = array('tag1', 'tag2');
, M o/ B$ l, Q3 {$ { - //$my_post['post_status'] = 'future';
) y- [5 f# W& j% { - ////$my_post['post_date'] = '2010-07-04 16:20:03';4 g- z1 M, e! R. ~" v, P
- 9 t+ q8 ]1 M9 C! v- x
- // Insert the post into the database- b1 D s& \% I, n. H& w+ z
- $ret = wp_insert_post( $my_post );
: f2 D1 r) E0 [7 L; T% \4 [% q - echo $ret;$ k, d/ Y/ z+ ^1 x2 q
- ?>* [+ _3 n- |+ {
复制代码 我自己写的. G' S( @& i5 N/ C0 i4 G- e! `
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|