|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
|2 x: E& f6 }" S3 m# K d+ e; A' Y, l; @- r
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持0 ]+ e. B j, Q
, K$ M" Z. f# ^4 q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' k9 w5 `& n( o9 \- Y* [
- e. k. A# `2 \4 ]1 \, l4 z D方便实用 简单 何乐而不用呢- 6 R* a) s9 m+ S2 p2 x
- <?php: h! ]/ x5 C* j M1 x) e8 z- ~
9 ]0 D5 `; c# U3 s' s/ g' I- define( 'ABSPATH', dirname(__FILE__) . '/' );) v- u4 I* `9 _, L
- require_once( ABSPATH . 'wp-config.php' );! G9 W" ^3 S }6 S0 B0 F
- require_once( ABSPATH . 'wp-settings.php' );4 F* I0 R. n$ K" D
- require_once( ABSPATH . 'wp-includes/class-wp.php' );5 ~2 O; s7 o& m% t
- require_once( ABSPATH . 'wp-includes/functions.php' );
: |3 T( t& x. i0 q9 E; b - require_once( ABSPATH . 'wp-includes/plugin.php' );
3 x2 ~# p4 D" ` - $title = $_POST["title"];) b# ~) ~ x' t6 d( y# K9 |# `
- $content = $_POST["content"];& i1 h/ C) s7 T6 S( F$ V3 Y
- $tags = explode("_",$_POST["tags"]);. r; @3 t2 t' k+ r& r
- $cate = $_POST["cate"];$ W& s& l8 P2 V. d7 g
- //print_r $tags;4 P. I4 u! V) p. @0 G- t" z: k" u* b
- //+ q0 \- S: x) o8 n7 y
- //
' }# C* p5 |6 _; [ T; a - $wp = new WP();! i/ ?" L: W( ?3 R- Z
- $wp->main();
: z* z) V, w5 l v$ b, ~9 G( Q- h. H - //
, V, |0 I" K; t, i" U4 | - $my_post = array();
! Q# _4 K/ K! c2 O5 j9 x9 r1 Z1 Z+ I# i - $my_post['post_title'] = $title;
7 w5 z" K4 A$ W! U0 I% P - $my_post['post_content'] = $content;
$ e/ \$ }# E Z - $my_post['post_status'] = 'publish';6 Q: d4 ~ G. }6 `6 |. i8 ~0 {
- $my_post['post_author'] = 1;6 R& H2 A( F" i6 Y+ x) m
- $my_post['post_category'] = array($cate);
- L# K- e. A" b U - $my_post['tags_input'] = $tags;% o/ M! X9 N8 @9 a
- //$my_post['tags_input'] = array('tag1', 'tag2');
% C! `& R9 H. b4 a- y: r( S; g - //$my_post['post_status'] = 'future';& o C. o ]' \% E% _3 V( \1 u# s+ _
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 w4 f: d) M8 R
+ b4 Y8 |2 V) X- N( K! e9 T- // Insert the post into the database
# j) X5 U( X! [. l! [* ] - $ret = wp_insert_post( $my_post );
9 R! }' U9 N1 x' X2 s' p - echo $ret;
) G: p* P% d' T" H2 y3 k" L: v2 e! \ - ?>) f- b7 H. j. u S; Q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ! J( j" S+ o; j1 h
- <?php; ~4 J9 m t5 C5 f
- define( 'ABSPATH', dirname(__FILE__) . '/' );
% f# Z/ R8 w) W+ }# T `; b - require_once( ABSPATH . 'wp-config.php' );- f( j2 P' o: A# J& H& [5 o
- require_once( ABSPATH . 'wp-settings.php' );
( h9 m) z1 G' a" c( | - require_once( ABSPATH . 'wp-includes/class-wp.php' );/ u$ o% E0 X6 L" f
- require_once( ABSPATH . 'wp-includes/functions.php' );
D/ T9 l8 n0 s c7 C& n; t8 W - require_once( ABSPATH . 'wp-includes/plugin.php' );
( _9 r- |8 }+ ~) e ^+ l - $pic_name = $_POST["pic_name"];* t4 [6 e/ v) l9 n8 F0 b
- $pic = $_POST["pic"];- H+ N9 B( g! f& Y. A" Y% C
- if($pic != "" && $pic_name != "")
8 S/ t) `- H9 W, Z% K0 i3 G4 k3 Q' M - {
- X: L' F6 Z# s/ A" V# q - $path = "images/";
8 o5 q& `/ H6 {, x3 S8 ?5 o - $pic_name = $path.$pic_name;
6 d: X X1 b! _: x* g0 U - echo $pic_name;% u8 h+ b0 ?. R; A0 `/ L6 m
- echo "||";
- S! c1 L% V# \, f6 N - error_reporting(0);, ~. {. M8 D- `: e8 r
- mkdir("images");
9 @% T6 s$ p1 k. l - $handle = fopen($pic_name, 'w');1 o K/ M* R' [% h% R% o C6 ~
- echo fwrite($handle,file_get_contents($pic));
4 u0 _( `" J0 E7 Z7 d4 k; I& h* I- o - }! H# @) I+ O$ A% h, B r, g4 v8 M* k
h1 q. N, [! Y/ v$ ~( O7 P7 C- $title = $_POST["title"];7 T/ |2 J' k9 ]; \4 H. _
- $content = $_POST["content"];
5 c1 Z: S l; D( H - $tags = explode("_",$_POST["tags"]);* C* D0 s4 S7 T( j& e
- $cate = $_POST["cate"];9 m, Z* f, V, ` i6 N
- //print_r $tags;, Z6 W2 t. M. A+ d" H7 |
- //
6 D0 R3 K% v/ o - //0 a3 o. K" l* h( @* @2 |) r
- $wp = new WP();
4 E* b9 l3 }# M4 m - $wp->main();
: u2 a% W! d, `) b# [ - //" y( {( Y9 n2 G
- $my_post = array();
, [( E0 J: ^! m& x, M2 Z: u' n0 h- v - $my_post['post_title'] = $title;
. ^% R Q7 \# r3 Q# w - $my_post['post_content'] = $content;6 q( u. j5 S. C# y3 E
- $my_post['post_status'] = 'publish';
/ w7 B0 `" g# f - $my_post['post_author'] = 1;% T8 ^2 \0 Q6 g. T7 j
- $my_post['post_category'] = array($cate);
, Z6 R+ s! ]# o4 U; P7 W5 T' _ - $my_post['tags_input'] = $tags;, [5 `! A, a9 B8 K
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 [* o2 Q! E H6 o: i+ L/ K: q - //$my_post['post_status'] = 'future';
9 K; {$ X N$ G! J1 Y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, Y0 Z2 }) S4 U' X! K
5 N( _( E# C- e: U4 C- // Insert the post into the database
4 D* z( f; H+ a. i c m - $ret = wp_insert_post( $my_post );) I; N# a8 C# V+ N2 X$ ^! I* V
- echo $ret;
% {$ q2 U8 f* A( q# ] n I. k - ?>
7 U+ D P h1 v8 x" k4 D
复制代码 我自己写的" O: w* O6 _6 F. U7 L1 \; E" U" U! @
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|