|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 0 P+ U2 D# A2 E
( z5 x% V% P1 q8 @
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 I& m; \1 [' Z: i) C; q1 x0 S0 C9 v" P/ ?' l
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# B1 s' x$ V& O) u2 _2 e
5 [' F' a- U7 l' {2 z
方便实用 简单 何乐而不用呢
$ K, L5 ?( I! T$ Y- <?php
9 O( C1 l/ h3 j F4 ^, L2 p- {
1 A# C3 K& b' A" e. O- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ N+ J. |% S) C* z, } - require_once( ABSPATH . 'wp-config.php' );
$ `3 c' _; y& u - require_once( ABSPATH . 'wp-settings.php' );9 i& }3 J0 K x: y& h* X7 f4 }3 c! _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
, O7 ]! J0 A# N. H1 }* r# V - require_once( ABSPATH . 'wp-includes/functions.php' );( p6 a/ H" U6 }. H' j+ Y
- require_once( ABSPATH . 'wp-includes/plugin.php' );1 U& e1 Y2 R. q
- $title = $_POST["title"];7 \$ [2 s T; P1 i5 {1 }0 Z
- $content = $_POST["content"];+ b% F3 n$ O6 I
- $tags = explode("_",$_POST["tags"]);$ G ?. b) P0 k2 C8 j; Z) Y
- $cate = $_POST["cate"];" Q2 J9 r7 w- b }8 ]
- //print_r $tags;
9 g' v+ i; n3 o% N! Q: [ - //+ Y% a3 |6 P$ R* S: g/ R
- //" ~1 t: f* u% N
- $wp = new WP();7 N8 y# N3 ?; }+ l
- $wp->main();; t+ m; n4 q+ k# _2 ]/ `6 X
- //3 F3 c3 z# {- A$ i& N" z- E) ~
- $my_post = array();9 i* \, l5 v% Z0 s
- $my_post['post_title'] = $title;
9 U! J) j8 [$ N - $my_post['post_content'] = $content;
( j* }; j, _' x- q( ^8 X+ A$ w - $my_post['post_status'] = 'publish';% h2 X2 N- [ B" X# c6 x3 r
- $my_post['post_author'] = 1;0 s* K ]& r1 w3 `' h* m
- $my_post['post_category'] = array($cate);, w3 T7 c' c' a$ M1 l. Q, u. @
- $my_post['tags_input'] = $tags;
4 [; ~' w; H; W$ I - //$my_post['tags_input'] = array('tag1', 'tag2');
4 O; T' V2 M2 t9 o, G6 \* z2 ` - //$my_post['post_status'] = 'future';4 _2 E: F) \' O& {
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! p/ k4 S0 v3 b4 H: z, j w0 ]& d! ?& G
( o* S+ ~: H D8 u& {- // Insert the post into the database
: o* `6 u. V/ Z$ o8 j5 U - $ret = wp_insert_post( $my_post );
! O2 w& ^* E& T, O/ }$ S - echo $ret;
, N8 h+ {4 @/ i, M9 S% E - ?>
7 _+ Q5 h- `( `! I6 X7 J# n
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 o% v# f3 r+ v: d3 O- <?php
; F1 n! p4 |' I/ `0 V - define( 'ABSPATH', dirname(__FILE__) . '/' );# t6 M5 t8 `% q2 l: V m
- require_once( ABSPATH . 'wp-config.php' );
7 M- M! k" w/ M( H* F/ x' T9 }) f7 E - require_once( ABSPATH . 'wp-settings.php' );
3 Y7 e+ U7 g0 A* w& S% m! g+ b* D+ y - require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 }, q. Z# A; Z* m2 h5 o - require_once( ABSPATH . 'wp-includes/functions.php' );
% B0 g" R. h8 r5 I6 | - require_once( ABSPATH . 'wp-includes/plugin.php' );7 h% W8 {" g- c* b! y
- $pic_name = $_POST["pic_name"];
9 Q2 U( t7 ?8 V O, i- d! o - $pic = $_POST["pic"];
2 Y6 `. B' K/ L* t0 ]6 P - if($pic != "" && $pic_name != "")5 h2 @' U) m C, @0 V) f+ s1 y- _
- {
! M# I! k5 U# T& M7 E2 ~1 i - $path = "images/";
8 h6 p# A' \2 w1 t - $pic_name = $path.$pic_name;
9 S8 v- G" p/ H8 R* ~# x - echo $pic_name;
' W1 R) f! x, r0 r1 |, z5 k - echo "||";; S' f6 z8 a. s( n
- error_reporting(0);! N# Q* s8 Z/ e3 n
- mkdir("images");
) ~3 a8 ~; }- ~ - $handle = fopen($pic_name, 'w');
" n3 ~- G3 `' u N! D! { - echo fwrite($handle,file_get_contents($pic));
! ]" @1 G3 ]! s, y( Z - }
: v8 F, p9 ^4 E/ ^6 |
6 ~9 B* A' f" \( b( a. O- $title = $_POST["title"];
6 z' X2 |6 j2 e( m3 c: n' u - $content = $_POST["content"];7 c. B. ?$ @1 y% p; E# E
- $tags = explode("_",$_POST["tags"]);1 O) `' J& h, p2 C/ S
- $cate = $_POST["cate"];" s/ F, `# O: L$ i
- //print_r $tags;
( D+ n! G; l2 K3 H" J - //9 P0 L3 k0 H' E
- //
0 Y0 i9 R& M& ]3 v% { - $wp = new WP();
/ x- ^* M9 G' z V b/ M - $wp->main();: e6 Q( {+ B. h4 m
- //* y M/ e1 y, O2 L J, |4 p
- $my_post = array();
3 u, t( G, u# I) j% o - $my_post['post_title'] = $title; d. s0 [& d& i) x" g0 B+ w& j
- $my_post['post_content'] = $content;
7 [; j/ R/ E0 W$ u" x - $my_post['post_status'] = 'publish';$ z* m1 T/ M3 Q3 N( p: H
- $my_post['post_author'] = 1;# ]# J+ P) V0 }) f- i. N' J
- $my_post['post_category'] = array($cate);
: _! Q+ ^/ z0 m4 A- W1 c: b - $my_post['tags_input'] = $tags;
% ^6 }) r' h9 b! C$ N - //$my_post['tags_input'] = array('tag1', 'tag2');
+ A6 i. q! w% g, \/ }# s% T! `# ? - //$my_post['post_status'] = 'future';: E" f8 e! Y' ~( ]* y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';5 T& H1 e O/ s8 P
- 2 K$ L" S/ f S) W u/ \
- // Insert the post into the database* _# V% d$ x, H* c8 m" d. r, v: _
- $ret = wp_insert_post( $my_post );$ J) F. t" x& A( e# |- ]
- echo $ret;
- ]1 a/ V" z) P4 b - ?>+ Y% d2 L* N a8 h) I1 ^
复制代码 我自己写的
. G" n; V$ g' o& V: L1 [插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|