|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' A2 @2 v3 k" O; U* ~3 }8 V. Y1 E7 X) G y3 p+ }. P/ N$ A
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, U6 L% l E$ J! R
( x) f- q, D" G: y; P) W我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
$ d: m3 z5 ^8 p
2 c5 C0 ]/ e% X+ g, b- m方便实用 简单 何乐而不用呢- - \1 }3 x- j6 e6 Q, `$ g/ ]$ Q$ _* Q
- <?php4 j8 {0 c3 ]/ C/ m9 S, Z
8 i" } D c1 W2 u3 \& i U4 }* Z- define( 'ABSPATH', dirname(__FILE__) . '/' );+ c; t- s! B5 A% B5 A) Q
- require_once( ABSPATH . 'wp-config.php' );
: C) Z/ l( M$ E; O4 f& T/ | - require_once( ABSPATH . 'wp-settings.php' );
5 ~0 l n" ]6 `9 m. O( z/ e; ` - require_once( ABSPATH . 'wp-includes/class-wp.php' );8 ]" b8 n1 z/ T* k9 [* g
- require_once( ABSPATH . 'wp-includes/functions.php' );
5 T$ v9 R) T8 d6 | - require_once( ABSPATH . 'wp-includes/plugin.php' );
- \+ V) S) F" C- K. P - $title = $_POST["title"];. w; C5 |2 ^8 m) U% D! o, g2 d
- $content = $_POST["content"];2 R# k% J& j* Z. Q; `+ W6 R2 b' \) ~* k
- $tags = explode("_",$_POST["tags"]);
2 {7 s- c) P- f# {/ a& f. j- B3 b - $cate = $_POST["cate"];( V, H& \8 @2 B7 Z8 _. U
- //print_r $tags;( f* w+ s, m2 L; ~; X5 ^: }
- //4 D9 O- G1 _/ V; A
- //
3 [/ b+ O! e/ {6 Z - $wp = new WP();
! L; R2 v! m4 X' K+ h- l/ a) ] - $wp->main();" j j: [7 L# o) F2 y4 z% P
- //
3 k) x* x. F2 G - $my_post = array();6 O( O2 @' V r1 S6 F
- $my_post['post_title'] = $title;! r5 A1 O0 R- Y7 j; X
- $my_post['post_content'] = $content;* Y$ P7 o* V6 F$ P
- $my_post['post_status'] = 'publish';% p1 V, a2 `4 Y+ [% p
- $my_post['post_author'] = 1;
+ K3 B0 u* @0 v8 s+ E( I. Z1 d, N - $my_post['post_category'] = array($cate);
0 s; G6 O s' i/ d - $my_post['tags_input'] = $tags;
$ Q2 r: `8 Z, b/ R& M8 V: ]8 w - //$my_post['tags_input'] = array('tag1', 'tag2');
4 r d9 K& a9 d - //$my_post['post_status'] = 'future';
# S! g Y$ D: U1 W9 S% y5 \ - ////$my_post['post_date'] = '2010-07-04 16:20:03';* `( @$ ?5 Z1 r
) n; h+ J5 h. N" t- // Insert the post into the database( Z8 [4 s) G4 [
- $ret = wp_insert_post( $my_post );4 J+ V- _' a5 Y0 o
- echo $ret;! @3 S+ u! q) A& h
- ?>! e: r3 I4 x8 s5 W% g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 9 v* C8 H6 B* L3 u
- <?php0 _# S \1 G9 M" B. [9 |9 ?
- define( 'ABSPATH', dirname(__FILE__) . '/' );% X8 C2 \7 D8 h" l/ S
- require_once( ABSPATH . 'wp-config.php' );) S; @' C# k3 \/ `2 x1 q0 @7 h$ R; G
- require_once( ABSPATH . 'wp-settings.php' );
. A6 g2 y: v0 |. Z$ J P Z0 D! [ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
! o8 L, t, _0 v2 w1 h - require_once( ABSPATH . 'wp-includes/functions.php' );! P5 }$ C! M% `- t4 \
- require_once( ABSPATH . 'wp-includes/plugin.php' );' z. W/ j. ]( j/ ~/ h& r
- $pic_name = $_POST["pic_name"];
& Z# b. e- X4 }5 b H c* _) u F H' w - $pic = $_POST["pic"];
% V9 b7 `5 Z; E" g6 n4 K! | - if($pic != "" && $pic_name != "")
. ~* E& y- Z( I/ g0 M: T# B# C - {
+ i6 q' x2 P3 U0 O) {2 A - $path = "images/";
9 s4 r3 n4 }0 D6 B - $pic_name = $path.$pic_name;
$ ]1 C: H5 e: z* T - echo $pic_name;
% Z$ m1 X, Y1 p4 C R - echo "||";
/ s: c3 A d: y& _8 D) t - error_reporting(0);
# K+ I# a. n- l8 a u) s - mkdir("images");. {; [' t) N- \4 D) z
- $handle = fopen($pic_name, 'w');
! E# u; ?& p- O - echo fwrite($handle,file_get_contents($pic));4 ?% @ \: y. ~$ c L2 c
- }/ h( a6 O) d# e! P2 B9 u* p
$ |5 s: s4 |1 o7 x- $title = $_POST["title"];6 W, c0 w5 r' M" q) V' M
- $content = $_POST["content"];7 l& N# k% j$ w/ E9 N
- $tags = explode("_",$_POST["tags"]);, I% ]7 h; A5 ^$ c+ q
- $cate = $_POST["cate"];
2 l2 |! k- A5 O5 G- d7 o% Y - //print_r $tags;
' k, K( u! H# _' O3 H6 M - //) u1 J: P+ r6 ?8 K- X6 p
- //1 c5 f; O- k8 `. q, S' R
- $wp = new WP();
6 h4 j' W) _; D - $wp->main();
* [% s# Q9 j) S8 G0 O+ n# e - /// t+ s* v+ h1 ], |* R
- $my_post = array();3 L4 V9 M* o6 b& K8 q
- $my_post['post_title'] = $title;
$ z% S6 k3 n' C - $my_post['post_content'] = $content;/ m& ^- ?: l0 q
- $my_post['post_status'] = 'publish';
U4 [5 v* ^( f7 V2 S* I1 F4 s - $my_post['post_author'] = 1;
2 ^+ C5 k# d$ Y: d& A - $my_post['post_category'] = array($cate);2 K( y l; V! A9 j- j( q$ d
- $my_post['tags_input'] = $tags;' Q) B- N3 l6 h4 h3 `
- //$my_post['tags_input'] = array('tag1', 'tag2');+ e' D0 e# d3 y; K3 V, c, [- N
- //$my_post['post_status'] = 'future';9 A+ Q \* q: I
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, ?4 L% c3 }* V+ L0 O2 ^+ [% G' ]) g; e - # A5 K: N( E: Y. ?, c
- // Insert the post into the database5 n3 o/ y+ h+ f
- $ret = wp_insert_post( $my_post );
+ n+ p3 B. y& A3 U! m) t - echo $ret;
. N, s4 l9 {& x% V - ?>0 ]5 X" E% ?1 [0 ~5 K
复制代码 我自己写的
2 n- r$ O" Y( h- ?0 ?插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|