|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
$ q. t7 }1 O. `2 y2 G7 ~" \: \; m) D' r
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持4 l8 v& I: t T" T2 b' ^
8 j) L3 e# `( @5 Y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
. K" f+ E2 W' |# n9 [. w, b% ^2 ^0 h+ k# `- L* K1 D
方便实用 简单 何乐而不用呢- 8 N5 Q- @) M" c8 D; h* S
- <?php
/ P: B7 }9 D B* E5 P9 H
0 y: G- ^# k* }1 ]" l$ S- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 l% l* v5 g. H4 G! i2 ~ - require_once( ABSPATH . 'wp-config.php' );" j+ @. T$ O8 b0 W6 @
- require_once( ABSPATH . 'wp-settings.php' );# W8 x# S/ H2 d# v
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 F1 |5 p) m, _# |; S2 w9 U5 H - require_once( ABSPATH . 'wp-includes/functions.php' );
3 l/ ^& N7 f& U, G9 s - require_once( ABSPATH . 'wp-includes/plugin.php' );6 ^5 j) A4 e; J1 N/ [' s2 `
- $title = $_POST["title"];
% o$ f' u1 h- b/ t y8 B1 P$ H - $content = $_POST["content"];
; g0 b3 e0 v5 C, _- Z - $tags = explode("_",$_POST["tags"]);
0 u& x# G9 r1 ?% Q0 U- U$ u - $cate = $_POST["cate"];
0 i2 U6 {# K( V6 w0 Q9 t - //print_r $tags;
5 M6 z. ~2 Z+ C/ P$ \: k - //7 X6 \$ a# |3 u: g0 ?1 s
- //; |/ e8 U% F0 N
- $wp = new WP();
_. L: g H! `* P5 ]* E2 L - $wp->main();; A% X1 x. G6 t# ^6 r
- //' }: J$ w# [) f% n9 q
- $my_post = array();% J Q4 |8 [ X7 l7 z2 @ m
- $my_post['post_title'] = $title;6 y2 p8 e/ S: t% c$ j# |- B4 j
- $my_post['post_content'] = $content;
4 ?4 X3 r6 C' }. }0 z N+ J* m - $my_post['post_status'] = 'publish';/ |& C, x6 ~2 J* ~8 V- A
- $my_post['post_author'] = 1;. z a# L6 `7 k9 z# a
- $my_post['post_category'] = array($cate);
O& ^( R. O) i) K0 F - $my_post['tags_input'] = $tags;
6 h* @5 E& A* g% R5 N4 B* A% g. s2 N - //$my_post['tags_input'] = array('tag1', 'tag2');; b. D' r4 l# @! D; v4 `
- //$my_post['post_status'] = 'future';
9 C% c3 R6 L; B2 O- y - ////$my_post['post_date'] = '2010-07-04 16:20:03';* J$ X3 T9 p& @& T
- 0 ?# u! A: M7 }
- // Insert the post into the database1 F/ F) r& O& g3 J0 L: ^
- $ret = wp_insert_post( $my_post );5 M, O4 C% c ]1 m/ U. ?. \
- echo $ret;" r! I# T8 |0 J0 A. R1 d
- ?>; b; L8 k; E2 \5 d0 m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 1 P1 O" |2 H( ^: S% A
- <?php/ Y# S. [0 z- y# {5 v
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. _1 B- l& R) i/ z' u1 Z- ? - require_once( ABSPATH . 'wp-config.php' );2 U1 @4 A# V1 ]9 x
- require_once( ABSPATH . 'wp-settings.php' );
4 m0 I$ Y2 m: r1 X+ U* @ - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 e4 C) P, q0 ?" f
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ a$ N" E5 o# v - require_once( ABSPATH . 'wp-includes/plugin.php' );0 q6 k" h0 c% y, \& k
- $pic_name = $_POST["pic_name"];1 ]" B$ v% `) R5 {
- $pic = $_POST["pic"];
H ^) Y( ?; `) f) t% B6 V; A }" h - if($pic != "" && $pic_name != "")" u$ r+ }8 L L( R* V" ?9 N9 R
- {
$ n9 M/ G" F$ S/ T' Q, J; l - $path = "images/";3 i1 ?5 H4 V( R ]
- $pic_name = $path.$pic_name;
7 A1 m+ {& V% b [5 W - echo $pic_name;% P* ^% b, M9 b: a5 w5 d/ U" D
- echo "||";
$ V; i/ G$ m2 x( S5 o$ B8 H - error_reporting(0);
' z( w& U) I7 F - mkdir("images");
" p4 |! y6 A8 p - $handle = fopen($pic_name, 'w');
: d% z. j8 h0 Q9 a4 G6 g7 |- y - echo fwrite($handle,file_get_contents($pic));
/ _/ O; ]4 x6 N/ p, ?' d - }
! H |; U; \% P4 d" S - 7 j2 u0 ^; ]2 P2 Z. b
- $title = $_POST["title"];
: G6 _0 H6 W0 n. x - $content = $_POST["content"];
) r! V, N7 F% g- a - $tags = explode("_",$_POST["tags"]);4 ?' G* i3 e, U5 N( `
- $cate = $_POST["cate"];
0 |) o% p* T+ x: L/ z* o - //print_r $tags;4 _2 `" o, H* g3 N( U7 `; U
- //2 L; |& |' }3 O/ A3 x
- //& C9 J8 w" J( l$ R5 e
- $wp = new WP();
8 R: G" F4 _3 K - $wp->main();# X( O# M: ^' ]0 y- e0 _, b( D0 L: w3 K
- //
" C- s9 l$ x1 a( y% l - $my_post = array();
3 Z: C9 W5 U4 f& m8 A7 d3 q1 B6 h6 w$ U - $my_post['post_title'] = $title;
6 U" \9 w: h8 d - $my_post['post_content'] = $content;
- s( Y6 E7 w% Y b4 T8 b: n/ r8 F - $my_post['post_status'] = 'publish';
H% P1 r" L$ r {: h - $my_post['post_author'] = 1;% ~6 z5 g; G4 u1 N5 v! o7 R
- $my_post['post_category'] = array($cate);
0 ~# i- V, F; Z% | - $my_post['tags_input'] = $tags;$ B) j6 J/ F T1 E9 b7 s; S
- //$my_post['tags_input'] = array('tag1', 'tag2');
+ s# S2 v4 p/ S* Z - //$my_post['post_status'] = 'future';. r+ S' ^' M) @ z/ A
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 N# ]: v; n7 M8 p* a) ~- }: \" e
- " }) l, i/ @( L x1 \, g% j
- // Insert the post into the database
. E" |! V' C, }) K$ R$ N - $ret = wp_insert_post( $my_post );, k T. y6 Q8 f# X: E. n0 G8 |
- echo $ret;
' t9 O' z( f r - ?>' V+ f$ R7 E% ]! k/ w! v
复制代码 我自己写的
: t4 `# [# w/ G4 j4 j4 `# |插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|