|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 1 U; z" h9 C. `& H/ ] Q2 S
* q% x; }1 F0 g3 z
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持9 _8 G4 B) Z9 K ?+ G& O& h
5 P8 h- M R* I
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
0 Y7 ?2 R2 H* w- ~5 Q& C5 R4 w4 j2 i, o+ {2 [
方便实用 简单 何乐而不用呢
5 E6 `: n' P6 P/ d- <?php
7 F! E0 R" Z6 \, b% _
, f# U% Z) \* e$ B y- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 I% r0 w: C5 [) U - require_once( ABSPATH . 'wp-config.php' );
) Y2 D4 v: n1 a( B9 e; z3 M - require_once( ABSPATH . 'wp-settings.php' );; }9 Z$ F* I6 l! H
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 V9 u1 S @' l @1 e - require_once( ABSPATH . 'wp-includes/functions.php' );8 y6 Y4 _9 S( T5 t1 K) k; c! _+ d
- require_once( ABSPATH . 'wp-includes/plugin.php' );
1 o& D( Q0 Z- t; a1 j - $title = $_POST["title"];
& D z, c; ^( B2 ^" C - $content = $_POST["content"];& C; [8 A0 Z6 d; a: e. M# N
- $tags = explode("_",$_POST["tags"]);
3 x0 h6 V' b+ D - $cate = $_POST["cate"];6 U8 G& o6 [1 ]% A1 i( {
- //print_r $tags;
' G' G: f. O1 ?) }( y: R - //0 S& T/ ?- X4 x8 ]( a9 J
- //7 n3 T/ v9 }7 O, B
- $wp = new WP();0 S& B7 l4 y) T0 X( p9 G) v
- $wp->main();& |7 g) q1 C- H) {2 g* P3 z2 `
- //
# y9 k+ ~1 p$ T/ S - $my_post = array();
3 C3 ?+ @# l$ j8 g$ Z - $my_post['post_title'] = $title;
2 x; J2 o+ p& }* A5 ^ b/ m4 ^ - $my_post['post_content'] = $content;/ G2 ~+ z% C; F F4 e
- $my_post['post_status'] = 'publish';
! l% a, E9 C _! f7 ]( l* S - $my_post['post_author'] = 1;- |! }2 {" B7 |# @
- $my_post['post_category'] = array($cate);
9 m# K7 u# q. p, L* m6 v" C - $my_post['tags_input'] = $tags;
4 I2 |* n& N9 m - //$my_post['tags_input'] = array('tag1', 'tag2');; g" i- n. D: Z$ q: I- l( _
- //$my_post['post_status'] = 'future';
7 S7 ?, T' K% F% F" ^3 D; u - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ L- E6 r6 F+ @( c- `6 r. h
- # D+ x; |: x1 |( v
- // Insert the post into the database
$ J Y, T$ q7 D" E! ?8 V+ y" l - $ret = wp_insert_post( $my_post );' z/ I: t ?" F0 M
- echo $ret;, u+ C3 j, J* h
- ?>
% Z1 H8 E' [2 b1 i3 j9 W- T
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
: x+ V3 ?/ s; F+ b7 t- <?php
8 C3 J- @# O4 Q6 @( E2 w3 B - define( 'ABSPATH', dirname(__FILE__) . '/' );% O, E* k& d: S4 o3 [% a
- require_once( ABSPATH . 'wp-config.php' );0 |# t. ]4 y% a# e0 z9 Z4 Z$ b1 ?
- require_once( ABSPATH . 'wp-settings.php' );6 D L1 e. a+ {3 p, }0 f" m
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 r7 y) T) Z3 w4 X
- require_once( ABSPATH . 'wp-includes/functions.php' );
+ G6 {" q) E5 b% s - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 c# w* d8 m, G. D3 E; n - $pic_name = $_POST["pic_name"];
( _0 z- h: Q# p5 ~1 i5 L6 G' W' o - $pic = $_POST["pic"];& J" d% \7 x# i$ p/ H7 B% g
- if($pic != "" && $pic_name != "")8 E4 i) E, q, `9 l
- {
! D1 K" @1 U/ _, o) X( F8 Q - $path = "images/";
% E x8 M! `) ^& s% G( L' q a - $pic_name = $path.$pic_name;
+ F* \$ q9 v: G) V* ]& x - echo $pic_name;
+ A1 r; d* [+ h3 Y( x$ C - echo "||";
1 D' s# L( Y+ J3 N6 ~ - error_reporting(0);1 B( p6 y' I% d0 |
- mkdir("images");
* ?, u0 e; `6 t8 s - $handle = fopen($pic_name, 'w');
8 `: D4 P$ u a0 i h: I/ H3 O - echo fwrite($handle,file_get_contents($pic));
: V% k$ n9 F% C$ }# Z( {7 H - }+ q1 u6 e! C4 y0 N
- ) g& \$ i$ Z: G$ `4 m- P/ u* p2 }, w/ M
- $title = $_POST["title"];( J6 N7 i5 I% e7 P3 Q& E' A
- $content = $_POST["content"];% O3 W b9 O7 r) U3 R# a
- $tags = explode("_",$_POST["tags"]);
: z |' r$ W5 n) J0 H1 } - $cate = $_POST["cate"];
, Z% Y# C! L- d1 p( D - //print_r $tags;
. s, _* B v& `5 _ - //( a+ V$ E2 L( E, Y" [8 {2 g7 s
- //
6 b1 ]7 E G8 `" ]0 I3 { - $wp = new WP();! D& v* L0 m; t7 v2 J6 h
- $wp->main();
' @. p' L5 a" {6 V - //
/ M. H& y I& M* v Y6 h+ h - $my_post = array();
8 e Y; c6 R4 V0 B - $my_post['post_title'] = $title;: d. ^/ Y- D& ^6 A. b3 E; o
- $my_post['post_content'] = $content;& |' U- H# j5 I) h
- $my_post['post_status'] = 'publish'; W) \* ?" `. V3 [
- $my_post['post_author'] = 1;9 Q; Y3 ~9 q% R1 i8 A) ?7 s
- $my_post['post_category'] = array($cate);1 i Q1 m# \+ j) R; z$ J
- $my_post['tags_input'] = $tags;6 \" D) s' H7 \/ e1 w
- //$my_post['tags_input'] = array('tag1', 'tag2');& G5 F/ V4 ? _; M: b4 K6 `* t
- //$my_post['post_status'] = 'future';
9 ]. h% v. a9 Q' P* F, y7 g5 k) {' a - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ j% p; n: @# A# y/ y# o z p
! d6 Z- e* I7 _" c8 R- // Insert the post into the database
: ]4 r: x6 j1 F: X - $ret = wp_insert_post( $my_post );- u& z7 R6 h' I- b9 Y# l
- echo $ret;
$ J' O1 o3 H2 D8 N/ J% Q$ o/ o - ?> X5 I1 `( Z1 y3 ^; a% g
复制代码 我自己写的
! w$ K; i( w+ D6 W9 g$ x# K插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|