|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
& S0 l6 a5 k2 @0 x! n9 u
4 |# u. }, l# G/ }直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
' Q7 D( |6 @, A# O
: P: t+ g5 r$ i& N我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: N# j$ ~* G7 _" z7 o4 m
- e; O( q3 Z4 o, {9 t& w! r1 @方便实用 简单 何乐而不用呢
# i. B9 l( T# ~ k" m! v; l- V2 W- <?php& V) t4 V& `. }2 E# F" h7 V
! z. T$ ?8 m* @- define( 'ABSPATH', dirname(__FILE__) . '/' );& a; \- O ~& c' S/ ]! ?) u' `
- require_once( ABSPATH . 'wp-config.php' );
6 m, ~8 Q% ?4 _4 o0 j - require_once( ABSPATH . 'wp-settings.php' );
$ E* p" L" N4 c& B; C# ^ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: n' v4 m7 \, F! z2 \7 a5 n - require_once( ABSPATH . 'wp-includes/functions.php' );
# K, h) p' @0 g/ P - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 G, d5 M4 V2 K( v5 o - $title = $_POST["title"];4 e" j6 v- f; @$ g ^
- $content = $_POST["content"];
& o( r9 y" L# I& b& G/ k - $tags = explode("_",$_POST["tags"]);0 P; E# Q5 U9 f& r% Z% u, |3 A+ X
- $cate = $_POST["cate"];) U8 p5 h; @$ ?5 x& B
- //print_r $tags;
E: F2 } A$ ^; Y2 c - //% S9 q' F: w- `
- //
( N N0 g0 \0 z& K( F" R - $wp = new WP();
" ]/ s+ j7 Q% ^9 U1 f, G - $wp->main();# @9 v6 r% p* X0 g0 f/ ?$ @
- //
# T# F! p( \* [" ^* t- F - $my_post = array();
U4 u: k# [* l' a - $my_post['post_title'] = $title;
7 V( h1 P' J3 o/ H6 F - $my_post['post_content'] = $content;! i# |; @$ S% S: _* z
- $my_post['post_status'] = 'publish';
W& i l% u6 i! u. T - $my_post['post_author'] = 1;1 [, P, v. l# E8 T: r
- $my_post['post_category'] = array($cate);' H9 _1 A, n4 d5 k
- $my_post['tags_input'] = $tags;) z4 z% a+ J2 e8 r9 X) x0 M
- //$my_post['tags_input'] = array('tag1', 'tag2');
- [3 u' J6 ?; w, i/ q6 q - //$my_post['post_status'] = 'future';) w" n( l4 N1 E7 j/ F
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
( i1 s; ~8 B2 M+ L7 U3 o - , W, x3 Q9 o; e
- // Insert the post into the database( ]/ }- b% I$ e
- $ret = wp_insert_post( $my_post );& p `5 x5 |, @8 h$ f" o
- echo $ret;
) f- p w) Z- T/ R( E" b - ?>' Z7 Y# C9 O( l% k% ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , I. I3 a% X$ @: G! S2 K. w
- <?php
. U( ~6 q/ X8 ]# D( J. d6 w# Z, W - define( 'ABSPATH', dirname(__FILE__) . '/' );! l a, W5 c; ^. M! M5 ]
- require_once( ABSPATH . 'wp-config.php' );' o2 C3 Y, b( F% I
- require_once( ABSPATH . 'wp-settings.php' );# u7 z/ Y# @4 [2 t; C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) t5 U1 ^( v% i5 e. m! g f - require_once( ABSPATH . 'wp-includes/functions.php' );( a1 [; D7 ]. `2 o. c5 Q
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 D/ x l( R$ k$ y ~6 A - $pic_name = $_POST["pic_name"];5 S7 x: G( X6 D; g* |
- $pic = $_POST["pic"];
6 l) Y: [$ f1 E8 }( W. ?; h. | - if($pic != "" && $pic_name != "")! X* ? `8 c7 k) x8 C
- {
1 m9 {, L6 B! l' X0 \, i - $path = "images/"; [' j/ n2 R5 k: C* q) ]6 H
- $pic_name = $path.$pic_name;7 H7 t& b( w& A P3 Q2 m
- echo $pic_name;2 T% p% b# S- Q" T4 v( t7 c- n6 q
- echo "||";
& P9 h( i' N) { w9 C - error_reporting(0);
2 S" Z# e% U& {" W: w- } - mkdir("images");
m5 ~" K: ^7 L& F/ G" S - $handle = fopen($pic_name, 'w');
6 }* T" {& R3 n6 J- b- u* t# D: X - echo fwrite($handle,file_get_contents($pic));, `6 d# X! z5 r2 l" |
- }
0 ?& a% w" l4 n0 Y% b7 o - % t$ G0 ^! s$ `+ N# i9 A
- $title = $_POST["title"];( ^* S2 L" {: v, S8 t
- $content = $_POST["content"];
5 D$ F, D. ^* e/ A2 W - $tags = explode("_",$_POST["tags"]);
1 U J" p* _# u, x# t. J2 ` - $cate = $_POST["cate"];
. y7 |4 Q/ u) J3 o1 s) @* K - //print_r $tags;
1 L" ~7 `9 A2 v) j! @1 m - //
/ A2 k. }! ?2 w' y8 i! Z3 c8 Y' X - //
) Z+ E) u; r6 `- P+ C. h( n# C - $wp = new WP();
: r7 [3 N- i# `/ T - $wp->main();
9 z: s* m9 r3 q, b6 w& ] - //
7 j$ L4 A+ A# T' I - $my_post = array();
. r1 R) c, {; F3 ?/ k: @ - $my_post['post_title'] = $title;
: t" y- \9 c6 x, l - $my_post['post_content'] = $content;0 C2 v* t$ u, h/ C9 e" u
- $my_post['post_status'] = 'publish';( }4 Z8 z5 f. u
- $my_post['post_author'] = 1;
+ ~+ H: O' x4 S7 @* Q4 N% B - $my_post['post_category'] = array($cate);% M1 o! Q* K0 p9 N1 j0 @
- $my_post['tags_input'] = $tags;0 O& J) r/ ]; Z8 }$ o* |
- //$my_post['tags_input'] = array('tag1', 'tag2');/ w1 @* {1 a( F: j0 t" A
- //$my_post['post_status'] = 'future';2 S! _5 d- W8 j: `
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' m8 G& Y' j ]" n% V4 y, i
# d, `$ z% \4 s* g: u* D1 ?& N- // Insert the post into the database
: b& d! s9 _& l6 ] - $ret = wp_insert_post( $my_post );
' u; b ~ K9 X& O+ o3 z- i4 j - echo $ret;, K' r" j; l* O8 y, L9 ^& L% r/ W; i$ {
- ?>
/ o$ R& z) g, e3 K/ f8 N
复制代码 我自己写的
! m- R6 s/ a4 m/ @8 G插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|