|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
& r9 V& @9 y e$ |7 u
1 p; [1 `5 i2 g& u1 }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. `8 u: [+ C9 P7 I7 w6 ]- C
9 C- z' a7 [4 {我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ }, |9 Q" y) p, o5 l+ ~: G |, q& W$ E
方便实用 简单 何乐而不用呢- + E- F6 H0 r; e% L
- <?php
; o3 D+ C) P2 A7 x. X, w* s - 6 v1 a" W8 k0 u* n( y# C a7 y
- define( 'ABSPATH', dirname(__FILE__) . '/' );% I/ M6 K+ j" V& \( m
- require_once( ABSPATH . 'wp-config.php' );
3 U& ~+ B- X" {6 s2 C3 Q* C. I. V - require_once( ABSPATH . 'wp-settings.php' );
- c8 G: s$ Z$ H) W+ {1 E4 r - require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ c4 a; V" {' T5 E' t; e - require_once( ABSPATH . 'wp-includes/functions.php' );) K! W6 N7 K5 G/ l3 K/ Y. F) }! m* p
- require_once( ABSPATH . 'wp-includes/plugin.php' );( z1 v) T5 v0 r7 n) t
- $title = $_POST["title"];
2 K: Z; M2 t& p, L. I4 G - $content = $_POST["content"];
|; ]5 z6 i4 r; H; s8 m - $tags = explode("_",$_POST["tags"]);& ?9 f5 @1 a( x7 }. N1 a
- $cate = $_POST["cate"];
s7 A$ [( H1 ^2 x6 C( T4 u - //print_r $tags;4 Q1 [+ h0 C: N
- //5 F1 I$ C) N! A, H
- //% b7 t8 x/ ]1 l
- $wp = new WP();
& @: N, r8 \1 Z2 j: [9 i! P - $wp->main();
1 N5 H+ n% U+ b* X - //8 w9 d$ ?. V4 X" u% |( i
- $my_post = array();
) b ?$ k' ]/ G4 R - $my_post['post_title'] = $title; r3 r. v- ]8 e: N
- $my_post['post_content'] = $content;4 r4 n, Q. U* R; y& f+ i( I
- $my_post['post_status'] = 'publish';
! E( [: N7 [' \2 k1 E, P - $my_post['post_author'] = 1;
( U; b9 b4 q3 f" p' Q, c' h - $my_post['post_category'] = array($cate);
! s5 g( j- R* ]5 J6 m2 e - $my_post['tags_input'] = $tags;
0 J; b6 D' q6 M! n: j - //$my_post['tags_input'] = array('tag1', 'tag2');9 C/ U4 v# @4 f9 A& C9 a
- //$my_post['post_status'] = 'future';
], ]4 Y# i7 K8 z. c - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( S; J( H2 f( n4 r2 c. h: { j! C
3 i/ d f& g; X8 e. Z% t$ s. E+ j& t- // Insert the post into the database
" G9 q; m; X% P# ? - $ret = wp_insert_post( $my_post );' ]# i, e3 O9 p: d7 }
- echo $ret;6 ~, d$ t% z% Z
- ?>
8 w. ?/ _$ \9 U E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 F M& I) R/ }6 h) V* i- <?php& z. ^9 \1 s0 {
- define( 'ABSPATH', dirname(__FILE__) . '/' );- @+ _$ K7 K M8 `$ `8 b
- require_once( ABSPATH . 'wp-config.php' );
4 ?4 ]& X v3 q: Y6 `( M' u. [9 F - require_once( ABSPATH . 'wp-settings.php' );/ h# E! r: R) E) C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );# S- m5 {) q! D& j# |+ o+ [
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ _0 d. g* W8 h - require_once( ABSPATH . 'wp-includes/plugin.php' );
M8 i: i7 B6 L- Z4 o4 b - $pic_name = $_POST["pic_name"];1 B* [$ B/ s- W% M, f) _, z4 P
- $pic = $_POST["pic"];5 O! Y: J7 s5 x N9 g# H9 I' s: d. I
- if($pic != "" && $pic_name != "")+ r- ~( k2 q: N {
- {
* k- |" C4 G; ~& D) b% _ - $path = "images/";7 F) K- ^! C# O* i4 d; n3 M( }
- $pic_name = $path.$pic_name;
- Q0 ?/ ?7 O e4 j - echo $pic_name;8 t% E1 }3 Q& |$ {. w. |
- echo "||";
6 f- T A3 X; {. w) O& A - error_reporting(0);
% J8 w7 M7 n: J! a1 Z% a( X- D - mkdir("images");
1 d; {" K Y4 Q: y - $handle = fopen($pic_name, 'w');; {3 a! z( |' A" h- I
- echo fwrite($handle,file_get_contents($pic));
" U* i& X5 l" n! g& w6 {4 n$ @! S* M( O$ H - }+ }0 w! @8 [! g5 _
- 0 }" t; I1 `- G4 j( e4 K
- $title = $_POST["title"];
' N7 E9 F% l4 p) ?: a; J - $content = $_POST["content"];" y$ q/ H$ x9 h2 l2 g7 V
- $tags = explode("_",$_POST["tags"]);/ Z& X5 |1 c7 N
- $cate = $_POST["cate"];8 l+ b. l- ]$ X
- //print_r $tags;+ { E4 Q r; Z8 S$ a6 ^6 N( I, ^
- //
2 [" b" \) A3 y8 V - //2 B% u7 ~4 a+ N6 _& G4 A
- $wp = new WP();2 z! \/ h1 t. k. t3 K
- $wp->main();
# e3 J e2 {1 T2 R! B& y) v: b! H/ o6 M+ f - //1 y! b- I" c; f) ^7 ~
- $my_post = array();
& _1 c6 i) Y/ S& e& }( J - $my_post['post_title'] = $title;
3 k- B7 \: W& s7 J! | - $my_post['post_content'] = $content;
7 G9 b: y$ V" m8 A0 d9 p - $my_post['post_status'] = 'publish';
' D, a2 q" `1 |& I* _9 e - $my_post['post_author'] = 1;
1 Q2 U5 ]+ L k" B' U( Y3 e - $my_post['post_category'] = array($cate);
1 Q D. v5 |! a4 v5 q6 F+ U) }* { - $my_post['tags_input'] = $tags;4 n# F" g1 t L; _8 b6 c
- //$my_post['tags_input'] = array('tag1', 'tag2');4 \3 E) }4 P0 K/ P' X# `
- //$my_post['post_status'] = 'future';
9 R: E% j$ S" w6 I1 x. K+ ` - ////$my_post['post_date'] = '2010-07-04 16:20:03';# Z5 P$ {4 b) A0 k% q3 y3 P* i
: B1 U% @( R2 I: B! I& R( D9 y- // Insert the post into the database
0 N7 D6 @* {, w4 x - $ret = wp_insert_post( $my_post ); U$ ]7 ?! i7 x' N _$ K
- echo $ret;
, Z, D1 M0 y: \, f9 P* [2 @4 K - ?># z5 w" v/ r/ i0 c/ ]0 h
复制代码 我自己写的7 S- A+ E3 ]9 |2 e# [5 K
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|