|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
) `1 ~9 D$ @! ? H; n+ a/ H
& z- h6 p1 U* \5 ?0 T" I直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 _& t2 ^5 e/ P" N- }
; N T6 L7 z2 ~3 O# j我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, O, u: w9 W5 J# q# m
9 L2 ^/ }; I9 M& ~% q方便实用 简单 何乐而不用呢- / z6 I9 Y, q3 p+ p
- <?php' {! l4 Y. G2 S9 z; l+ Q4 U
- ! _. ]+ e+ v' ?! c- C/ @/ m6 p
- define( 'ABSPATH', dirname(__FILE__) . '/' );* `9 F$ h$ S$ q5 U! c2 H& n
- require_once( ABSPATH . 'wp-config.php' );
- S8 i1 ^: W5 p - require_once( ABSPATH . 'wp-settings.php' );# `8 p4 J6 B+ x: g5 X7 W
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 [$ i+ k6 G. o& D1 X5 C" _ - require_once( ABSPATH . 'wp-includes/functions.php' );
* x1 Z0 @+ k8 x9 B( m+ } - require_once( ABSPATH . 'wp-includes/plugin.php' );
' A; k- l" q' p& b - $title = $_POST["title"];7 D7 i/ w5 k( `! ~& }) h I
- $content = $_POST["content"];
' r$ s5 [7 }- T# d H - $tags = explode("_",$_POST["tags"]);
# ~, W% ~! v( ~: y" u3 o2 W - $cate = $_POST["cate"];" k. m2 J. S' a$ V; R
- //print_r $tags;3 o T( a C, _7 ]
- //) l. L, @/ e/ |* h
- //( U+ p3 i T, v! S' q3 t
- $wp = new WP();! S7 T0 A" B; Y' \/ p7 [# j8 m
- $wp->main();/ M& j$ x, `, j2 A2 g. d8 j! F
- //4 p) d7 \8 n8 O- e+ A+ n
- $my_post = array();0 \7 ~4 y4 C; V5 X8 C
- $my_post['post_title'] = $title;
: O+ v) D' d* T0 J/ B5 f - $my_post['post_content'] = $content;; {( i' a, X7 T1 a
- $my_post['post_status'] = 'publish';
: U; H! G, R3 G! ~6 c+ C+ K% a - $my_post['post_author'] = 1;
2 {0 l+ k" }0 M - $my_post['post_category'] = array($cate);
3 {9 A4 E! o8 f) s9 } - $my_post['tags_input'] = $tags;
& _" K8 X" L/ P8 U6 [ - //$my_post['tags_input'] = array('tag1', 'tag2');
9 @7 f- j6 T# _7 q - //$my_post['post_status'] = 'future';+ x# Q1 J P: j% T `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ W$ J8 y" @2 @7 K& x9 K9 M* C
8 D& R2 g( b3 E X- // Insert the post into the database7 N: T3 u4 B( j0 Z& X( u1 J# G
- $ret = wp_insert_post( $my_post );
2 v: [; _% C" W5 _0 S - echo $ret;5 H7 _/ N' f" Z8 Z0 h! v
- ?>
$ O- K1 ?' \; F
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 G$ ~$ A0 U& B5 u. P h
- <?php
- p) a! r: b5 {2 c/ q2 q7 x3 y - define( 'ABSPATH', dirname(__FILE__) . '/' ); a% |/ ~6 T0 i+ d0 I
- require_once( ABSPATH . 'wp-config.php' );2 P. f7 C1 }7 S0 L! y2 {* f5 ^ m
- require_once( ABSPATH . 'wp-settings.php' );
8 S4 ^9 a/ v5 A9 l - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. W8 Q$ a9 |' V0 Y - require_once( ABSPATH . 'wp-includes/functions.php' );& q h- p% E2 m# H/ S# A% @- Q
- require_once( ABSPATH . 'wp-includes/plugin.php' );
* w; _6 Q2 y) @; b4 H" k' h - $pic_name = $_POST["pic_name"];
' G4 x5 y4 A9 n( q( A - $pic = $_POST["pic"];$ I% d( |* I+ q9 p/ |, I i3 i
- if($pic != "" && $pic_name != "")
6 |3 i, c& m; f, k2 u - {, f! @& s5 ~6 V! e1 P
- $path = "images/";
4 Y( h& b/ r+ K* J0 O - $pic_name = $path.$pic_name;; H* m; n( I- e8 F! ^) \
- echo $pic_name;3 Z1 B# V- A( H4 ^/ Z6 h! q" o
- echo "||";2 g, Y& O2 f( ^3 P% Q; I4 }7 W
- error_reporting(0);
' Z2 C( H- ~' Q6 ~0 \ - mkdir("images");" D- P5 D9 Z% m! n) G& O+ e
- $handle = fopen($pic_name, 'w');
1 n }* \* G9 n7 B7 l - echo fwrite($handle,file_get_contents($pic));1 z0 I. \+ M0 r g. k I
- }# V/ Z1 K8 Y7 A7 y3 ?$ q$ _ L0 ]
& h" O D+ }5 Y4 ~3 k. ?( e1 B6 i- $title = $_POST["title"];* W1 u8 m" {4 O+ j- F
- $content = $_POST["content"];
8 G* u+ M+ a& ~$ R - $tags = explode("_",$_POST["tags"]);; U0 O+ l' t8 r# `; B
- $cate = $_POST["cate"];2 p9 n1 e# p* V7 ~
- //print_r $tags;
5 z3 N: P9 K1 c! a" {! X8 x - //3 r3 f* q! p# ^$ F% J. I6 \, R
- //4 }5 ^% @8 C: |2 [6 q2 O x- j
- $wp = new WP();! N4 i1 ~5 Z( ^0 ]2 X
- $wp->main();
2 a( w1 w k( f' n! Z( J - //+ ?3 |% A3 @; }' T4 R2 o5 t
- $my_post = array();
" d: {: L @8 X/ ]9 K* O' m; u2 I/ @0 z - $my_post['post_title'] = $title;9 _/ I) p! e6 m4 H4 ?: v$ H
- $my_post['post_content'] = $content;0 o% ^$ g6 A5 {( Z2 M: C
- $my_post['post_status'] = 'publish';0 Q) u W- `) P' M+ h1 S; y
- $my_post['post_author'] = 1;
+ V s& I ?% g# | F- p - $my_post['post_category'] = array($cate);
: _* H4 a' i. o! c: f - $my_post['tags_input'] = $tags;% \9 b2 `, ]2 X9 [! c
- //$my_post['tags_input'] = array('tag1', 'tag2');% t# L/ ~. J9 l% G4 I1 H" F" |
- //$my_post['post_status'] = 'future';" t. S- C- F( d1 b+ h+ J8 I1 U7 z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 [# U8 M* _9 L" K) l2 ?% U# C7 Y
- ( A, n4 Q1 O) X, t1 h X& M
- // Insert the post into the database
/ ~3 ]% { e( J/ T - $ret = wp_insert_post( $my_post );* G, T5 W; ?; N1 E j, S& a
- echo $ret;3 l1 U3 L$ g5 |+ d
- ?>6 m4 r( D+ s n& G5 _
复制代码 我自己写的
7 _# h& B& o+ I- D, A( O2 b插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|