找回密码
 立即注册

QQ登录

只需一步,快速开始

PropellerAds
Google-Bing-Mediago-Criteo开户
⚡️按条S5代理⚡️静态⚡️独享⚡️5G广告专用虚拟卡/U充值/高返点皇家代理IP⚡️#1性价比⚡️
Mediabuy⚡️玩家开户首选【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️
Taboola/Outbrain /Bing⚡️一级代理开户投流-7*24h❤️人工在线【官方】❤️搜索套利买量投流开户独立站⚡️开户投放
Google FB TK游戏代投⚡️E.PN 虚拟卡⚡️BINOM TRACKER 60% OFF!比Adplexity还好用的Spy工具
ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款全球虚拟卡, 支持U充值
Facebook 批量上广告尤里改 - FB 稳定投放免费黑五教程(持续更新、欢迎交流)FB 三不限源头 - 自助下户充值转款
各种主页、账单户、BM户(优势)IPCola原生住宅IP⚡️$1.8/条双ISPFB资源,账单户,分享户,国内一手TK加白户/二解户/FB海外户/GG老户
最大欧洲Nutra网盟BA找量 FB高权重耐操个号⚡️稳定过审GG,FB,TK, 欧美源头, 欢迎合作❤️FB企业户海外户,授信户,TK加白户
联盟收款/海外资金下发/服贸结汇⚡️Spend.net — 美元卡仅需$0⚡️✔Taboola海外户广告位出租
虚拟卡返佣1%,国内持牌机构   
查看: 8253|回复: 3

[原创教程] wordpress 调用函数更新文章 多站管理 Post操作就可以了

[复制链接]

14

主题

39

广告币

219

积分

初级会员

积分
219

社区QQ达人

发表于 2013-2-25 14:36:05 | 显示全部楼层 |阅读模式
本帖最后由 finder 于 2014-12-28 15:13 编辑 ' _, L3 j2 Q  s+ |& O$ n; g

3 d( T5 P& k3 b+ g. M直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持! N3 m$ O0 Y- n" f% a

' b% I/ t9 K3 g& k我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章  如果你采集的文章直接使用一个post操作就可以了" ]; d/ @; G/ `- P& ~8 l. D
% o: J0 y; J" e' `6 I/ X
方便实用 简单 何乐而不用呢
  1. 5 p$ u5 O6 `% D- A/ |! Y
  2. <?php- t6 K2 k6 q/ M
  3. . y& Z0 u$ }/ x/ ~1 g" R1 G0 B/ u- t; x
  4. define( 'ABSPATH', dirname(__FILE__) . '/' );
    + j# e; |8 e1 o/ G9 w7 t
  5. require_once( ABSPATH . 'wp-config.php' );
    $ u* U- x* p# o
  6. require_once( ABSPATH . 'wp-settings.php' );
    . n8 E% M2 s+ n' @
  7. require_once( ABSPATH . 'wp-includes/class-wp.php' );5 |, a/ ?9 l( S' [
  8. require_once( ABSPATH . 'wp-includes/functions.php' );
    3 F9 i4 u' f6 o/ y
  9. require_once( ABSPATH . 'wp-includes/plugin.php' );8 w" Z1 Y" T% t6 K9 A
  10. $title = $_POST["title"];% y& J) R$ A7 U; y
  11. $content = $_POST["content"];; P" O4 l. c4 @) g' G2 E0 B
  12. $tags = explode("_",$_POST["tags"]);2 W# I8 }- w! k
  13. $cate = $_POST["cate"];
    ' g) i. t2 X5 ~- z0 u
  14. //print_r $tags;
    7 @# F' p. F! q: Z4 x2 j. I% j
  15. //' I/ j2 s" w% e8 Y! \6 E1 e7 }
  16. //( Z' ~0 E" u* B& {8 c. S% g
  17. $wp = new WP();
    & c/ M: L7 \& h5 m4 ^& f
  18. $wp->main();) V) }( I! L% x
  19. //( g8 F9 T! o: [; G. `' p
  20. $my_post = array();
    ) s# e4 K3 T4 @3 U% @
  21. $my_post['post_title'] = $title;/ ~: g& \$ G* w! ^& y- L, U
  22. $my_post['post_content'] = $content;
    ! R6 L* J' {* a% _
  23. $my_post['post_status'] = 'publish';
    & G" ^" p% `6 N% F7 E1 r% @( P
  24. $my_post['post_author'] = 1;
    3 H1 D* `. G% O5 I; g( ~/ \% Z
  25. $my_post['post_category'] = array($cate);
    ( J2 R( t  K. X
  26. $my_post['tags_input'] = $tags;
      X- N. V. U) l" g
  27. //$my_post['tags_input'] = array('tag1', 'tag2');
    6 e' q0 p1 k- i5 k$ X, V6 d4 ~
  28. //$my_post['post_status'] = 'future';- n$ U8 O/ j0 z
  29. ////$my_post['post_date'] = '2010-07-04 16:20:03';. R0 k: q: S' L$ G8 q( t, T7 }  B2 P

  30. 8 c. E/ I; M+ n8 M$ ~% ?0 y
  31. // Insert the post into the database3 l# h. }6 K  W. p$ I
  32. $ret = wp_insert_post( $my_post );0 T) e- w5 L; W+ r: x
  33. echo $ret;. x$ f0 b) h. h( @% A7 b( o! s
  34. ?>" _, w, x4 Q( [( [
复制代码
下面是更带更新图片版因为有些网站屏蔽了盗链接 小气

  1. 9 H$ b: H. l1 Q4 O. E
  2. <?php
    5 \- a! g0 V3 {% q3 N8 X
  3. define( 'ABSPATH', dirname(__FILE__) . '/' );
    6 H0 @, u' A4 B
  4. require_once( ABSPATH . 'wp-config.php' );
    / R% ^8 `0 [9 U7 C/ V
  5. require_once( ABSPATH . 'wp-settings.php' );
    : Z; R" g$ u2 [& K9 G
  6. require_once( ABSPATH . 'wp-includes/class-wp.php' );- u7 j+ _- [  p* [4 H  w6 j% D
  7. require_once( ABSPATH . 'wp-includes/functions.php' );
    5 S7 c3 Y- d/ i5 C4 W" l. |
  8. require_once( ABSPATH . 'wp-includes/plugin.php' );0 g& N- M( x8 t! C2 v7 w
  9. $pic_name = $_POST["pic_name"];. [1 r& c9 B$ R& [1 i
  10. $pic = $_POST["pic"];$ |8 T% `8 _: \7 ~+ F. g$ }
  11. if($pic != "" && $pic_name != "")( m7 }  s3 @( \0 l- i( @
  12. {
      h* D7 Z/ M: V# ]0 d5 K
  13. $path = "images/";
    8 B0 [% s7 `5 H  U8 |
  14. $pic_name = $path.$pic_name;( U2 l9 S! b. R5 f* `+ N
  15. echo $pic_name;5 }% p4 Z& a8 z. g1 A
  16. echo "||";
    1 T0 o( T1 b# N
  17. error_reporting(0);0 |0 y% b& n4 i
  18. mkdir("images");
    5 @3 _. l) X; M6 J  }
  19. $handle = fopen($pic_name, 'w');
    , i6 t/ O+ \# S+ b$ p: C
  20. echo fwrite($handle,file_get_contents($pic));
    / p2 q: k* X9 @" u/ m" a/ L& Y+ K
  21. }" r/ m: y, f2 N
  22. 6 q* J3 k; l, F
  23. $title = $_POST["title"];
    7 N/ `7 U; U! M
  24. $content = $_POST["content"];
    4 Z8 K: Y  S& z" Y  d
  25. $tags = explode("_",$_POST["tags"]);
    0 {: z, s) g* {5 b8 m
  26. $cate = $_POST["cate"];
    , c! K9 S2 H( ]; m- Y( n
  27. //print_r $tags;
    ; S; e4 s/ c! s6 T1 P
  28. //$ U: T) ~) f$ V7 ~
  29. //
    2 h8 `1 \8 T9 `
  30. $wp = new WP();; h/ a2 {: s& v3 B; P# c9 h
  31. $wp->main();6 A5 Z7 O! C) T
  32. //9 Y- Y7 [: R" i+ i. `( |7 T
  33. $my_post = array();
    $ J" J, d! z& t  r: m  K0 m9 R
  34. $my_post['post_title'] = $title;
    " h, R  o4 M6 a6 w' L# c
  35. $my_post['post_content'] = $content;
    3 M! }% A# \4 C+ D8 U. {5 m% ?  h
  36. $my_post['post_status'] = 'publish';9 ?, T8 h9 ^" J: S7 L0 H
  37. $my_post['post_author'] = 1;# z4 J5 _9 o" h# w
  38. $my_post['post_category'] = array($cate);
      A0 t) g. O/ E8 d
  39. $my_post['tags_input'] = $tags;: C8 b9 ?' j7 T! R- b
  40. //$my_post['tags_input'] = array('tag1', 'tag2');
    4 u1 n" f3 J, l: U1 Z
  41. //$my_post['post_status'] = 'future';
    " `: N8 ^! Y" W( p; Q) P
  42. ////$my_post['post_date'] = '2010-07-04 16:20:03';
    + c7 z! r0 [, q' c3 R

  43. # ~$ _$ ]4 I0 t' _. I& `
  44. // Insert the post into the database. ], i3 B+ X" n
  45. $ret = wp_insert_post( $my_post );
    $ M. }/ ]2 K9 T* F( @% y
  46. echo $ret;( B6 {  i  E+ H3 H+ r0 f
  47. ?>8 U" w6 O  t7 ^
复制代码
我自己写的- A8 f  f* @$ I. _" j
插入效果看图 不看广告看效果 已经测试过有需要的 拿去

评分

参与人数 4广告币 +6 收起 理由
helloworld + 1 赞一个!
mj23zyb + 2 经验不错!
suyu8776 + 2 很给力!刚想自己写一个呢
左庶长 + 1 很给力!期待更多分享:)

查看全部评分

相关帖子
回复

使用道具 举报

54

主题

9

广告币

6010

积分

禁止访问

积分
6010
发表于 2013-2-25 19:12:29 | 显示全部楼层
火车头的wp免登陆接口就是利用wp_insert_post,用哈默的接口相对强大些
回复 支持 反对

使用道具 举报

21

主题

679

广告币

894

积分

中级会员

积分
894

社区QQ达人

发表于 2013-2-25 20:33:59 | 显示全部楼层
用xmlrpc不是更好吗
回复 支持 反对

使用道具 举报

15

主题

598

广告币

565

积分

中级会员

积分
565
发表于 2015-3-3 14:05:49 | 显示全部楼层
楼主辛苦了!~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们|联系我们|DMCA|广告服务|小黑屋|手机版|Archiver|Github|网站地图|AdvertCN

GMT+8, 2026-8-20 00:46 , Processed in 0.084678 second(s), 23 queries , Gzip On.

Copyright © 2001-2026, AdvertCN

Proudly Operating in Hong Kong.

快速回复 返回顶部 返回列表