|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 5 R, O3 D3 R3 i1 u1 [
h" N1 G5 s: C0 \) e. H# p直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% L* t5 E; _+ M! h3 @/ l7 @# S
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了 ?$ a! U' g$ A e' B) v9 J
5 T+ G4 h- x4 v& |/ v% g7 ]) V: n方便实用 简单 何乐而不用呢- + B s+ k& R# {
- <?php" H8 Y; l/ T9 o. T4 d4 S) y
- 0 \( e6 D/ }( R$ `" A: |
- define( 'ABSPATH', dirname(__FILE__) . '/' );
) E z! J1 M' k8 L$ m& v# l - require_once( ABSPATH . 'wp-config.php' );4 P" }1 w; ? t! O* c0 _
- require_once( ABSPATH . 'wp-settings.php' );" [ E o$ [ |2 d8 w, B- \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 C+ L% p7 ~9 k J - require_once( ABSPATH . 'wp-includes/functions.php' );
" Q" k# e/ `$ h - require_once( ABSPATH . 'wp-includes/plugin.php' );- y- q8 p8 c" X: W
- $title = $_POST["title"];2 i2 ]- D A8 y4 W. q
- $content = $_POST["content"];
8 |% z7 w7 W8 ` - $tags = explode("_",$_POST["tags"]);
H, i) g+ H! L& W9 e% Z- l - $cate = $_POST["cate"];
/ e' W( s! |2 b0 g. S3 N - //print_r $tags;
7 {- P! s( z$ F6 o' P2 u! z' K - //. s2 O+ {( a' t2 m1 J! R: q
- //0 T, U9 J! B6 A w
- $wp = new WP();
; }0 z9 `6 I, w - $wp->main();8 j% t$ n! z) r' F
- //3 | B6 a4 z- U2 @2 t$ _9 l+ q
- $my_post = array();7 l, i/ f8 ?. D) q" V! {
- $my_post['post_title'] = $title;
4 \/ d$ u3 j6 n6 ?+ ? - $my_post['post_content'] = $content;
1 p3 ^: v9 W+ L( L9 i - $my_post['post_status'] = 'publish';
0 f9 S. h5 V% U - $my_post['post_author'] = 1;
$ W. ]3 D: x7 R) c6 p - $my_post['post_category'] = array($cate);3 J' y8 O% t3 L7 K% k5 c5 K/ q
- $my_post['tags_input'] = $tags;
; v# `7 \5 v" G, L6 r5 I* t# l - //$my_post['tags_input'] = array('tag1', 'tag2');
: l8 O* c1 t+ H- p8 w4 C - //$my_post['post_status'] = 'future';4 I+ q2 M7 W; _9 b: i/ v0 ^
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# Y8 V. M( M* T' C/ k1 {) R
9 t" o; B+ K4 J% A- // Insert the post into the database6 [: W8 ?5 ~( c4 f
- $ret = wp_insert_post( $my_post );
" r8 p- u( B9 M+ k1 O F S - echo $ret;
: _0 E: L5 _1 _; F: { - ?>
) f+ b6 Q/ p1 L2 ?, [1 {" K
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- # }& R R( J: V# Z
- <?php
5 O9 K: v& e! m8 _' s. n" q - define( 'ABSPATH', dirname(__FILE__) . '/' );
$ V C; P, _; y; l' W0 z- D @$ u$ K - require_once( ABSPATH . 'wp-config.php' );
5 Y/ }) V- P6 i' u2 R! T- f$ M - require_once( ABSPATH . 'wp-settings.php' );% s' z J7 Q! f5 F3 y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
. H+ R; ], z1 {& P$ e V5 ~ - require_once( ABSPATH . 'wp-includes/functions.php' );
8 `' `% S4 x7 S, Q+ G- z - require_once( ABSPATH . 'wp-includes/plugin.php' );
0 n$ a- P" j* D2 b* ~ - $pic_name = $_POST["pic_name"];
9 T, n: F% }. Y4 G# o% `9 B - $pic = $_POST["pic"];/ _# J( |3 A3 H i) K9 k
- if($pic != "" && $pic_name != "")
5 [3 w' g8 ]; A% [1 X( Q3 B - {
5 U1 I, ^1 R. ^/ f/ Y - $path = "images/";
3 N! W, G6 Z& P* V/ U5 ^% Y - $pic_name = $path.$pic_name;% z2 ~$ j0 _- z( Z3 L# Y
- echo $pic_name;2 C2 \0 ]) `3 i2 M+ f9 l8 z" r
- echo "||";& \2 ]5 H* v- B6 c4 E9 p& S
- error_reporting(0);
6 W. C. q! D! N - mkdir("images");; w6 m% T2 J" c) x: P, S! |$ ?; t
- $handle = fopen($pic_name, 'w');+ f+ A" ^1 B1 [3 @$ C+ @" j
- echo fwrite($handle,file_get_contents($pic));3 G. S z/ l5 M3 v5 }: c$ i/ q6 L5 A! {# ~
- }. F: b# O. G B' `
2 v7 y* \. u% p, Z; X( z" q- $title = $_POST["title"];, J+ z4 ~' V3 ?% |
- $content = $_POST["content"];
4 N* ~6 {. V- `- W1 A6 x2 u8 } - $tags = explode("_",$_POST["tags"]);
! @6 Y2 Y- C0 |1 \; G1 L - $cate = $_POST["cate"];8 L! ~+ k! T0 i, m
- //print_r $tags;
6 u7 ~. L( U( s" L( b3 v: Z - //
q- Z, T [6 O' b! g! d! b - //
8 F( n, ^! Z7 g6 A - $wp = new WP();
* t. I" N; ~" K+ Y$ [8 _$ A( I - $wp->main();1 U f" n- g# `! B
- //
, g/ t6 x9 x# _# v0 e - $my_post = array();" y( D4 j0 S5 G: E. o1 g1 r' J0 ]
- $my_post['post_title'] = $title;
! X' {# N# u ?0 W& [5 G+ v - $my_post['post_content'] = $content;
# C/ K0 T& y1 Q- ]# O5 ~ - $my_post['post_status'] = 'publish';
" \8 ?6 n/ y( [. X5 e% f/ |( R - $my_post['post_author'] = 1; Z& C' @% ]5 p/ G/ a2 H' t2 e7 q
- $my_post['post_category'] = array($cate);
8 I- r r D& q3 t' }" z - $my_post['tags_input'] = $tags;$ e1 G* Z( t* X% J
- //$my_post['tags_input'] = array('tag1', 'tag2');% y V0 V2 r9 m
- //$my_post['post_status'] = 'future';
+ ~$ C9 Y, Z4 L* K8 J: w - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, G+ h+ F2 e( u& l7 w
3 G& z. y7 `: q8 x- // Insert the post into the database
: `/ u6 y# f ~9 o) u$ Q - $ret = wp_insert_post( $my_post );
- y" e* H* U4 S- n - echo $ret;
+ r4 P2 j; j! x4 X - ?>% V2 t: c. ^ _& Y1 {& m% a
复制代码 我自己写的
1 d; V7 {# p8 _& C2 j2 {插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|