|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 a! s! Y, B( E- S0 y( p1 j+ E |; O9 s8 q' U% i. a+ [9 S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- K2 f4 z+ m9 T6 C
! S" I% z: ]: f, v: f我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了4 |0 U) x! }+ l% t2 A' L3 o3 y1 `
/ U8 e' y3 g' v# y方便实用 简单 何乐而不用呢
. @: f J6 ^# ^; w! x ?- <?php
. c6 \$ j* i9 m+ @ - 8 \7 q# N# |" U# L: n Z5 }/ R
- define( 'ABSPATH', dirname(__FILE__) . '/' );
J( Z0 m8 [2 v/ V/ |7 j9 L/ y# Z" G - require_once( ABSPATH . 'wp-config.php' );
/ C2 O: ~$ s6 D4 q2 N - require_once( ABSPATH . 'wp-settings.php' );
9 k' j T; A8 L - require_once( ABSPATH . 'wp-includes/class-wp.php' );" F- Q: v- ~! W& y t% O4 @
- require_once( ABSPATH . 'wp-includes/functions.php' );; x3 d4 w1 k, f. c; y7 T
- require_once( ABSPATH . 'wp-includes/plugin.php' );5 T4 h: D2 d# V6 P
- $title = $_POST["title"];& j+ Y+ K/ S' w) n/ o9 @
- $content = $_POST["content"];
* W4 m3 A1 \& A- x& L - $tags = explode("_",$_POST["tags"]);
8 J4 m7 f! E% F: T6 H8 f - $cate = $_POST["cate"];
( @2 T; g( @4 i' D5 Y7 | - //print_r $tags;* {! H3 A4 e$ i4 r) U# E. Q& t- l
- //. Z( w7 J3 j3 B$ R1 s. y0 S* J
- //0 @8 _+ C! `. ~, D3 {& c- R+ H/ u
- $wp = new WP();
$ B2 S/ v% R a2 D - $wp->main();
0 c+ W5 R# R8 O1 x: L0 E" l6 \ - //
) Y: d) \+ ?# o* F8 g, N7 _ - $my_post = array();
1 U) O: M/ }; F" C/ t - $my_post['post_title'] = $title;
' }1 N$ @: S2 o( t - $my_post['post_content'] = $content;9 ^- B: R& w+ C& s! W8 U% M. k
- $my_post['post_status'] = 'publish';
$ ]8 X P/ W/ F$ C, r* e - $my_post['post_author'] = 1;7 |( w' ~% q: A" k
- $my_post['post_category'] = array($cate);, ~/ r6 |: R8 H7 f; }8 p
- $my_post['tags_input'] = $tags;0 v) v% ?9 {- e) f
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 C+ u, K- i: e( D. S- e - //$my_post['post_status'] = 'future';
+ t0 _$ g$ n: G$ X, c: l# ~/ [9 f - ////$my_post['post_date'] = '2010-07-04 16:20:03';3 v3 o8 b/ n4 C* Z. w
8 G1 n1 U: j8 t9 k. V; f& i- // Insert the post into the database
% M3 K( m' j8 A+ s& V! M: f - $ret = wp_insert_post( $my_post );
2 p% Y0 T) R1 S* ^* v& F" _) ` - echo $ret;
3 Y$ x; i! J' b2 J - ?>
* K/ ^" \. \. \) n$ P
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 l8 H/ B! A, x5 O5 e- <?php2 r# T3 E" {& V/ e
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 q( S6 z/ R, s8 _0 H - require_once( ABSPATH . 'wp-config.php' );
2 b- N0 u- t( x - require_once( ABSPATH . 'wp-settings.php' );+ K6 N" a8 o8 T( b% b0 Q9 C
- require_once( ABSPATH . 'wp-includes/class-wp.php' );" E, ?8 {4 Q5 ^) E) t8 n2 s6 o
- require_once( ABSPATH . 'wp-includes/functions.php' );
. y v7 b- C2 u& \ - require_once( ABSPATH . 'wp-includes/plugin.php' );% J; E) U j( U! J2 L4 H
- $pic_name = $_POST["pic_name"];
" l+ t# J. {4 a( [: ] x - $pic = $_POST["pic"];4 s! g- n: U1 A5 o% j$ z
- if($pic != "" && $pic_name != "")
' R3 n: M& {% z( L5 d0 x - {
% u/ T. g; G4 E# y; u8 n, ?6 L - $path = "images/";
6 a( H/ P3 @6 F" Z. e - $pic_name = $path.$pic_name;
5 ~, z: b7 ?+ c4 k! l - echo $pic_name;
[7 \4 u9 w. u) z0 K - echo "||";
: d# o" w/ r, c9 `$ { - error_reporting(0);% y' @# a: N$ i5 Q; H- ^: o
- mkdir("images");
9 U3 k* {) D% o3 X# |& q3 r - $handle = fopen($pic_name, 'w');0 P8 c) h, I4 X, I0 g% Q" d0 d# O
- echo fwrite($handle,file_get_contents($pic));
- |* X# v, y! }3 B) @. n8 ~ - }
& W& {/ U5 Y; Z4 e* Z - $ ^% r9 {. x7 f: f4 v
- $title = $_POST["title"];
1 t* j3 A5 S8 F/ i& n - $content = $_POST["content"];
( t. f8 i( J" c! a- ` - $tags = explode("_",$_POST["tags"]);2 C! v) N5 d0 N+ K3 o: ], b
- $cate = $_POST["cate"];
+ I5 ]8 ^3 @$ n4 c - //print_r $tags;* ^4 H q8 f' H( ?* Y# E
- /// i" F: A8 a! q7 R6 b
- //6 P3 x6 ]0 g I( N Q4 ^4 g
- $wp = new WP();
f z7 s0 m5 J* \ - $wp->main();
: m& C6 A6 a, A - //
/ ?; u W4 ]3 x, d - $my_post = array();
t6 e7 ?' p+ H. X0 o5 G - $my_post['post_title'] = $title;
: p. z& x) v3 j' l( `9 v - $my_post['post_content'] = $content;' `' R3 h1 }+ W
- $my_post['post_status'] = 'publish';
; B+ C5 g8 |0 L& U; [& K - $my_post['post_author'] = 1;- @2 O6 g4 }4 _5 I; }" F) [! j" A0 q1 ~
- $my_post['post_category'] = array($cate);7 X" g' ]( ^( j3 g a" ~
- $my_post['tags_input'] = $tags;
" J) R! [# a, ^) u5 |6 s% D - //$my_post['tags_input'] = array('tag1', 'tag2');
+ _( H/ C% t2 x6 c' v - //$my_post['post_status'] = 'future';2 u/ f4 V0 C9 m& @2 W, O
- ////$my_post['post_date'] = '2010-07-04 16:20:03';6 U* |* B2 l6 |: ~
- ! E; ?2 t8 A# m" o, W8 F
- // Insert the post into the database6 d, G+ h: T' \ \% N$ `
- $ret = wp_insert_post( $my_post );/ t$ O' g. ?; c, I7 c0 x4 R8 F
- echo $ret;
4 {4 Z" ~, B+ U6 m - ?>
1 ]/ l. A& |9 y$ K( o6 x8 m
复制代码 我自己写的
7 _ L* X( v( f( X, @. i% u! Y插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|