|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 , M5 |1 H% ~7 i* q
" _1 `1 ?/ s7 s% L f( k直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
# t% S% V+ T1 H: M9 h# Q
6 |, [* b, _* R5 m8 O9 e1 I" z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
. g* _$ q$ h7 ^& n2 p: I( A
& x; \, b, ]( B4 q G4 M+ Y方便实用 简单 何乐而不用呢
5 j5 G; {$ {. O" n* `- <?php7 F5 C8 O, g; m& @
) E8 L4 `1 C8 R, v- define( 'ABSPATH', dirname(__FILE__) . '/' );5 p( ]6 \: w0 T8 K+ I0 M4 }. c
- require_once( ABSPATH . 'wp-config.php' );: y: p' X9 Y7 c0 _
- require_once( ABSPATH . 'wp-settings.php' );
z3 T6 U. y$ I% B- J+ n9 J - require_once( ABSPATH . 'wp-includes/class-wp.php' );3 ?8 k6 O7 j. G, r, N8 r
- require_once( ABSPATH . 'wp-includes/functions.php' );- k1 M9 k& n! f3 p
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 t8 O* V$ Q3 X( c - $title = $_POST["title"];
( T3 x( z2 n% [- C8 H; _ - $content = $_POST["content"];+ p# I) i( _' c4 M- b
- $tags = explode("_",$_POST["tags"]);
" N- K6 W% `5 C9 D- f, e* L - $cate = $_POST["cate"];
# u& I+ s2 S* Y+ f; }) @ - //print_r $tags;
k; p3 |$ a! G9 f% D - // d" [2 q2 x8 H# ?8 a6 }0 o
- //* P3 J. K. B; ]
- $wp = new WP();
0 u; W3 z. E/ [ ^9 X* G - $wp->main();
( s4 r7 l0 `* c( p+ c - //
: q. |0 {$ ?" P% h E8 H - $my_post = array();0 `5 U% y& {+ U" {% x0 e
- $my_post['post_title'] = $title;
. I4 n; z# i% R - $my_post['post_content'] = $content;* y5 \5 M0 P& n) {+ f; l8 Y2 J T
- $my_post['post_status'] = 'publish';
2 }5 x F# V1 c) y! ]% s - $my_post['post_author'] = 1;6 M. b; n+ Y% h1 {8 |' {
- $my_post['post_category'] = array($cate);1 X5 d6 @$ ?: n6 B3 n5 L
- $my_post['tags_input'] = $tags;
/ _! {9 _9 X& X - //$my_post['tags_input'] = array('tag1', 'tag2');3 X T& s% b! t
- //$my_post['post_status'] = 'future';! j( m2 k; M: @1 ?0 N5 ]
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! W0 p. F0 w! O! ?
/ v( m; O# P- x* a- // Insert the post into the database
* d+ W+ T0 X* g% T - $ret = wp_insert_post( $my_post );; F" i0 Q) q- a7 G. X, A( v* J) Y7 T
- echo $ret;- L9 J: r" V0 n) W( L/ _( j& \' B0 M
- ?>
1 y5 T3 q. E1 w- `2 J* y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! p8 ]7 P' C7 T# R& A) ?- <?php
3 B/ r9 d6 j, k, H" f - define( 'ABSPATH', dirname(__FILE__) . '/' );
# o$ g% G8 {; T# G* d9 \0 ^ - require_once( ABSPATH . 'wp-config.php' ); o! C& f1 }: `7 h$ ]5 K
- require_once( ABSPATH . 'wp-settings.php' );( Z! m' L2 d# R/ \& C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 z3 a6 X9 r2 M8 i* Z+ W8 J
- require_once( ABSPATH . 'wp-includes/functions.php' );
! f# V! v' K$ u - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 J- a" _; e8 X) {3 h - $pic_name = $_POST["pic_name"];7 T ]7 e: H7 k2 n- o. P
- $pic = $_POST["pic"];4 O, l8 m7 d- d1 B
- if($pic != "" && $pic_name != "")
/ p% J9 y9 Q; g) f7 w; G" g7 G+ G2 U - {
( L( i& y! l& M d2 Y: ?: j - $path = "images/";2 o" V* x1 Z/ N4 P1 Z5 n# z/ \* I
- $pic_name = $path.$pic_name;" i. Z* R( E7 G2 z" L
- echo $pic_name;
6 T. x8 ^/ [, }2 ^2 D - echo "||";: L6 F4 t, Z4 e" O* ~# P
- error_reporting(0);
9 R# @( ~) z' b8 h3 J! C# O - mkdir("images");; ~# m' R7 L. q( g& x
- $handle = fopen($pic_name, 'w');
0 ~5 ]- I4 w% V3 s - echo fwrite($handle,file_get_contents($pic));9 z1 t4 I- q& j0 T# P( x% r0 L
- }, A; u. V' D4 t% |$ u
- : y9 M+ ]+ R) m8 t" ]' D* X0 r" l" d/ T$ G
- $title = $_POST["title"];
# J# D+ O- p3 G, g - $content = $_POST["content"];1 Y) Q& T5 D( ^+ o: h
- $tags = explode("_",$_POST["tags"]);8 V K0 _6 r4 m
- $cate = $_POST["cate"];
* y% o/ ]. W0 Z - //print_r $tags;# P: w! N( N! L/ v
- // ` B8 H% h; J9 W+ I
- //
/ {2 L& z3 u9 I( @- O - $wp = new WP();
" l7 `. O0 `0 L7 R8 u - $wp->main();
7 U- Q9 E' u5 [ - //
g6 ?! y. G! I1 W - $my_post = array();
2 S. \* T4 d# O$ c$ J - $my_post['post_title'] = $title;
* B& h! L" X0 g - $my_post['post_content'] = $content;5 ]9 |6 L" G0 C- u6 W7 S7 l
- $my_post['post_status'] = 'publish';* r3 X) r: E! b5 b$ ~' ^+ p
- $my_post['post_author'] = 1;6 u' `* `( E; ~" `
- $my_post['post_category'] = array($cate);# Q% q L) }; r2 E7 a7 t
- $my_post['tags_input'] = $tags;
) S) N& B; P/ k7 y4 |$ J - //$my_post['tags_input'] = array('tag1', 'tag2');1 j, |. @) L1 E
- //$my_post['post_status'] = 'future';
. ]* B# f6 u2 _! O9 g - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( T& K+ A( V+ n1 [2 D' I! { - 1 I0 X5 I9 h1 f" v- O& [
- // Insert the post into the database
$ ?- y! u& \# p - $ret = wp_insert_post( $my_post );/ x0 u) L E6 M) o3 `) \
- echo $ret;, X* f& u2 ^% x+ o; o
- ?>5 [2 z5 ^" h7 ^, V3 |9 v8 z$ r: Y
复制代码 我自己写的* Z2 O" j! T3 v" F
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|