|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
! p ~' v- P0 w) B- P' c/ O# _5 r- T9 N4 y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持3 ?% A) W' {. o
) m' u+ r7 U/ T8 }& o% a
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 h2 z1 ^* y5 Q+ N- v7 R& O
( ^5 c3 j3 i6 u( }8 ?8 t
方便实用 简单 何乐而不用呢
) q% \; Z$ f) u- <?php
" f; o k8 X0 C" l" m
M) @. C Q2 d" T1 ~) M- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ W6 B6 t l; }) i4 \ - require_once( ABSPATH . 'wp-config.php' );
, y( T! A! N# Q! s$ M" V - require_once( ABSPATH . 'wp-settings.php' );0 }# r- @: [/ `# w& J# P- i
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 y+ y# }. H( r ]$ P* w
- require_once( ABSPATH . 'wp-includes/functions.php' );, D; l4 b0 U- W7 J4 f: H
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" C3 H, P8 K* h3 k$ {# @+ ? - $title = $_POST["title"];
: t( j: V' G0 y1 _$ _2 | - $content = $_POST["content"]; {+ _- ^: x7 p, O2 k4 h* M
- $tags = explode("_",$_POST["tags"]);4 a0 Y2 {3 x/ u" H Y
- $cate = $_POST["cate"];
/ Z8 H% a: r: a; g - //print_r $tags;) X# U4 \, Z: _2 V% Q+ {
- //1 o, f! X5 I+ [6 b5 G( _( [' } t
- //
- h2 J/ ]9 b! {. |* \3 n1 v - $wp = new WP();
7 K7 m5 R4 G3 c4 {* T0 A - $wp->main();
) z9 D; h$ z3 T. b6 d; r6 T, `4 T - //) O* E; B/ l5 U
- $my_post = array();
; w& l: M- s& M3 f/ l4 K - $my_post['post_title'] = $title;
1 @) R1 V& @3 f I# M - $my_post['post_content'] = $content;) ?% U. k6 F1 T) Q
- $my_post['post_status'] = 'publish';
) G- u8 }% Y. ^ - $my_post['post_author'] = 1;
1 q. S& R% t/ M; b: Z - $my_post['post_category'] = array($cate);
# ^6 H8 y, H) M& f6 i - $my_post['tags_input'] = $tags;
2 r/ L; ?! X+ ?' G! K/ ` - //$my_post['tags_input'] = array('tag1', 'tag2');
; c0 {3 n% f* K/ E - //$my_post['post_status'] = 'future';1 _: G5 u J( |
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; X( c7 f) r# n7 ^% l. s) y- t
- 1 N! l5 S8 p! |$ g5 ~" u% y
- // Insert the post into the database
% h1 t5 \/ L4 ^! R9 w - $ret = wp_insert_post( $my_post );% x Q0 B# C& v/ Y8 T
- echo $ret;
6 ~5 Q( t3 M- {( x# \. p! X - ?>
' t+ i( k# `# a3 P8 z. p1 z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 ~, L5 K( V1 q. _# B$ `: _
- <?php3 f3 M1 c) B! L7 l. x* ?& Q C
- define( 'ABSPATH', dirname(__FILE__) . '/' );7 t. _0 ^. s; X( O) Q3 S! {
- require_once( ABSPATH . 'wp-config.php' );
6 l" I# f! y2 V" V - require_once( ABSPATH . 'wp-settings.php' );. ^- Y M5 b6 L! T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );+ Z6 ^. ?6 \# u( @- Q* H! y
- require_once( ABSPATH . 'wp-includes/functions.php' );$ d6 s! X# ]: _6 { C
- require_once( ABSPATH . 'wp-includes/plugin.php' );! h3 ? H' L3 i6 k6 T
- $pic_name = $_POST["pic_name"];; z& z/ {+ i1 _
- $pic = $_POST["pic"];
6 s4 O$ c1 ]9 T; n; j9 k' Z - if($pic != "" && $pic_name != ""), F* T! @3 ], I$ a/ j/ `
- {: U; E0 T5 I( m' N
- $path = "images/";
+ W' T% E6 V, {+ F1 j/ {) u - $pic_name = $path.$pic_name;
( r7 e* s6 v# {% f& `. p [; |9 f - echo $pic_name;# O" ^: W+ K4 e! x, s
- echo "||";
& x. y3 J$ x' ?2 n8 B3 b7 g* L - error_reporting(0);/ R! }5 f1 C. s( N6 W, d4 p- q7 D
- mkdir("images");1 i {5 d3 p2 E! g; Z
- $handle = fopen($pic_name, 'w');
! o6 `& R3 i4 ~" w$ t4 [& w - echo fwrite($handle,file_get_contents($pic));
$ H* N3 k: ^: Z- A - }' a, ]( a3 s! X9 O+ D* U
0 M8 w J- M) m |7 z7 Z' s/ M- $title = $_POST["title"];" \! a: o3 t: m! X
- $content = $_POST["content"];
9 L6 T, g0 H: l5 J5 d - $tags = explode("_",$_POST["tags"]);
( d" Z7 @5 ^$ \1 _ - $cate = $_POST["cate"];% Y' ~, A& T# B
- //print_r $tags;
. _( I$ t) h" l9 |9 B - //
- I* v/ Y9 ]* B9 h3 E1 c, T - //
; B% R! I) T; O( O - $wp = new WP();9 Q) T9 N, R& C( m
- $wp->main();. K4 b* g& x. R x, Q, o8 A4 n% E
- //3 ~2 s4 r; G. L& D, F4 h
- $my_post = array();
) r& O" H+ s# Q - $my_post['post_title'] = $title;/ S- C3 k0 u* Z! X7 E% M& o
- $my_post['post_content'] = $content;
& K) a0 r* l, ]. N! k- ] - $my_post['post_status'] = 'publish';$ h$ Q# E; b6 I+ d5 A
- $my_post['post_author'] = 1;
% Q7 Y% {- T& |2 i" u - $my_post['post_category'] = array($cate);
! t; E' Q, p, ]# O- @ - $my_post['tags_input'] = $tags;$ @# x w2 i) z' w* N% _
- //$my_post['tags_input'] = array('tag1', 'tag2');: b) x" w( H! f6 j- ?2 Y( M
- //$my_post['post_status'] = 'future';
8 ]. ]' M9 g! M; } - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, L, d$ z% M. S( g, O! K
w+ r. E2 w l# u* ?- // Insert the post into the database8 v6 e) R$ x- C
- $ret = wp_insert_post( $my_post );
9 X; p v3 `9 v& \) M - echo $ret;
& G1 h% v0 j4 Z4 \ C - ?>2 k3 @2 t; @7 f
复制代码 我自己写的
" `/ T8 M5 k+ S9 N {+ G0 w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|