|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 E% b2 o4 O- w" P; l' k
# g: ~: g8 f7 ^$ j) M6 K直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持1 o+ G* a; q# P: e( D
7 a5 ]7 v9 ^$ Q8 m @' f0 z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
. c+ ?: Q" \, ~ \, |- V
/ h* o) [1 N; _( P; _8 k8 W7 W方便实用 简单 何乐而不用呢
. K8 ~2 {" e& k3 ?3 J1 }* E- <?php
3 \8 B0 ]& R5 o& K5 T" M - - a% h9 i' @' o: |! M0 h
- define( 'ABSPATH', dirname(__FILE__) . '/' );/ C- F+ K3 u$ }. m: L" s% o
- require_once( ABSPATH . 'wp-config.php' );
! q1 B0 g/ A1 D - require_once( ABSPATH . 'wp-settings.php' );. n2 @( J- j, {) F! t& j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) {! X6 H8 G1 v! O - require_once( ABSPATH . 'wp-includes/functions.php' );
. A. Z# E6 ?+ n% H - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 {3 ]; P6 q7 d" L y% @ - $title = $_POST["title"];
' P8 P. O7 `0 |8 w, n( O - $content = $_POST["content"];
7 C1 z. F: I5 v - $tags = explode("_",$_POST["tags"]);
1 u# L+ i' Z2 x6 x0 r, F - $cate = $_POST["cate"];* }, V7 `- Y' U% e3 S/ a+ Q- H- c
- //print_r $tags;
$ I& b2 A# E! x4 |0 ` - //( {& y' B; U& M
- //8 Z, E' h; i& X% Q8 S
- $wp = new WP();
0 |+ ]- O8 g* N# _ - $wp->main();
/ u! Z# d2 `1 F2 J - //
3 V8 F$ w0 c# n u6 L2 U - $my_post = array();
+ H8 v; g2 s$ V) U. a& o - $my_post['post_title'] = $title;
# u! }9 z3 f# d6 N - $my_post['post_content'] = $content;+ V1 C" d. }" p/ c
- $my_post['post_status'] = 'publish';
& a; n. R3 C/ q9 s: q! H! ^: X& w" A( A: a - $my_post['post_author'] = 1;7 d+ k: m2 H% d) x. O5 k! \
- $my_post['post_category'] = array($cate);' m+ ?' ^2 W0 E
- $my_post['tags_input'] = $tags;- R, `& c! T; v4 M. d
- //$my_post['tags_input'] = array('tag1', 'tag2');
- R% {3 d8 M4 D0 d - //$my_post['post_status'] = 'future';" x6 a4 L" T( d e7 n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; E0 v4 W4 f, a* {9 n- d9 g8 {
- ; R5 M8 _) o. ?$ W4 x
- // Insert the post into the database
" s- q; n% I8 | - $ret = wp_insert_post( $my_post );8 T1 r2 n5 H! O8 p: J: z
- echo $ret;( @2 a$ j6 K# @/ V4 `7 J# `3 i
- ?>. h2 p0 T9 d. ]8 N
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
+ K+ ~$ @8 g0 z, ^+ l- <?php
6 T# E7 `- a7 F* H - define( 'ABSPATH', dirname(__FILE__) . '/' );
; t9 q u. ?. E - require_once( ABSPATH . 'wp-config.php' );8 l% O, L+ w+ a+ l! ~; @ M
- require_once( ABSPATH . 'wp-settings.php' );
3 N! v ]5 J% A& i - require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 j4 ]) {4 _+ M: p& A5 @ - require_once( ABSPATH . 'wp-includes/functions.php' );
; c8 @' z0 f$ v9 Y& v - require_once( ABSPATH . 'wp-includes/plugin.php' );. g/ ?$ o, q' x( H" o- L+ c
- $pic_name = $_POST["pic_name"];
8 O0 ^' U$ q4 k. c5 W0 T6 j1 O7 _+ N - $pic = $_POST["pic"];
# e" a" {1 [' `$ G0 M - if($pic != "" && $pic_name != "")
6 T% Y! y- Q1 F - {) @) F. J% y4 @4 w$ R+ B
- $path = "images/";/ ]3 m5 l! I& _% S) `4 m
- $pic_name = $path.$pic_name;) _; o0 r* v# S+ c0 y# H
- echo $pic_name;9 E& Q* z2 H0 E7 B& y1 L. {+ T7 y
- echo "||";
( N, y' h) [* X$ ?( k( {( T c - error_reporting(0);
9 M$ g7 k0 ?% e( w2 F" h - mkdir("images");
, n5 Y& ]4 C Z% v& { - $handle = fopen($pic_name, 'w');5 B/ v- {5 v% ^( l
- echo fwrite($handle,file_get_contents($pic));4 a# P. p' A& C! l2 n
- }' g+ v/ w+ T7 E: J0 N. C6 x
- 2 i5 X. p- _. e
- $title = $_POST["title"];
9 o2 q9 L1 z/ x - $content = $_POST["content"];
0 r1 b+ P& m% [$ ^! n5 X# L - $tags = explode("_",$_POST["tags"]);
3 S/ P" o. [# o$ Z& V7 G0 X - $cate = $_POST["cate"];( |6 j! o: B& n$ I0 @6 N3 F+ a
- //print_r $tags;0 _" P9 D3 X$ M
- //
2 g4 A( o i8 q+ h7 ? - //* L3 Z' H* R1 s
- $wp = new WP();+ L3 M& Z7 J8 K* ?( c* N3 w7 V
- $wp->main();
+ ^; ?; V( G# F$ G. J - //
+ _" o J4 U. b' | - $my_post = array();
- Z: ~* ~2 ~0 ?: A/ T - $my_post['post_title'] = $title;$ |1 t) [; N% ]. B* N! G
- $my_post['post_content'] = $content;; E$ B) r( J |' T3 \* g7 Y" y7 Q: {
- $my_post['post_status'] = 'publish';
; c' C' q5 O/ C: E - $my_post['post_author'] = 1;. M; U/ t9 _+ S" L5 V
- $my_post['post_category'] = array($cate);
q8 g% C# y% |3 F8 x3 h - $my_post['tags_input'] = $tags; w# Q4 B- B! N, n
- //$my_post['tags_input'] = array('tag1', 'tag2');
' K6 S4 O: L4 U - //$my_post['post_status'] = 'future';' D7 V5 ]: a' F N, x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
) g6 g8 T' ?* U0 Q5 E - 6 M6 O( T4 G0 l9 b$ ^& G6 B4 F
- // Insert the post into the database3 V3 U% L) x6 a e6 l4 O, D E3 }0 U; u
- $ret = wp_insert_post( $my_post );& P3 `. `4 `1 n' m6 [3 P- s" l
- echo $ret;
+ L5 [! r* h* l. ?6 {' b* @3 { - ?>% o4 x5 k3 |, X6 b: W& K
复制代码 我自己写的4 S/ ?8 S' p0 h0 b
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|