|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
9 B5 ?+ w9 l; ?9 w
' d0 A5 a( q" G; D# q l2 _" p2 f直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持% Z; `' T" X3 r8 U; A0 a+ M
m1 M' Q! x! c, ~! s" q) i
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了" s( d4 X5 f( \7 }& b
2 D6 W' c# \4 u( T+ Z* D方便实用 简单 何乐而不用呢
! W9 U4 V: |7 b) @. ]8 r- <?php9 v2 A' w. C4 @2 S
, X& r4 }8 M9 Z* u9 O- define( 'ABSPATH', dirname(__FILE__) . '/' );, @$ A6 \! h4 o
- require_once( ABSPATH . 'wp-config.php' );- c/ b* Q- l+ g% }! j
- require_once( ABSPATH . 'wp-settings.php' );$ t. X1 r. O( V
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 q I# Y$ q$ i* j. \ - require_once( ABSPATH . 'wp-includes/functions.php' );
% M% D: x# H6 Q - require_once( ABSPATH . 'wp-includes/plugin.php' );7 P- T6 p! t! a( k/ O. d
- $title = $_POST["title"];
+ C7 s C# r, D+ U! D - $content = $_POST["content"];; ~( ~5 p+ M, k$ S9 d' t2 K
- $tags = explode("_",$_POST["tags"]);
- P) M, h7 O. \ - $cate = $_POST["cate"];
) l+ `/ ~8 H% t. ?: b& `$ O6 K6 b' \ - //print_r $tags;
' `( i$ G/ c' k) ?. F - //. Q M% X* X2 ]4 X& x ?% j' f/ z
- //
# F0 {- |9 l" m# W& d5 s - $wp = new WP();4 o8 l$ e! f/ \! ?
- $wp->main();
0 ], f# o1 @$ w. F2 d6 j - //' Q9 ~3 X: Q5 F" o
- $my_post = array();
' n6 u, A; u6 C - $my_post['post_title'] = $title;
' z2 l% m9 r- J7 S$ Z3 z$ s9 B - $my_post['post_content'] = $content;( D1 C* f0 R; d- h+ M5 o' Y
- $my_post['post_status'] = 'publish';# f2 N' x% i1 L) i! w( d0 J8 T
- $my_post['post_author'] = 1;3 \5 \; ~+ i1 L
- $my_post['post_category'] = array($cate);1 n- C% l4 e" s: O1 z" D
- $my_post['tags_input'] = $tags;$ J0 T" ~, j: g
- //$my_post['tags_input'] = array('tag1', 'tag2');+ R) P% c" F) u \% s
- //$my_post['post_status'] = 'future';
( x* g$ Y% l* j. {+ C - ////$my_post['post_date'] = '2010-07-04 16:20:03';( o8 |. o/ z0 E" t8 R
3 j' w) ^( ]5 I/ H* U3 N c- // Insert the post into the database
1 q5 M. W3 E/ b' R - $ret = wp_insert_post( $my_post );
+ C! q/ N( F4 r- K - echo $ret;/ P+ {5 E$ R% }* v! F7 K
- ?>( C* E2 ^$ ] d1 ^$ k8 C
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 b3 b: u3 q. U" D- <?php
, _9 U. n& F. u - define( 'ABSPATH', dirname(__FILE__) . '/' );
! |2 h3 ]5 N- U7 d& A - require_once( ABSPATH . 'wp-config.php' );7 R! E O& Y* }# d* z: q
- require_once( ABSPATH . 'wp-settings.php' );! L$ Z0 \. R- c7 ^1 J- L8 i7 Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
% V4 k. S( S/ o7 n7 B - require_once( ABSPATH . 'wp-includes/functions.php' );
# s% p4 V# O0 `( c - require_once( ABSPATH . 'wp-includes/plugin.php' );' M0 c* A K9 l( V
- $pic_name = $_POST["pic_name"];
9 ]5 k5 q% _0 Y6 `; t# \9 o- l" T4 i - $pic = $_POST["pic"];
6 y7 }; j6 G2 @- W/ Q - if($pic != "" && $pic_name != "")
5 o2 y% l% H8 C' I* J u' B5 x - {
" F5 P4 R/ N0 j' c, m+ m - $path = "images/";
9 U& R4 ] y( i! N: _2 d - $pic_name = $path.$pic_name;# o: _/ M' p0 p3 `5 G" T: g
- echo $pic_name;2 n. K! V1 r; y6 G
- echo "||";' ?9 h& E" M8 d# |& W. F) \
- error_reporting(0);
3 N- t' ^3 W2 a0 n: f - mkdir("images");! f3 W# L" L' m) e* i! C2 w5 C
- $handle = fopen($pic_name, 'w');/ W5 n0 h% n% \5 [; N% N, h
- echo fwrite($handle,file_get_contents($pic));% O# N& k2 w* ~9 w
- }2 r( u0 z5 O, m [: ^
$ [. K# A R9 k" l; A# s- $title = $_POST["title"];* z6 e3 ^8 T$ q7 P6 s
- $content = $_POST["content"];" U- g9 A1 i. Y
- $tags = explode("_",$_POST["tags"]);
- p- H! L( b0 S, @/ g - $cate = $_POST["cate"];
: A! k0 q* w2 H: W4 ~+ `1 c2 H - //print_r $tags;+ M3 L6 Q& Y3 B; m! @
- //! p. [8 }. L8 ^, }
- //
! y! Y" b8 X0 Q: p w8 \ q" f - $wp = new WP();+ `: K- M7 K+ \* a
- $wp->main();+ y+ G6 P# g$ n ~3 g
- //
2 O/ h' q0 U+ }( z& S. Q - $my_post = array();
8 d+ i0 c# I4 a5 P4 }' m" f - $my_post['post_title'] = $title;6 R# }7 P3 Q1 p
- $my_post['post_content'] = $content;' u1 z7 U8 Y" O% y$ _
- $my_post['post_status'] = 'publish';) I* k% {) Z) k0 N
- $my_post['post_author'] = 1;
' z( ?+ ]/ H6 F0 E) T# \ - $my_post['post_category'] = array($cate);
! |0 ^8 J( A ^ - $my_post['tags_input'] = $tags;; z% z0 f) H1 z
- //$my_post['tags_input'] = array('tag1', 'tag2');& D; C; `" i0 {. u% V
- //$my_post['post_status'] = 'future';
, G$ Z, _. [' N& v0 B9 k - ////$my_post['post_date'] = '2010-07-04 16:20:03';* ]8 G3 ^) H c; z
& w8 U0 M) ?* w3 E7 W. Q, m4 R- // Insert the post into the database! T9 w- z u8 q2 `& u3 `
- $ret = wp_insert_post( $my_post );
" P8 J5 O! `$ p - echo $ret;0 H( i: c. l2 G \# c1 p
- ?>* a& {% N- y s A; ?' }
复制代码 我自己写的& b% @! T8 o! g R% I" _
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|