|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 E; J8 @9 s' ^) z3 P% Y2 T, K6 x) A3 Z$ |/ @, ^! B7 U7 y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
* R$ Y- C2 [ K9 U' Y9 I$ I" d9 t0 |% {# O7 q R9 d! E9 G* x
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' ^% \ `4 j2 a3 e5 B# l! Q6 V2 X: k: x2 u5 F) ^9 Y
方便实用 简单 何乐而不用呢
6 Y9 l/ `6 a% d/ g- <?php
4 [+ s: R9 l$ Q% O
0 {! o {; f# a) L" E2 S e$ n! I! U- define( 'ABSPATH', dirname(__FILE__) . '/' );( c3 n3 o3 V& R, F6 k9 Y* \6 u
- require_once( ABSPATH . 'wp-config.php' );& V V4 D, a* W" A& q
- require_once( ABSPATH . 'wp-settings.php' );
# G+ i: |6 h4 Z# Q9 Y; H - require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 P" X* |7 N$ |8 W& W$ J - require_once( ABSPATH . 'wp-includes/functions.php' );
4 R1 E2 [+ f. }4 o- u% w- A4 p: a - require_once( ABSPATH . 'wp-includes/plugin.php' );" X6 w3 X( D2 s
- $title = $_POST["title"];
( _& [3 S. w# ?/ D; j4 a/ j - $content = $_POST["content"];5 Y6 v Y$ n8 `/ x- K
- $tags = explode("_",$_POST["tags"]);- U1 E* P# n- J
- $cate = $_POST["cate"];
; O" ]5 W- |$ }! e: W) H; x1 P - //print_r $tags;
( f$ S4 H1 |. W6 ^3 B - //, N( v4 z' N' N
- //
' K: r+ v5 l8 C( n8 u% @ D - $wp = new WP();6 C' r! X8 A: N) t! Z# _; J
- $wp->main();
6 u# m9 N3 T9 _! ]" |' F r' B - //
" R; W! t# M# q' q7 s - $my_post = array();" \9 _: S( k+ x1 E' R) y
- $my_post['post_title'] = $title;/ C: i& L2 w* {; n) L; Q7 l7 g$ B
- $my_post['post_content'] = $content;* z) ?9 [$ {$ O: L/ O; O
- $my_post['post_status'] = 'publish';, c& E) v9 V% p7 `2 [( B. c$ `" R) Z
- $my_post['post_author'] = 1;6 f$ e+ R: ^1 Q4 K2 b J, f- |
- $my_post['post_category'] = array($cate);4 N; E# k `% F( B( O7 v' U' i
- $my_post['tags_input'] = $tags;. F# Q' K. e8 m5 O( l
- //$my_post['tags_input'] = array('tag1', 'tag2');* h e1 \$ _: t( [
- //$my_post['post_status'] = 'future';* `6 P8 @2 C% F! `( r/ u
- ////$my_post['post_date'] = '2010-07-04 16:20:03';) k) o" I7 _9 Q3 x
- 0 U1 z: c% D1 c- X- {( `
- // Insert the post into the database
+ [- M/ D5 [' `# Y9 n - $ret = wp_insert_post( $my_post );5 _* ?0 V9 m4 }7 j6 n! C+ _ K! h
- echo $ret;1 d0 S) s! E, \4 T+ X) F
- ?>: y, y6 P$ H% F# h/ j1 i$ {$ R/ N
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 9 t9 G6 L6 H8 T$ R5 r" Y! f6 z6 K8 p, t
- <?php, m7 z! [% ~ d" {0 d
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& U8 W( ^# a0 \; T3 z: ?: ~ - require_once( ABSPATH . 'wp-config.php' ); }* ^6 k# F( `4 W* Q: j) G3 l6 E
- require_once( ABSPATH . 'wp-settings.php' );% w9 m/ [ f6 G6 A/ z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );, x' d; j0 q* w+ {
- require_once( ABSPATH . 'wp-includes/functions.php' );
" D: w" B( ?, |* T. X: ^' K& X - require_once( ABSPATH . 'wp-includes/plugin.php' );
3 r9 D, L* K3 |0 e! [, I; I - $pic_name = $_POST["pic_name"];
/ ~0 g) P! `! z T5 q! ]3 r( @ - $pic = $_POST["pic"];
: Z8 W7 X2 [$ m2 ?3 @4 b2 p: ^ - if($pic != "" && $pic_name != "")
0 N/ R0 K- u+ |; }) s8 j+ I# x' V - {
+ @+ ]9 s* U/ b+ Y1 \7 m' P - $path = "images/";
( w( h9 f$ S* f, N' `$ }; K5 q - $pic_name = $path.$pic_name;; F9 @0 b$ j' n2 x7 {
- echo $pic_name;
/ e2 G2 i4 U& O - echo "||";
( F5 M1 O- q: `) C8 A8 d2 o( l5 y9 b - error_reporting(0);
* p+ h1 G, A! i5 V - mkdir("images");9 e, p4 c; p! E4 H
- $handle = fopen($pic_name, 'w');8 t7 p7 `( s3 x& Q
- echo fwrite($handle,file_get_contents($pic));9 R# z) z& A \8 X
- }
: Q. Q1 \" T4 P8 j$ o
: {& T& a, v' T5 b" Z- $title = $_POST["title"];. D3 X- L5 O) h* C, K1 J' {# t
- $content = $_POST["content"];) ]: E* ^8 k; q$ v1 r# ?; Y
- $tags = explode("_",$_POST["tags"]);
4 ?$ S8 m% g/ z* {: U6 g( R6 n - $cate = $_POST["cate"];
- b4 M. W2 [8 z - //print_r $tags;' A" @" C" p2 `% h' v) s! l3 g# x6 M1 {: O
- //
9 q! v5 C+ H. {* H( A - //7 c- b! L' I4 _$ p
- $wp = new WP();
% }' M5 J7 S) l - $wp->main();& \- Q7 j. G4 W7 v/ B" F5 Y% m
- //
+ R ]* X2 ^# \* ?3 N9 w - $my_post = array();
; R! b$ u& l7 B1 q4 Z7 I - $my_post['post_title'] = $title;
7 g. ?% ~) s9 m2 c1 A+ z/ Y( b - $my_post['post_content'] = $content;; s4 x" u) @* }5 q' S
- $my_post['post_status'] = 'publish';
| {) G9 A" m - $my_post['post_author'] = 1;2 ^! q9 |8 o# t' d# ^% ?% S$ I
- $my_post['post_category'] = array($cate);8 n! p4 L% b3 I# `; e6 B
- $my_post['tags_input'] = $tags;; u5 ^% V0 o6 g! H) ~' W! {" H
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ z3 m$ l8 }/ g* f" m - //$my_post['post_status'] = 'future';
7 \2 @6 q% H2 _# ` - ////$my_post['post_date'] = '2010-07-04 16:20:03';
' C4 m, Z1 `% b* e& {. S: l
9 ~9 K+ W- r' G- // Insert the post into the database. U0 b/ h/ |6 r
- $ret = wp_insert_post( $my_post );, V" [, L a+ U5 q7 {+ m
- echo $ret;
, }1 P' Q0 ]! Q - ?>& h# i3 e* Q, s2 I; C) ?
复制代码 我自己写的
& Q. k: m* @& m% s插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|