|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " A @4 o6 b5 e3 _4 b
/ v h) ? @; t9 o7 }9 B直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持4 I. N+ n$ u; P2 @
3 p8 m0 p; J7 {1 j' M% x我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
2 H' n/ b3 D' _. J+ L- g: R2 G! q; B1 B G
方便实用 简单 何乐而不用呢- - D( b! ^& P" m6 Q
- <?php
* d( x$ Q7 n) r# x8 Y, n' ~4 y - ( U o+ @ b: n5 m, y' }0 f4 |
- define( 'ABSPATH', dirname(__FILE__) . '/' );
! G4 p5 g# _' B: F! i* t - require_once( ABSPATH . 'wp-config.php' );
& u% Y9 |1 A" }! n, M; [$ i - require_once( ABSPATH . 'wp-settings.php' );9 H( c! O. Q7 i i5 S
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; q8 U) ?6 N5 S% ~: x# _+ Q - require_once( ABSPATH . 'wp-includes/functions.php' );1 [6 U; C. ^; G E) Q1 {* Q
- require_once( ABSPATH . 'wp-includes/plugin.php' );
7 ~. ^( W* O' H; A% `% x - $title = $_POST["title"];
1 i) z7 a+ t; r Y - $content = $_POST["content"];( A5 V. m/ Y! K$ B! \
- $tags = explode("_",$_POST["tags"]);
) g! c! l# H7 ^8 S( k) E - $cate = $_POST["cate"];
8 Y8 w% E0 w; V - //print_r $tags;; `4 J+ U& ]9 p
- //+ l' X3 Y* m8 d/ o) j
- //% z5 D5 S0 y. G& J
- $wp = new WP();
) L3 }' }- F; H2 _, u( c - $wp->main();
" D1 q8 X6 n$ O- R0 r( t: x - //
$ U4 A( Q+ x( U* h0 [2 I$ F - $my_post = array();
/ x: T2 e8 o+ B8 i/ c( P e - $my_post['post_title'] = $title;
! V/ V3 O0 x. f! H( D - $my_post['post_content'] = $content;
$ \; ^, U! A4 a# \; f- y - $my_post['post_status'] = 'publish';
$ e: |( v, B- P0 O. |' ~6 d# c - $my_post['post_author'] = 1;) C$ b2 _: K: q1 \( i
- $my_post['post_category'] = array($cate);
. s3 A" _* k1 N$ R - $my_post['tags_input'] = $tags;+ R. N5 T' b) }; o
- //$my_post['tags_input'] = array('tag1', 'tag2');& R7 O; _; N0 w' g4 Y9 F
- //$my_post['post_status'] = 'future';" ~' D. G+ C4 `: o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
& ]1 W d' f! ~/ h1 C. z. ^2 I" b
9 ?* B7 Q0 i. Z* A) l0 y- // Insert the post into the database
/ q' H$ x7 _3 d/ m* D - $ret = wp_insert_post( $my_post );
0 L3 `2 l6 U# k! B4 z! G - echo $ret;8 S' c$ F+ L' E# z V9 P9 q& Z$ s
- ?>, m* [" D( H0 c+ h
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
) _) t8 B3 N- B6 _' `- <?php8 }6 e3 o7 T* |9 \* S' }8 D( @
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ S6 j4 D* q f - require_once( ABSPATH . 'wp-config.php' );
1 n. g! f9 m3 l7 R$ T - require_once( ABSPATH . 'wp-settings.php' ); E/ Q2 t) O. C5 Q! H8 v7 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) A% X8 |- C1 V0 z9 B - require_once( ABSPATH . 'wp-includes/functions.php' );
/ [' T( ]+ `1 |1 Y2 n - require_once( ABSPATH . 'wp-includes/plugin.php' );
3 H" j1 a" p* A5 G. U8 K/ c - $pic_name = $_POST["pic_name"];
5 A. Q2 c+ s7 D! O# c" y( E; n - $pic = $_POST["pic"];
% @& P# s2 ?: ~ - if($pic != "" && $pic_name != "")7 V9 I; C+ H6 q7 L
- {9 k: Z# c( P4 C- v+ h
- $path = "images/";
4 F) T5 _# p. w. { - $pic_name = $path.$pic_name;5 x' Y$ T7 O# f# X; T4 N
- echo $pic_name;- N5 T! N% ~ N! T, s# e
- echo "||";
: D0 a- B& y3 K! }! @* j# V - error_reporting(0);8 d( i4 ]3 J1 `& x+ a5 L
- mkdir("images");
! E2 |; c/ Z6 J* X \% q( U% V - $handle = fopen($pic_name, 'w');
6 X# @ h4 j8 M7 V - echo fwrite($handle,file_get_contents($pic)); h1 C8 g' `# }# f( i& r* r, L7 c
- }$ r8 G, N% i+ {& ]) _
- 4 j9 [0 ?7 A$ I! B
- $title = $_POST["title"];
& r5 ?! Z9 I0 f# u4 C - $content = $_POST["content"];
9 ]# f% v3 M0 Q6 i' T3 X. o - $tags = explode("_",$_POST["tags"]);
$ q, z4 o! d0 e2 H4 U- Z - $cate = $_POST["cate"];" l; I' ^' Q+ E" k1 B, V: ] q# R& V
- //print_r $tags;
# x: w5 l1 y- d+ |7 b0 a - //3 G2 z/ W: Y: i/ P! i
- //% p+ E* {( n) V% z* e
- $wp = new WP();
1 F0 T9 _# q: p' _; k* C. B ~# n! T* H - $wp->main();8 g% o. I! F$ }& l u% @' T1 M& V
- //9 `- Y: } R% R! a4 R& H
- $my_post = array();% P, f2 b; d! i' ~$ ~8 G0 e* ^0 U
- $my_post['post_title'] = $title;: P( D0 f# x% H( G1 i& d, x7 A- U5 [
- $my_post['post_content'] = $content;# Z* X6 F3 |' t6 \) F) i
- $my_post['post_status'] = 'publish';; }/ e g0 v! j' T, j) p: A' y& ^
- $my_post['post_author'] = 1;
9 j- a, I" |' F - $my_post['post_category'] = array($cate);
# N( T" A: A9 V/ q, Y - $my_post['tags_input'] = $tags;
) G- k# z9 G1 Z - //$my_post['tags_input'] = array('tag1', 'tag2');
) C) I# H6 g& z2 U8 q0 U, p; ~* U; t7 n - //$my_post['post_status'] = 'future';) N1 ~4 `3 x1 E
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; d+ R$ G5 b" I/ O" H2 F+ z" J
6 I/ f9 I( c. q) f; Q6 M/ }- // Insert the post into the database
& A1 b/ k! Z# i* n( P. U! h - $ret = wp_insert_post( $my_post );
* z8 ~8 J' K2 ]! b) T4 f3 c2 |& V - echo $ret;
% { q" x8 Z4 f: v$ U4 E - ?>
, \. h/ y6 K7 e0 [; \0 q4 r6 j
复制代码 我自己写的
/ B+ e# {) ~/ o; w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|