|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 0 A. m3 `' v( o; i" ^8 _ r, @& s
z" ]; d' Z% W) i4 X' l5 S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 C$ [1 d5 V: J m/ H; r1 s
6 X/ U, o, C5 b) H+ j我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了* n0 T% v( p% p9 k! q( g
% l! A6 {. U9 n0 f. b
方便实用 简单 何乐而不用呢- ' B, g4 Z6 l) _$ e9 M
- <?php& R* n' F+ n6 z6 v* U- f+ ^/ ~2 ]7 X$ S
& D! l# A0 I+ I- define( 'ABSPATH', dirname(__FILE__) . '/' );# |9 k2 d- _) K3 m3 E# h
- require_once( ABSPATH . 'wp-config.php' );4 ]; S3 A7 L( h4 X" o' T
- require_once( ABSPATH . 'wp-settings.php' );# o3 W# F& q2 d8 \+ b8 d
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
& K, n0 J( O9 W1 P: \ - require_once( ABSPATH . 'wp-includes/functions.php' );
0 l# O- Y L m) a2 J% { - require_once( ABSPATH . 'wp-includes/plugin.php' );/ a$ R, k5 i# ^" C7 M' U( G9 ?
- $title = $_POST["title"];
& }7 ]/ F% P2 H - $content = $_POST["content"];4 O' E. U& t5 K
- $tags = explode("_",$_POST["tags"]);5 e {8 @! T* f
- $cate = $_POST["cate"];
- |9 m4 K1 |* f; [: I7 X1 m( s2 `" r - //print_r $tags;; o- T* M: @, G* Q
- //
+ k; l- W/ d$ o3 L2 a/ p2 x - //) _) n0 E. m1 }4 _; F
- $wp = new WP();
' t& R- f8 w1 {: y4 n5 L6 [ - $wp->main();
% z: u( o* J9 g& M4 Y8 q - // O/ @2 J' b- G9 W/ m) n" B
- $my_post = array(); B, [* S7 C) _& n/ j
- $my_post['post_title'] = $title;
6 Y1 E5 s$ z# u. N1 j; L3 H - $my_post['post_content'] = $content;$ _# d0 F4 V& V$ I3 H
- $my_post['post_status'] = 'publish';( g( N& w- `4 m7 ~8 r* q2 x( X& ?
- $my_post['post_author'] = 1;
3 @/ \7 c+ W& F) Y - $my_post['post_category'] = array($cate);
( x# v# R2 }4 l - $my_post['tags_input'] = $tags;# ]( b' c- }4 c! ^ g! l. O p
- //$my_post['tags_input'] = array('tag1', 'tag2');
9 Z- M- N* u0 v# h - //$my_post['post_status'] = 'future';7 i2 \8 \& |& h4 y+ G( K# z! U) \
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 X9 N9 y! @6 z) ]1 T* _2 x
- 4 c: ^; S7 r8 }
- // Insert the post into the database2 Q3 I5 C" Q( a) j ]
- $ret = wp_insert_post( $my_post );
9 H3 P$ N9 o# A& s" D0 n4 w - echo $ret;
/ `! W0 [0 N' {6 j g. J; m - ?>$ y& q- ^& L' I6 A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
& k# c: _: G0 w/ R- <?php
! ?6 E" ^' c9 X; e* w$ l/ ?3 N - define( 'ABSPATH', dirname(__FILE__) . '/' );
2 ~" h% O6 |" m, f5 K7 p - require_once( ABSPATH . 'wp-config.php' );+ ^6 e3 o" G0 }
- require_once( ABSPATH . 'wp-settings.php' );/ n2 `8 [: ^5 Q5 I' ^7 G9 q- g8 c
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! O) U% K, l) t+ P/ d" a0 q - require_once( ABSPATH . 'wp-includes/functions.php' );- F! B( e+ d! V5 z
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" T. r/ Y. s( U" R - $pic_name = $_POST["pic_name"];
2 c4 O" \: E2 |) ?, S - $pic = $_POST["pic"];, A& t5 f1 d2 U, t8 n# N) ^
- if($pic != "" && $pic_name != "")& N) v$ B6 X3 F6 f6 Y4 v) p
- {
n$ o9 I3 U3 M" X: ~ t, P6 } - $path = "images/";
. K( D! J. L: X) _! u) m8 b5 `- E - $pic_name = $path.$pic_name;
7 ?5 A8 \# H1 O$ h* a. Y, d - echo $pic_name;0 S4 r0 l% h# X: M( J
- echo "||";& X( Q5 w5 v8 q* |
- error_reporting(0);
% x& [2 u" k- m/ O1 o! a$ v - mkdir("images");
; A5 W2 y; m7 k& _ - $handle = fopen($pic_name, 'w');
! x/ k/ M# q3 O& |( H - echo fwrite($handle,file_get_contents($pic));; H* T+ @9 F K ^# ^6 x
- }2 l& l9 ?8 L$ ? x1 ]6 |' f2 d# {) s
4 O" A/ m$ ?" I% {5 L6 ]- $title = $_POST["title"];$ F3 i: s+ s# a/ ?
- $content = $_POST["content"];
3 @9 w" i% R' g% Y6 P7 X - $tags = explode("_",$_POST["tags"]);
: h$ {" j( Q0 I2 c5 u! [ - $cate = $_POST["cate"];
% i0 g6 c$ R$ b - //print_r $tags;
8 C1 ~/ e0 ~8 R# L5 Q1 D- c. h - //9 h$ R# g U: p
- //
1 B" O1 e Z& d2 m+ P* m. f - $wp = new WP();! [$ f+ g* ]! G1 g
- $wp->main();
% t6 f! _: V8 j# h - //
6 n- n, \; C' X - $my_post = array();
" [5 ?2 Z7 Z t, q - $my_post['post_title'] = $title;
+ f8 ]8 V( L" n; z$ ]- }3 Y - $my_post['post_content'] = $content;; K3 m4 |0 l+ y" Y3 b n
- $my_post['post_status'] = 'publish';+ Q9 V8 s2 v+ D4 b
- $my_post['post_author'] = 1;5 P9 g& b2 t) T- r
- $my_post['post_category'] = array($cate);- e) ^6 A* a. \
- $my_post['tags_input'] = $tags;
6 Y3 R& F' z0 G& H! E - //$my_post['tags_input'] = array('tag1', 'tag2');# a- L6 l% B8 L) ^# W+ g
- //$my_post['post_status'] = 'future';
1 `9 k; \3 H' X" m5 m: q' }' ] - ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 }) n2 P" c' F
' i( N& u1 c* _; a9 _- // Insert the post into the database) H" k$ H: @& f* a7 h
- $ret = wp_insert_post( $my_post );
, B. f7 ~& y9 Z- c& W r - echo $ret;
) B$ l& L5 r0 e, k, O - ?>
5 _& K3 m) t. K( c4 u0 H
复制代码 我自己写的
- c0 w! ~- F$ ?: Z$ q0 M插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|