|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! V: G/ g( L+ t" d
7 M$ r* G0 ?$ p* B0 R直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持9 U2 p) K8 @0 z G- R( K, s
, |; M1 R( ~; _6 m; D" T* a. R3 W$ `我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 C' k/ \' A' \: [& l: q
- \1 J6 ]) h* \方便实用 简单 何乐而不用呢
8 ?) U4 y+ t, p" z- <?php7 G* {' A8 X5 Y# K+ U
8 G( U, R9 T8 g m5 o2 N0 z+ l9 K- define( 'ABSPATH', dirname(__FILE__) . '/' ); s$ E8 a0 E1 k) w% V; W- m
- require_once( ABSPATH . 'wp-config.php' );7 ~5 o/ p, r1 {. d t6 |+ m
- require_once( ABSPATH . 'wp-settings.php' ); ~' E* W2 V8 S1 y/ \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ N- _' J4 }4 k' I/ _$ \% {8 p - require_once( ABSPATH . 'wp-includes/functions.php' );% D7 Z6 {4 h8 V& h! ?
- require_once( ABSPATH . 'wp-includes/plugin.php' );
' t! V: E0 z/ P: p - $title = $_POST["title"];
5 B9 F* c+ Q2 N4 _ - $content = $_POST["content"];
5 E: a& `. u. }* @1 `) P1 k - $tags = explode("_",$_POST["tags"]);
" e% h6 i6 r3 j& @5 A' N - $cate = $_POST["cate"];3 ]# t$ Q! k, Y7 q7 X5 [' d! ?
- //print_r $tags;
) M* Q% Q6 X _1 |+ S) T - //
& e; F& F0 R- M+ u3 ~+ ~+ w# D1 u. Z - //: H# J) _+ j3 N. y6 g) S# Z4 U
- $wp = new WP();) \9 Z( Q D+ b" t* T
- $wp->main();7 N: @+ L" R! U
- //- A/ z1 q/ z+ W8 C
- $my_post = array();4 m& n( g; J0 A5 p( N2 `; N
- $my_post['post_title'] = $title;
* q' L- T9 w+ _6 [; L - $my_post['post_content'] = $content;
' ]2 m: D; ?7 g6 ~) q - $my_post['post_status'] = 'publish';
" o) a* _* O q5 P - $my_post['post_author'] = 1;
7 v; @8 O$ ^7 n2 } - $my_post['post_category'] = array($cate);
. b, F& X3 d/ N5 p3 X - $my_post['tags_input'] = $tags;
! c1 }, Z6 ?% \) O: ?. M1 K - //$my_post['tags_input'] = array('tag1', 'tag2');/ C8 Z* U) D l! T0 T6 y4 v
- //$my_post['post_status'] = 'future';
) L; b3 a) H. |2 U0 A - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ z& v& x/ n; }
, j$ ~! O; n3 g! H2 r- z0 ~1 J- // Insert the post into the database. E5 Q% D* x5 ?# f, O
- $ret = wp_insert_post( $my_post );
/ W9 Y* |9 f' d( g2 w. @ - echo $ret;
6 s6 G# ]! n# q2 g- I* l% ` - ?>
% @2 t% g1 p- n( k9 W
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 j4 I" V" s( M+ V! Z3 `: b5 t- v: P
- <?php
8 q7 m6 d+ L6 Y - define( 'ABSPATH', dirname(__FILE__) . '/' );3 @' W5 l6 h6 c3 s. v3 @
- require_once( ABSPATH . 'wp-config.php' );
: y5 ~$ ^$ F8 p9 w4 A: Y W - require_once( ABSPATH . 'wp-settings.php' );3 R. P9 e8 O! [) t8 _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );; j2 k b+ t% ?
- require_once( ABSPATH . 'wp-includes/functions.php' ); t9 D2 g; p+ Z& C
- require_once( ABSPATH . 'wp-includes/plugin.php' );
. T9 ?! ^% D2 i" F. T - $pic_name = $_POST["pic_name"];4 Q7 q& h; K; {+ M
- $pic = $_POST["pic"];
) Z0 ]: s6 w6 Z% P2 G! ?+ ? - if($pic != "" && $pic_name != ""): r3 A7 E9 k. p& r Y. T8 a% g
- {6 b% W: ~7 M& W
- $path = "images/";' j; a8 J& H' c7 F
- $pic_name = $path.$pic_name;1 q9 h/ W( j8 w8 v( o4 k5 n
- echo $pic_name;! u. w4 s* b- g! o0 s
- echo "||";0 o! z6 n$ m0 M% w, m. u$ `9 y
- error_reporting(0);6 _) k* c2 @0 D% Z9 ?
- mkdir("images");
; U% Z' L1 x: ]! K8 L4 h, P9 j4 V - $handle = fopen($pic_name, 'w');3 u% p2 k. q! O+ K$ G' \
- echo fwrite($handle,file_get_contents($pic));
9 o* [% Q6 T# T8 _5 |$ Y9 q - }" D" [1 c$ ^' A! t F$ M" Q% s
- 8 U4 v3 m6 E$ D; n* E! n
- $title = $_POST["title"];
2 ]# P8 I; E: \0 I, L3 Z! X - $content = $_POST["content"];) l. Q' P4 z6 [
- $tags = explode("_",$_POST["tags"]);& J* H7 Q# ]9 @; [# d* @: |
- $cate = $_POST["cate"];! a5 N) l+ b B1 V) f) g* ?) r
- //print_r $tags;$ j+ U0 }) \; S+ ^0 t) d8 u' ^- E
- //
5 E ]- g4 O8 }. b. a- e - //
* \ l6 r! E; a% a# U0 c - $wp = new WP(); a, `2 E1 ]2 w' R5 j7 {+ {
- $wp->main();
2 J. B) r5 U( Y9 r - //" Q# @2 ?. K* b6 V1 K8 o
- $my_post = array();
2 p0 a) D( t5 q: d - $my_post['post_title'] = $title;2 N1 Y X8 M- g* Q3 }
- $my_post['post_content'] = $content;
! ? g2 |& p$ ~7 `3 j) R r- @6 I2 _ - $my_post['post_status'] = 'publish';/ e4 E3 T B3 z
- $my_post['post_author'] = 1;1 Y+ i' S8 a K; s+ [, A5 d' {
- $my_post['post_category'] = array($cate);* U3 _/ b B& Z' Q1 L6 z9 P& W
- $my_post['tags_input'] = $tags;
7 y2 Q7 L) L" T ^3 \+ C - //$my_post['tags_input'] = array('tag1', 'tag2');4 @/ U% ]# H! _/ u1 W1 ]% K- ]
- //$my_post['post_status'] = 'future';; K9 w1 y$ `% \+ C: B6 o" b% t, B
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
. [0 U8 y+ e l0 ]8 S - & ?) V* K4 b8 S: N! ?! w
- // Insert the post into the database/ N4 K/ K) K* h) w4 o/ w
- $ret = wp_insert_post( $my_post ); \" p+ C8 t: T8 U- u7 k. t7 v
- echo $ret;
g( y2 K( M+ i - ?>
/ A" J8 U0 [7 Z* `
复制代码 我自己写的+ d" ~/ u. q1 T' o0 b7 G! f' D
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|