|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
* H( X* Y6 l1 U3 r" m2 x2 |4 ^; i. {! n, J0 x$ s4 |8 M$ O# A2 ~
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持# l* K5 _$ X; y$ L
. R M7 C$ B4 h7 ^/ p我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
5 J X1 H7 w E4 y* A9 `( A3 |2 @) B% F. o
方便实用 简单 何乐而不用呢
4 K. I2 `) v) {! z0 K/ E5 l6 I- <?php
% r) L1 J7 t5 p8 W( U+ y
% R4 }; e+ X' w& M+ R" v2 e# j- define( 'ABSPATH', dirname(__FILE__) . '/' );7 u ^5 r9 Q4 W0 A
- require_once( ABSPATH . 'wp-config.php' );
) y: N* W+ Y0 q6 f, K - require_once( ABSPATH . 'wp-settings.php' );
+ P5 r6 T/ k( k. r* N; w9 J6 F - require_once( ABSPATH . 'wp-includes/class-wp.php' );% ]& {( l. w6 u1 Z1 l; r+ K
- require_once( ABSPATH . 'wp-includes/functions.php' );) y1 Q% v4 a0 A
- require_once( ABSPATH . 'wp-includes/plugin.php' );
+ h% F2 w, T0 w - $title = $_POST["title"];
: p! Y; t( `3 P1 P. C - $content = $_POST["content"];) P$ f1 M* S1 Z$ J) i$ g- l) m
- $tags = explode("_",$_POST["tags"]);
/ I6 ?7 h7 s) b% W2 M' j4 s - $cate = $_POST["cate"];
7 U" r* d' Q i3 T2 U4 D# e - //print_r $tags;
6 S3 a" |$ \' V) Q6 i1 T - //; I9 a1 L0 j/ s; p: u
- //5 |' u3 c# |' H, A- X& d7 B5 D3 L* I
- $wp = new WP();1 i( y7 N9 x" f% J
- $wp->main();
0 z$ M! n% s' f3 Y1 |. _ - //
; V' [9 V t/ G6 x - $my_post = array();8 f6 l, K% i' [, ~- Y1 l; c
- $my_post['post_title'] = $title;, d8 q. F0 a4 h
- $my_post['post_content'] = $content;" q& S3 `/ |% L
- $my_post['post_status'] = 'publish';1 }" b6 ?) N; h! G" D, m
- $my_post['post_author'] = 1;
! y3 b9 c3 ~. O1 J* G - $my_post['post_category'] = array($cate);
, l7 a0 e5 e- S0 N - $my_post['tags_input'] = $tags;. c5 e, M6 O( J# ]' e7 F9 @: D
- //$my_post['tags_input'] = array('tag1', 'tag2');+ w( i f l1 w% m1 H' e* f
- //$my_post['post_status'] = 'future';
+ [' j; ^+ n( N - ////$my_post['post_date'] = '2010-07-04 16:20:03';" Q- [' f) p. J. R; [7 t3 v+ K
- / [ \6 o6 z5 Y7 ?
- // Insert the post into the database
4 [. z& Z1 D7 x* \1 d" S4 [ - $ret = wp_insert_post( $my_post );
- r+ B% D' e3 |: w# a3 [5 `+ @$ y - echo $ret;
! n; x' |0 e/ q - ?>
# V+ b- {/ F) t* s7 i8 n
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- p- ?; |7 ~5 N" A- <?php! N4 C8 a% R" Y, e% x0 E* W9 l
- define( 'ABSPATH', dirname(__FILE__) . '/' );
( g' q7 s( |/ `7 Z - require_once( ABSPATH . 'wp-config.php' );% ?7 R! I6 g; y7 ~5 t; S6 \
- require_once( ABSPATH . 'wp-settings.php' );3 C3 ~7 Z) v5 h' ]4 g
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
* }' @# n% I1 Z: s0 J - require_once( ABSPATH . 'wp-includes/functions.php' );
! x% A9 V. N5 b4 C2 w) L) ?7 D - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 F0 g- E% Z; V' d: i8 z7 x! t - $pic_name = $_POST["pic_name"];8 X5 f# g& [1 x4 v2 f
- $pic = $_POST["pic"];8 n$ I/ w% V/ f
- if($pic != "" && $pic_name != "")
6 p3 U. o0 a1 k( M8 y - {* E& H; a: Y! w2 R, ` Q* M: r' ~( a
- $path = "images/";
7 M7 f: s4 x T: R - $pic_name = $path.$pic_name;
& e1 i7 \) R5 ~* T7 b7 K/ @ - echo $pic_name;( k6 a5 J* h2 V9 ]' I% A
- echo "||";; ~! G4 e8 u3 b8 p( T: h5 H" e/ \
- error_reporting(0);$ x: S! m9 n" H _+ D- w n/ ?
- mkdir("images");
9 Q/ n: i' ^0 _4 Q' v# x - $handle = fopen($pic_name, 'w');
`+ B0 ^9 v$ q$ j. W( B! g - echo fwrite($handle,file_get_contents($pic));
$ v/ r! c Y. d- J5 G7 f D - }0 C. p2 J9 x6 G6 c( m
& s4 ?' H% z* e# `- $title = $_POST["title"];. m+ M5 f3 |, e% s; }* f
- $content = $_POST["content"];
- z8 c5 [+ f; U" U - $tags = explode("_",$_POST["tags"]);
6 P5 I5 f0 V3 K& F/ M& {0 z, B5 y% f - $cate = $_POST["cate"];
; Q6 ]3 |" c8 g o9 W7 t - //print_r $tags;
, ^$ g2 {3 _2 C: c& {% N+ ^# J - //6 D* G: k+ _, D$ v
- //' d3 o( W: G- f/ _7 s, F
- $wp = new WP();9 q. `: Z7 K% h/ m
- $wp->main();
3 x' H8 f5 u' l - //
/ i* O: z( j: i, g+ p, P* X - $my_post = array();$ O- s- @6 ?0 K7 V9 `
- $my_post['post_title'] = $title;
; f- x! C, X6 H# v$ u d - $my_post['post_content'] = $content;
9 Z6 k/ k' }/ `/ f9 }, k3 i3 l - $my_post['post_status'] = 'publish';; h3 A$ p6 V& ]; O m) e
- $my_post['post_author'] = 1;1 [6 {6 X) K- _+ K$ N! v. B
- $my_post['post_category'] = array($cate);
7 p/ d' i$ r2 p# i3 F ~ - $my_post['tags_input'] = $tags;+ f9 ]+ C" N. j; S5 ^
- //$my_post['tags_input'] = array('tag1', 'tag2');
( c T6 ?. q. M0 V0 g - //$my_post['post_status'] = 'future';
5 J+ M* ?" a5 F6 X" @1 y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. ~/ X! H: b# {7 o6 `+ N - ' ]9 m$ A0 A, _' J7 M
- // Insert the post into the database: a6 P. ] r- | t8 _
- $ret = wp_insert_post( $my_post );* h _ J" F7 P
- echo $ret;" |1 W6 i5 E9 ]" l+ S# Y
- ?># X9 Y7 h! u: U8 }( A- N! R/ @
复制代码 我自己写的
8 X q! F' g- B. S6 G插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|