|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; ?' ^7 B$ v/ `0 R v. u1 {4 s. p, P' _: A
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持( G. R% ?# C- P9 H5 B0 e
& a3 U9 H: m3 G5 `( ]1 M我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ R8 q/ s0 r; D2 W7 B! z d& F* A4 Y' r7 V
方便实用 简单 何乐而不用呢
- d8 O @* p& R5 j. s# v- <?php2 ]& C: K. A5 T. {
- ) V: n1 K& V8 _% J- q1 C0 r: j! Y
- define( 'ABSPATH', dirname(__FILE__) . '/' );( D# R7 u8 c9 l* |0 ~9 z
- require_once( ABSPATH . 'wp-config.php' );
: V' a. b9 |! `+ H( n - require_once( ABSPATH . 'wp-settings.php' );
. A% B4 |3 v( b8 L - require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 O! P$ n+ |6 G# Q8 R6 B' O6 r& X4 A8 i - require_once( ABSPATH . 'wp-includes/functions.php' );
+ O# b9 ]3 l+ C' m0 U' h: w - require_once( ABSPATH . 'wp-includes/plugin.php' );" x7 V; i5 M# d! ]: ^+ \7 A
- $title = $_POST["title"];7 m% n9 f6 s) a4 h: G# K) Y
- $content = $_POST["content"];8 R+ a: M9 Z! F
- $tags = explode("_",$_POST["tags"]);
- P8 Y1 t1 ?% |0 D1 F- h! ? - $cate = $_POST["cate"];5 v; P2 U( E7 U. b2 x
- //print_r $tags;
( n8 V( @* p' E. h! Q5 e6 v; N - //
4 L/ B; e# W, _0 S+ n2 @& i - //
0 c3 a- v% y# l( R" E( t - $wp = new WP();# z4 |9 R' ]7 l5 S$ L4 P% T
- $wp->main();
+ |5 t3 G1 m/ v# A! Z. Q% q - //
8 F# n+ N6 Z! {) i/ q" @9 ] - $my_post = array();. L+ D. M# ^- z0 C
- $my_post['post_title'] = $title; Q6 l" ^$ H% W' Y
- $my_post['post_content'] = $content;/ v: f% Z E F$ C& i. y
- $my_post['post_status'] = 'publish';
1 J& o- [) F2 K$ ]3 g/ [ - $my_post['post_author'] = 1;" m! I) ?0 M; E! U9 W" \
- $my_post['post_category'] = array($cate);
/ I- M/ ^: u8 o, b# p - $my_post['tags_input'] = $tags;
1 |: H& M: Z# ~( R2 m& X3 L8 k - //$my_post['tags_input'] = array('tag1', 'tag2');
# D0 K/ I( {. d- n# l$ V# j - //$my_post['post_status'] = 'future';
+ M' i) P" c- W/ g4 H - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 o/ B# p2 q J! K8 |
( | C8 I0 H" D$ z! v0 u- // Insert the post into the database+ c2 C) R, [: K, h
- $ret = wp_insert_post( $my_post );; Y0 X" u0 Z9 o) G) I
- echo $ret;
) `8 ^4 P+ u1 ], O( l% |9 w - ?>
2 J' z5 U% H8 R2 ~) x6 \* D0 Z8 M
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, ]- }/ b- k9 }: E8 P7 U- <?php
6 G# l3 o* ~) ?3 A9 r+ b - define( 'ABSPATH', dirname(__FILE__) . '/' );
8 Z4 U4 ]; p" e# B/ o. E - require_once( ABSPATH . 'wp-config.php' );
8 u, \ F- ?; e' W( I - require_once( ABSPATH . 'wp-settings.php' );
1 a6 {( n S) f; `8 a4 r( [ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
& U# c) ? @) {: ]* L - require_once( ABSPATH . 'wp-includes/functions.php' );
4 @8 Q2 A" M, B+ K7 s - require_once( ABSPATH . 'wp-includes/plugin.php' );* r6 o! k8 z+ ? S
- $pic_name = $_POST["pic_name"];
/ e4 d8 Y7 C7 A% l: H5 c - $pic = $_POST["pic"];0 Z$ C: T7 h; U# j) u* Q+ c6 i6 y
- if($pic != "" && $pic_name != "")! X. D! ^. c$ G e2 H
- {
" X( v# Q+ ~, a% C$ K, c - $path = "images/";+ G! D' N! d6 ~; h
- $pic_name = $path.$pic_name;: o- j* C1 z9 k: M
- echo $pic_name;7 ?7 p6 s! d5 o: Y
- echo "||";
( S+ `4 K w6 j7 j - error_reporting(0);9 X3 S3 O% X3 a5 \4 g& o% I- W v
- mkdir("images");! }7 q/ b; x; Y/ {- ]
- $handle = fopen($pic_name, 'w');
6 v0 D" f" U5 @% P6 P6 O% } - echo fwrite($handle,file_get_contents($pic));, O- R# A# q9 {! z, q! v
- }% T- u% I% G( U5 l
- 5 h- [3 i/ x* H& l5 B9 h2 F
- $title = $_POST["title"];
% K6 `6 y* v' z - $content = $_POST["content"];/ B! O7 D" L# b5 ]6 ?
- $tags = explode("_",$_POST["tags"]);
$ E% |( s+ N- h5 h - $cate = $_POST["cate"];; R2 n7 u6 A/ h! x' ^7 C" J
- //print_r $tags;
, S7 o( _9 F4 C8 s5 u* B6 M% k/ x - //
! C$ e& [& ^! J# d - //
' Q( e, f+ ]1 j( x - $wp = new WP();
P7 T$ P7 ]5 p" g - $wp->main();4 B! g& O% ?$ ?1 h/ m
- //
" z8 d+ p( C% g# W - $my_post = array();
8 r, V, }! o- H0 Y - $my_post['post_title'] = $title;1 R6 R2 N9 J7 I" Z C. B1 ?
- $my_post['post_content'] = $content;
~% p/ k! ~5 }! A5 S4 ]/ o - $my_post['post_status'] = 'publish';
6 B& w9 d0 _# ` H - $my_post['post_author'] = 1;/ c* y5 J! G) n
- $my_post['post_category'] = array($cate);
/ o8 _2 B' C) V - $my_post['tags_input'] = $tags;
, F! I6 R- s/ n7 U% K - //$my_post['tags_input'] = array('tag1', 'tag2');
) q4 b5 w6 Z R1 B! b - //$my_post['post_status'] = 'future';
' k3 E. k6 P. t* M - ////$my_post['post_date'] = '2010-07-04 16:20:03';
' ]6 g9 \+ ^, h( n - 0 ]9 g/ [% r6 _! P) {9 ], L
- // Insert the post into the database$ ]( Z$ J" C+ [6 M
- $ret = wp_insert_post( $my_post );' `0 n; t( Z b( g. u
- echo $ret;
( m2 h* I8 ?4 |" t" V5 k8 ? - ?>
( N* c8 Q( O/ n
复制代码 我自己写的
+ l y% @, @9 t1 [8 I插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|