|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; c, _, A; l. d3 F- k; m
8 P& c* k y( R, B& a1 z直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 u# }" z) t/ r5 S7 }6 q
) O+ p" o! F! K. q: x2 T我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了! h }8 r- ?8 G t3 b D
, h/ w( P9 H4 A$ h6 S1 y- k: f方便实用 简单 何乐而不用呢- , n5 H4 @" S- i; D$ P
- <?php
( d% |& `# V/ P7 z - 7 H' `9 ?! ]" m+ q, u
- define( 'ABSPATH', dirname(__FILE__) . '/' );3 ~+ u; y8 S4 ^. G z2 j- \+ Q
- require_once( ABSPATH . 'wp-config.php' );/ ]; @4 p8 ]/ K0 g/ K
- require_once( ABSPATH . 'wp-settings.php' );3 h g( ~( M/ w, |3 A; ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );+ L, x9 P& N) J% j
- require_once( ABSPATH . 'wp-includes/functions.php' );$ I. G/ }+ j! c; C1 B
- require_once( ABSPATH . 'wp-includes/plugin.php' );
' p; S7 {1 Y; H* q* q - $title = $_POST["title"];
6 `6 P9 l3 E: L j2 h6 X0 Q - $content = $_POST["content"];
* L, L, C4 }3 v - $tags = explode("_",$_POST["tags"]);
9 z5 V5 F8 \8 M! ~ - $cate = $_POST["cate"];4 W( K3 z* j9 u1 ]0 C
- //print_r $tags;
- D. S1 p; \; u; H% c# w. n - //
& e( N" R) z" e* s. w" E: P - //
: d2 \3 i5 R' V( m6 [( u - $wp = new WP();, W# H9 h5 X- r6 Y/ z, h
- $wp->main();
) K5 a# ^ Z' x9 `2 w6 ]2 s6 Z% d. v - //
+ c$ u( K0 y; x1 |2 M! c4 m - $my_post = array();
$ U6 G+ S# P! Q5 I) n! c - $my_post['post_title'] = $title;. F, B# X5 x( \2 Y0 M2 y1 ^
- $my_post['post_content'] = $content;
8 J0 J) L2 I$ |. ~( t - $my_post['post_status'] = 'publish';
! M$ m' U0 I* O! ^/ r5 p, x$ W - $my_post['post_author'] = 1;3 e* u* t# d4 m% r
- $my_post['post_category'] = array($cate);
+ \2 b- h- [& d - $my_post['tags_input'] = $tags;4 P1 N, L/ V6 n9 D+ Q: \7 |; m
- //$my_post['tags_input'] = array('tag1', 'tag2');
7 n( l* Z/ S# E - //$my_post['post_status'] = 'future';
: D0 m# o; Z. C* o( c8 m5 ] }$ i$ ~0 k - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 r$ y7 u) ~5 H: |. w - - ~- \) C) G! G- r! B; `
- // Insert the post into the database/ i' N0 w2 n/ M# m* |$ x6 I. g6 u8 ^$ d
- $ret = wp_insert_post( $my_post );" n* V5 w1 x9 q) H
- echo $ret;
( m! f: Z: @- S+ u5 r- L3 A) r - ?>! C/ K; |% `1 L" }" [
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 G* b+ x# Q \/ }
- <?php8 e/ I( h f. y; t( R
- define( 'ABSPATH', dirname(__FILE__) . '/' );; t5 k0 N! W' v/ r9 f& c: G
- require_once( ABSPATH . 'wp-config.php' );9 m# c/ m: @5 A% `0 |. M$ X" i
- require_once( ABSPATH . 'wp-settings.php' );, U* L6 B- C( g4 J
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; V) V( j& b! k! U* W - require_once( ABSPATH . 'wp-includes/functions.php' );7 s, \ }2 v/ W( C( b- l
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! T; n% ~! ?/ y - $pic_name = $_POST["pic_name"];
) N: y7 H9 [/ X - $pic = $_POST["pic"];
7 o; y! J/ ]8 m$ j" n* \% v - if($pic != "" && $pic_name != "")
% A0 C# Y! s0 Q4 ^ - {
8 y; m& G [5 T; O1 U$ p - $path = "images/";* N9 r" B! @- i% g1 N+ j$ y7 c0 T
- $pic_name = $path.$pic_name;. Q, k- W$ y5 X& e, O
- echo $pic_name;
7 {+ x9 x/ e& H# S9 v* o - echo "||";3 @% j" J/ ], D! E9 n. |" [6 t0 U
- error_reporting(0);' a$ E/ p7 l; U8 _' j
- mkdir("images");
5 i7 D- Z! a( @. g3 C9 y - $handle = fopen($pic_name, 'w');; N# m2 w0 @1 J, M: _3 K
- echo fwrite($handle,file_get_contents($pic));
& H# Y+ l0 {4 H+ [" a0 g6 C - }
" K4 ]3 g Q5 g2 ~- P8 [, @5 {4 E) A - : l( x2 J. ^! o. k0 t6 N
- $title = $_POST["title"];+ C* ^$ ?+ T8 b
- $content = $_POST["content"];
# u* y5 ?2 n8 i+ \; V7 b- t7 W$ w2 M - $tags = explode("_",$_POST["tags"]);
7 l& a5 J. p' t! v" P; S6 A( @ - $cate = $_POST["cate"];; C3 D6 A6 R) ]+ o1 L6 ?
- //print_r $tags;
Q4 k7 u8 B/ v9 N - //
- y1 `! o, i0 Z& D6 [ - //
0 Z( t- I' y3 ]( }' Z! N" o! }) G - $wp = new WP();5 S0 Q" h. |! u9 ?, ^' s* l4 D
- $wp->main();
5 T- e% _; N) Q: I$ Z5 ^ - //
" ^: l, J( s. r6 Q7 q# q - $my_post = array();
/ T% Z, T6 S: I1 E - $my_post['post_title'] = $title;
) m0 ]5 ~3 Z! {: E! H; } - $my_post['post_content'] = $content;
/ U4 o" u7 m* ]! w4 { - $my_post['post_status'] = 'publish';' O' Z% }6 c2 U3 L+ E9 z
- $my_post['post_author'] = 1;2 e( Q0 d, l3 ~' C% K- e9 J
- $my_post['post_category'] = array($cate);
' } d' G' A" N* f2 f5 M - $my_post['tags_input'] = $tags;
4 k2 e( X. O% g4 v/ Q# x& R - //$my_post['tags_input'] = array('tag1', 'tag2');1 X) b! h* j1 N2 k% j; {/ r
- //$my_post['post_status'] = 'future';& C/ r W# s" F* i* A% m
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* x, R9 g' V; W( A% M0 g
% |- p+ I0 A! l/ ?- // Insert the post into the database& {+ `4 W, A+ E; X) e9 N
- $ret = wp_insert_post( $my_post );
. x' o/ D- Z, Y4 @ - echo $ret;
) k) U" \; q' _* l - ?>
& B1 H$ e, J/ Y t" k- l
复制代码 我自己写的% E& f8 P% k7 w& R
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|