|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. D% m4 {2 ~/ p# r4 Z/ n- G+ Z% p- M. B5 {0 @- {* U* v
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持6 g% m7 v1 T9 j
" u: q9 {2 k* K8 B% W
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
2 I3 ]! @/ j( Y5 Z
7 L" d" ]/ t2 m9 _5 T方便实用 简单 何乐而不用呢- 0 Q/ N% r. F1 W% J. D# n) Y
- <?php
4 Z9 t7 o) @, O$ S/ E! ]1 Z& c
7 L* g! ~7 |3 l: F t- define( 'ABSPATH', dirname(__FILE__) . '/' );8 u4 V- g" J/ t9 H
- require_once( ABSPATH . 'wp-config.php' );
' h8 w9 L" U6 {) z - require_once( ABSPATH . 'wp-settings.php' );
6 d; e5 x& n+ t2 q# y+ \% x - require_once( ABSPATH . 'wp-includes/class-wp.php' );
* }4 Y& k1 ~9 m" d3 z8 y" i# w5 ? - require_once( ABSPATH . 'wp-includes/functions.php' );- m6 ~2 C1 _0 {; ]+ x; L+ M
- require_once( ABSPATH . 'wp-includes/plugin.php' );+ [+ Y9 s* L( b: {* H s9 H
- $title = $_POST["title"];
* e, u# T# a& S, c - $content = $_POST["content"];
2 ~0 z+ l+ O; H2 K - $tags = explode("_",$_POST["tags"]);
. ]2 C- e/ X$ e+ ~9 N( S - $cate = $_POST["cate"];3 B' Q* [" i* F# t
- //print_r $tags;
) o% R6 s$ |" _1 g1 @ - //
' K. _9 `6 _% D4 Y1 n( c - //
. n3 L) K* F9 O0 \& S! G - $wp = new WP();, O/ h' ~8 p) H. O! L
- $wp->main();
: C, S3 T; T7 P - //# r% h6 M! y: @9 d! R( \- l8 f) f
- $my_post = array();
3 F- X4 D9 B- r, L - $my_post['post_title'] = $title;
# U/ R; G6 g, m# c+ }& m; Z - $my_post['post_content'] = $content;+ O4 C ]+ r& [. G( J% {1 |
- $my_post['post_status'] = 'publish';: v$ @3 v3 L5 n
- $my_post['post_author'] = 1;
, R, G" U2 z ~4 B5 Y6 U# {7 O - $my_post['post_category'] = array($cate);/ S# K3 _9 j- P' i+ r2 \: ~6 X0 P
- $my_post['tags_input'] = $tags;
- X2 v9 j9 F+ X1 q" d! H - //$my_post['tags_input'] = array('tag1', 'tag2');
8 m; b6 y6 I# M* A8 t3 s4 W - //$my_post['post_status'] = 'future';8 S. v9 ?5 ^- I- Q4 e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ P# d6 H: @# a, z% u/ m6 q8 U2 h
" l% t2 K6 z( }2 N- // Insert the post into the database3 H8 d1 T5 v5 h
- $ret = wp_insert_post( $my_post );
' e+ o; {$ I% X, A: E# g - echo $ret;
- B& G# ?# o$ R8 j. S( I2 E - ?>
5 Q% S4 q* ~" w; G1 \' ]# K9 M
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- " e f- d; _3 L" O# [( B% R$ _" H
- <?php- }1 t' J9 h8 V- j9 D- b% A
- define( 'ABSPATH', dirname(__FILE__) . '/' );) X9 p7 g1 y3 y8 g
- require_once( ABSPATH . 'wp-config.php' );' I1 O4 A3 {7 r* ^, i# ^
- require_once( ABSPATH . 'wp-settings.php' );
" G* `+ ~9 L/ i; G2 d! x+ E0 ^ - require_once( ABSPATH . 'wp-includes/class-wp.php' );- z) V/ O: d& u- F% \. |3 c
- require_once( ABSPATH . 'wp-includes/functions.php' );, p% G5 _: d# c+ F' a
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ T+ ^! Z; O& O% R7 h6 W
- $pic_name = $_POST["pic_name"];
4 f6 r, S* u1 F) T5 Z - $pic = $_POST["pic"];
1 x3 X* M7 I$ x# V - if($pic != "" && $pic_name != "")% z& L) B/ a Q0 B8 b" G1 y+ ^/ F
- {: G7 q; O, v _8 D- ?! w2 ]- T* v, h
- $path = "images/";
+ L( \( z, l1 X- C: m3 Q - $pic_name = $path.$pic_name;' f8 c, P' _& {8 l- D; h# k
- echo $pic_name;
- T9 f" v$ S- ~* i0 x0 k - echo "||";; d" q4 X: I) Z3 u- X4 h9 ^" `$ I
- error_reporting(0);
: J) K+ I- A Y$ G( [0 I - mkdir("images");9 H' T! F8 C0 P/ Y8 z. u
- $handle = fopen($pic_name, 'w');1 \: L# j* \, i: h3 ]7 [
- echo fwrite($handle,file_get_contents($pic));
! F# q, M) p0 r4 a! o0 |) i - }
& ~ I. V% H' B" b6 p' i% l. ?
; F: P( M. W; ?0 \# t/ C- $title = $_POST["title"];
! b2 T: }/ N' k0 p6 g - $content = $_POST["content"];; F" T7 |' [, c& V; [
- $tags = explode("_",$_POST["tags"]);
( r; l8 G& s" _5 v% i7 M( ] - $cate = $_POST["cate"];4 y2 c/ l" Y v* d+ d
- //print_r $tags;, H. w4 p3 j: J. L3 Q+ n! y* i
- //5 m' ^/ P5 c+ g( S2 n
- //
9 l4 P( E7 t l - $wp = new WP();
& s2 X# v$ _. k- n, g1 ^3 X - $wp->main();" i0 ^' c6 v( @0 D; B! |
- //
4 K4 O: a+ m- n( T# C - $my_post = array();
8 v* t( }) ~9 L - $my_post['post_title'] = $title;' \/ \- s% B+ {+ L
- $my_post['post_content'] = $content;3 X2 Q+ l. z/ j9 V$ o
- $my_post['post_status'] = 'publish';: S3 ?) G7 I$ F) u/ C
- $my_post['post_author'] = 1;- M7 l( u9 F/ r% X2 G" h
- $my_post['post_category'] = array($cate);) j( Z* z' b% O& Q$ |, C7 z1 q, I
- $my_post['tags_input'] = $tags;$ |7 j$ K* [% g8 I" {
- //$my_post['tags_input'] = array('tag1', 'tag2');$ y" o* N, R5 d* C0 Y) [
- //$my_post['post_status'] = 'future';3 q2 P8 d, `& g$ P
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
( u( T/ u4 u% w; G, B& l - # \! V) x8 P- |, F9 b6 \
- // Insert the post into the database1 I) z3 O5 w3 o- m, j
- $ret = wp_insert_post( $my_post );! N$ W* O# e# ?+ w4 s, C' X
- echo $ret;
+ m6 _8 `5 y e; F1 D - ?>0 n3 K" O) X3 G! B2 ]
复制代码 我自己写的
% ~2 L2 b9 [8 s. \3 ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|