|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 L8 [6 }& p* P% o5 h
2 ^) }4 R F+ N4 i4 ]% d3 j5 c直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( E8 R0 H1 Q2 a$ u. c
) `' L9 |9 }* A$ {$ b, B我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了2 _6 l3 `9 ]+ J3 V6 \
# c( N- r2 F" r* p1 U/ t0 r4 f
方便实用 简单 何乐而不用呢- 6 \/ S( U- e/ W7 t/ }0 `& _. S
- <?php
2 [0 U, c ~6 y# f/ R' e! B- P7 w - ' R; u' k- p; j N
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ i5 V e, O/ `/ B6 F - require_once( ABSPATH . 'wp-config.php' );
6 k( \0 ^5 Z2 ` - require_once( ABSPATH . 'wp-settings.php' );: E) } R2 D7 `& k w6 d
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 O" y# T& {9 v3 l5 P - require_once( ABSPATH . 'wp-includes/functions.php' );% I/ M V: G( e7 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );- O) \# K6 F9 y$ M7 `
- $title = $_POST["title"];. {) g5 E, Z( z# J$ |
- $content = $_POST["content"];+ ^( `" i# g7 C
- $tags = explode("_",$_POST["tags"]);8 J9 n M3 r& B; u; A6 t
- $cate = $_POST["cate"];
. A- |9 ^# z! D2 G# ] - //print_r $tags;
8 t' \. s! w' T* s - //
; l! _' {+ x& b. a! ]5 ~/ h - //5 ]8 j _( g3 o6 {& ?
- $wp = new WP();$ A% Z# m$ L3 V6 s
- $wp->main();$ l, X( Z& g! Q' J3 P6 E# G
- //
4 |: y5 I, s$ q2 N7 A' F - $my_post = array();
1 u, G; s$ J! @, W7 p$ V+ x+ t# K - $my_post['post_title'] = $title;0 n5 R6 I/ A# N* y% U
- $my_post['post_content'] = $content;
. u$ {0 k- o( ~# j/ x! x - $my_post['post_status'] = 'publish';
; X5 o ~9 X/ C. Z - $my_post['post_author'] = 1;* M4 y' W' j/ S6 O; j
- $my_post['post_category'] = array($cate);
! r1 n2 x9 c& K) V0 e# H - $my_post['tags_input'] = $tags;" @% f @. O# l% [1 [
- //$my_post['tags_input'] = array('tag1', 'tag2');* t0 J, l& u/ U' M6 q9 k
- //$my_post['post_status'] = 'future';6 o ^. L" a: i, N7 N: g
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
% Z2 [0 X# q! Z! O - O- ^9 \9 D4 } X9 I
- // Insert the post into the database
- }% x( x3 ^0 @) Y - $ret = wp_insert_post( $my_post );" I. D. d2 _) ]8 s& l7 t
- echo $ret;
7 D. X. [, D+ J7 Z9 Z& z6 l; y7 ` - ?>: g) L( x1 j& p" |1 y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, i' `" @' o7 u1 o7 r" M4 q- <?php2 E$ F4 R/ U5 d8 J# i) d* I, u
- define( 'ABSPATH', dirname(__FILE__) . '/' );' i0 |$ A, l6 f3 {6 q! n5 V1 Z: Z
- require_once( ABSPATH . 'wp-config.php' );, H/ p/ ]5 G7 y
- require_once( ABSPATH . 'wp-settings.php' );1 L6 D8 b0 E& Z3 w6 q' E
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 D+ F, h- R1 z# N - require_once( ABSPATH . 'wp-includes/functions.php' );
1 X; y# T+ Q$ w( h( l - require_once( ABSPATH . 'wp-includes/plugin.php' );
0 B B% I% h+ t2 f - $pic_name = $_POST["pic_name"];
: I+ [5 H" {" t' l4 E! D - $pic = $_POST["pic"];& k% Y2 d# W" ]9 e* j- W9 w+ c
- if($pic != "" && $pic_name != "")
: ^2 V) A& T( ?* D$ h8 E' s! } - {
1 g- m7 K* g; K( G - $path = "images/";+ C* k S1 N8 S6 Q, ]) a
- $pic_name = $path.$pic_name;
+ E! b7 k# s" O2 p# \3 O" R - echo $pic_name;
6 @" e2 a) x4 ?3 f* D- d - echo "||";
# X8 c. N. p6 a; B' |8 X f - error_reporting(0);* x8 s! @7 D: o7 }) x! r
- mkdir("images");
. r0 x; h2 y3 p H( @9 y2 Q& x) f - $handle = fopen($pic_name, 'w');2 O# }9 s7 i, H; c2 B. E
- echo fwrite($handle,file_get_contents($pic));+ X$ U1 k- p ? X9 }/ D
- }$ A. W7 |2 G# r, A; m
- & @$ L. n t, _( C9 h" X' d
- $title = $_POST["title"];5 e; G" E9 p6 g) Y- L9 ?' j
- $content = $_POST["content"];" `/ z |, s' \( i; `: Y; c
- $tags = explode("_",$_POST["tags"]);! L# B! I7 R+ R$ O8 k
- $cate = $_POST["cate"];; R* F: @4 M) A- s- ~7 Q3 k4 m
- //print_r $tags;
. K5 G5 ]9 E! p5 F. y( o+ t - //" I, ]( i$ C' x8 M: }& W- K$ ^+ s
- //
6 |! Y& g. l2 b! }- r - $wp = new WP();3 e9 }, L2 v# F
- $wp->main();* B+ P4 j+ g! Y# C' @
- //
/ S% r) W4 q! b2 G( W( O7 ~ - $my_post = array();
4 \- @. X3 V) s6 {; l* ?8 a! \* K! P! h - $my_post['post_title'] = $title;
* S0 \0 i8 s7 [5 z5 N: | - $my_post['post_content'] = $content;3 ]" E8 Y! R" \4 A0 q
- $my_post['post_status'] = 'publish';
9 \) r7 N0 Y7 X" K9 d1 D* f - $my_post['post_author'] = 1;
{; e$ q+ |1 d. H7 F4 m4 F - $my_post['post_category'] = array($cate);
& K5 @# M8 U" [' S; f9 } - $my_post['tags_input'] = $tags;! L0 i( C) @8 Z; Y+ j, a0 Z: F8 |
- //$my_post['tags_input'] = array('tag1', 'tag2');
1 w5 j) h3 N6 J; X, p$ ~ - //$my_post['post_status'] = 'future';$ p' s2 H7 K# f8 v
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
* q) z/ s' B6 ?7 O" ? - 9 X/ p% @$ p4 p7 f& c7 D: W
- // Insert the post into the database8 X! R5 O3 I, h6 E
- $ret = wp_insert_post( $my_post );
* ^/ @: I$ k1 \6 d4 v* w2 Z( O; g - echo $ret;* [ T4 X( }# I6 j
- ?>! ]9 C& v# r. b2 G
复制代码 我自己写的
. ?& H4 Y; j6 t5 V( O) Y7 X插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|