|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 - O2 ^6 _1 K r4 i* c( R- d
( q4 ]( x3 A4 c直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持! f/ `! u: p) V
- q; |4 M, I; ~: d
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
- ^* S3 w7 \% @; M/ P0 R# e: ~# `3 D" w9 }% W
方便实用 简单 何乐而不用呢- . S: ]2 g8 y; w& `
- <?php) T# G' r+ C5 ^% h! V
& M& p, C. p; S1 E7 @$ n) h- define( 'ABSPATH', dirname(__FILE__) . '/' );. M1 s* [5 N# t ?3 {2 O& `& \5 p2 ^
- require_once( ABSPATH . 'wp-config.php' );8 q+ o- w+ N- C( ^3 o+ {3 x
- require_once( ABSPATH . 'wp-settings.php' );
! s, I# b. q( S, f E( ? \ - require_once( ABSPATH . 'wp-includes/class-wp.php' );- G% _$ E& d/ w1 Y8 M0 N! R
- require_once( ABSPATH . 'wp-includes/functions.php' );, x3 K" C6 H( Q: I, A9 E0 Q! L
- require_once( ABSPATH . 'wp-includes/plugin.php' );% X, l2 ^$ {/ F* G! P9 J
- $title = $_POST["title"];
$ K/ x' a6 U, b: D6 ~/ M c - $content = $_POST["content"];7 Q; o" e4 g5 f+ y
- $tags = explode("_",$_POST["tags"]);7 A" N: s) c8 B1 Q6 q, \
- $cate = $_POST["cate"];
- O" x. X; j, d2 P7 v) \4 n" A - //print_r $tags;
' H$ H- C( K+ d - //
" @, Q' H- ^0 U% ?" F- H. F2 { - //6 X4 v- d* R$ x0 m& Z% a8 [
- $wp = new WP();. P" R, L/ c+ K3 `/ I
- $wp->main();
3 E9 i+ c% x% m+ \ - //' b, l' E6 `0 D& i
- $my_post = array();
: n2 P5 g# R% k- O9 Q8 R - $my_post['post_title'] = $title;
! k# d ^9 o& W - $my_post['post_content'] = $content;
7 D5 `; w c' n. n: b - $my_post['post_status'] = 'publish';
, j! \" [* e0 X6 T; H5 x- T - $my_post['post_author'] = 1;
/ {- [$ c; ^ j- C1 P. g* g - $my_post['post_category'] = array($cate);. \6 \( `+ G4 k7 i& e
- $my_post['tags_input'] = $tags;, i0 c. ]* A e8 Z1 O
- //$my_post['tags_input'] = array('tag1', 'tag2');
, H. r& c" v J9 w% L e - //$my_post['post_status'] = 'future';, J6 m7 }$ y3 N P5 o( X( h- D, p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';6 P3 p' x c6 f
, z5 ?$ {- e9 h* g6 O9 }1 a- // Insert the post into the database l! |7 S& A; D' l' l
- $ret = wp_insert_post( $my_post );
/ j2 _1 C4 n! O - echo $ret;
+ C2 e( ]" _( f/ q+ g% R - ?>
& R" R3 o+ O5 s' u
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 ]; x; ~ T j; p, V- <?php: s' @+ P& ]) ]! w- e0 y% h! o
- define( 'ABSPATH', dirname(__FILE__) . '/' );
, g7 T; S! f+ v: H - require_once( ABSPATH . 'wp-config.php' );
/ b f8 `1 x7 ~6 J. R { - require_once( ABSPATH . 'wp-settings.php' );
! {- d- b# L9 q8 X: X2 D) M' p - require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 N$ W0 P9 `$ e2 Z* B- `& Q- l+ Y/ y - require_once( ABSPATH . 'wp-includes/functions.php' );; I9 s( r8 c. X+ k
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ E( o0 b! v4 G
- $pic_name = $_POST["pic_name"];
$ L5 Z1 V/ g3 Z& U& J6 S7 L - $pic = $_POST["pic"];
2 j+ }/ z6 S0 w4 Y7 j3 p - if($pic != "" && $pic_name != "")
& b7 z8 ]9 B3 H0 B0 b$ _# ] - {- G% a2 A2 s( C8 Q
- $path = "images/";
; H9 j' G( p% K" Y$ e - $pic_name = $path.$pic_name;
* ~% d+ q2 G& y - echo $pic_name;/ s Q% [: C! I5 u# v
- echo "||";
2 |/ s4 d! T! m2 ~2 P - error_reporting(0);
0 e% n3 M2 }9 L0 W; q5 { - mkdir("images");
0 k; [: }" G+ j% R5 g - $handle = fopen($pic_name, 'w');) l: G4 `1 C$ g: a
- echo fwrite($handle,file_get_contents($pic));
0 T* U% x$ {& v, [1 n* ^$ W' O - }
. u% n3 o! d+ _# n `3 E
( L6 o4 x6 n& {* S# ]8 B- ?9 K1 L- $title = $_POST["title"];6 e2 Y v5 G' x& E2 o( Z" E
- $content = $_POST["content"];$ H1 `5 [# ~* X* h- |9 V1 I
- $tags = explode("_",$_POST["tags"]);
" {( E1 a% _ h& d* D3 E - $cate = $_POST["cate"];9 B4 A* Y5 d5 t' U
- //print_r $tags;
& @6 |/ u+ v' j3 X" b - //8 I+ O! A: I) A# S3 v. c- v
- //
" z9 u% ^8 T4 P, [) |: a# F - $wp = new WP();
N1 V8 r2 l8 t8 B |2 u1 I - $wp->main();, l2 g+ a$ w, v, `
- //( }0 {) U: @" `8 J8 A/ t& K
- $my_post = array();& [2 f: c% I. b) |- k: l7 P
- $my_post['post_title'] = $title;, n( j; K9 |) H. C' V/ Y
- $my_post['post_content'] = $content;( n, R v- A, d6 l: f
- $my_post['post_status'] = 'publish';
; s, K" B7 s; M7 p - $my_post['post_author'] = 1; L( n. L+ x! O
- $my_post['post_category'] = array($cate);# D9 v% r( {0 r/ X
- $my_post['tags_input'] = $tags;$ N; ]" G# i! B+ g9 }
- //$my_post['tags_input'] = array('tag1', 'tag2');% n% J! Z5 t0 ~' E: J9 v
- //$my_post['post_status'] = 'future';0 ?4 A. V V- P1 \& C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ m$ K' f6 \2 k
% V3 |* S3 E/ A2 M% q4 t7 @- // Insert the post into the database& T1 |& S; M6 p2 _" t
- $ret = wp_insert_post( $my_post );' W" [6 o0 |7 t; R8 u
- echo $ret; \# W* } e& t1 H
- ?>
+ R# @! L/ }" d, e. L8 Q2 t
复制代码 我自己写的4 w3 _; y; [1 z3 K: L/ C& K
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|