52AV璈A|52AV.ONE

 曉撖蝣
 蝡唾酉
敹急瑕
  • av隢憯BBS
  • 璈A
  • 芣瑟憭瘚
  • 鞎澆
  • 52av鋆貉摰
  • 銝剜-銝剖銝餅
     
亦: 4192|敺: 0
銝銝銝駁 銝銝銝駁

[wordpress] WordPress芸蝢拍凋誨蝣嘯hortcode隞亙Y蝺刻摩函凋誨蝣潭[4撘萄]

[銴鋆賡包
頝唾唳摰璅撅
璅銝
潸” 2016-6-9 12:40:16 | 芰閰脖 |芰憭批 撣 |摨閬 |梯璅∪
WordPress芸蝢拍凋誨蝣嘯hortcode隞亙Y蝺刻摩函凋誨蝣潭(shortcode button)
0 M' D; F9 B3 `. g
, ]3 M& t  l2 X- c6 o" B/ Hwordpress Shortcode逕ordpress凋誨蝣澆賣臬肓ordpress 2.5祇憪鋡怠伐冽琿wordpress凋誨蝣澆臭誑撣豢嫣噶敹恍啣函楊頛舀蝡Y亙摰對凋誨蝣潛撣貉冽交唳蝡亙誨仿單閬閮乩頛桃Blog隢思犖嗡wordpress璅⊥踵嚗wordpress Shortcode撖衣曆pageW乩撟餌舐
( {( M! q; W! l! w9 Z$ Z
隞乩 wordpress 凋誨蝣潛閰喟隞蝝孵脤具
+ q4 O" f' W; Z" {+ m( X) E2 V  y+ F9 @, y6 \; R8 O
凋誨蝣潛 wordpress 雿輻券撣貊陛柴 靘憒唾憿舐內箸摰餈蝡 , 臭誑雿輻函蝔撘蝣潮隡潭潔 :* j" a4 d: k$ ^; w, ^" b9 E
  1. [recent-posts]
銴鋆賭誨蝣
甇文 , 臭誑閮剖銝訾批嗆蝡賊 :

/ D) |: Z# M% B
  1. [recent-posts posts="5"]
銴鋆賭誨蝣
甇文 , 銋臭誑箸蝡銵冽啣銝璅憿 :
, l: }) `1 T' i0 k
  1. [recent-posts posts="5"]Posts Heading[/recent-posts]
銴鋆賭誨蝣
4 |5 U/ _6 o/ |: w$ v

( f" r4 o$ w. \1. 蝪∪桃凋誨蝣

! T# W2 J; t' [' `4 F/ ?祆摮貊蝚砌典 , 撱箇銝凋誨蝣潛蝔撘蝣 :! B9 ]4 {. l  h  G; r/ [& `& x8 L
  1. [recent-posts]
銴鋆賭誨蝣
閰脩摨撱箇舫撣貊陛桐蒂銝銝閬撣賊脤 PHP 亥 撱箇蝔憒銝 :

5 `; s1 Q7 ^: I& M: b/ ~6 V
  • 撱箇銝賣 , wordpress潛曄凋誨蝣潭澆急迨賣 ;
  • 梯身蝵桐臭蝔曹閮餃凋誨蝣 ;
  • 閮餃賣賊蝯針ordpressaction銝7 ^* }0 \* M: P) L1 |

3 ?) X2 Z5 {) S: r, u# v/ B3 s6 p2 s
祆摮豢蝔撘蝣澆湔交曉逆unction.php(批嗅==>憭閫==>銝駁蝺刻摩==>function.php) ,銋臭誑曉其鋡怠怠狄unction.php桃函php瑼獢銝准
  M) t) y7 r6 [' c6 a9 B/ b, U2 i) ^
1.1 撱箇餈賣
0 G( \3 v. |# o( A& o/ i1 U$ a嗥潛曄凋誨蝣潛嚗摰鋡思蝔曹餈賣貊銝畾萎誨蝣潭隞選隞交撱箇銝賣賂敺鞈摨思葉脣啁蝡8 y1 }% S2 k# m, W& V/ O
  1. function recent_posts_function() {
    2 w& o& b; i/ f3 x6 z! i% k
  2.         query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => 1));: i- u+ m; s) _6 a' h
  3.         if (have_posts()) :
    ' Q7 l% U+ X& E7 B! [; @: p. ~
  4.                 while (have_posts()) : the_post();
    ! P# A! a' u: g
  5.                         $return_string = '<a href="'.get_permalink().'">'.get_the_title().'</a>';" ]: V; _7 u8 p5 J3 I% o; r
  6.                 endwhile;
    * y2 k& K& r. n6 z
  7.         endif;) R" T. k. F5 R' f9 A% C2 ^8 C
  8.         wp_reset_query();
    # `' {; z" o, G0 w
  9.         return $return_string;% b# X, H' A# [
  10. }
銴鋆賭誨蝣
憒銝蝷綽亥岷鞈摨恬脣啁蝡嚗銝西銝撣嗆亦摮銝脯澆閮餅荔餈賣訾蒂銝唬遙雿批捆嚗航銝摮銝脯

: S3 C, `' {0 W( l- s$ l2 |. Y3 e4 F

/ {. x, v- i: G# q4 F$ Y7 M1 B, X; ]1.2 閮餃凋誨蝣
6 H" q0 S! R. N1 L曉剁閮幃ordpress賣豢臭凋誨蝣潘
  1. function register_shortcodes(){
    : u& ?7 l3 o: e% k' x6 R
  2.         add_shortcode('recent-posts', 'recent_posts_function');. I0 r+ E& U$ j! K* k- L1 x' O
  3. }
銴鋆賭誨蝣
嗅冽蝡批捆銝凋蝙函凋誨蝣
# i4 [$ F# e  d% z" h9 c* C* f
  1. [recent-posts]
銴鋆賭誨蝣
撠芸澆 recent_posts_function() 賣賂閬蝣箔凋誨蝣潛摮臬臭嚗隞仿踹銴

& B/ V; `4 l5 k/ m( i! K( G- b  \& c" ^, D

) B, Y% s6 ]1 c6 \" a1.3 Hook into WordPress
+ k8 u1 u) b* k0 C: M% S- q
* m2 m& l" W. n箔賢瑁 recent_posts_function() 賣賂閬摰蝬摰 WordPress 憪文銝准0 v. B- s# F: ?
  1. add_action( 'init', 'register_shortcodes');
銴鋆賭誨蝣
1 a- N5 D1 |7 a) X- b
1.4 皜祈岫凋誨蝣
" x7 K$ r5 `$ G# s" n
蝪∪桃凋誨蝣澆歇閮剖 , 曉券閬皜祈岫臬西賣迤撣詨瑁 臭誑撱箇唳蝡 ( 暹 ) , 撠銝隞蝣澆唳蝡批捆雿蝵 :
  1. [recent-posts]
銴鋆賭誨蝣
2. 脤凋誨蝣
2.1 凋誨蝣澆
凋誨蝣潭舫撣豢敶 , 箏霈亙詨航摰游賬 閮剜敹閬憿舐內銝孵賊啁蝡 箔圈桃 , 閬蝯衣凋誨蝣潭摰嗡賊隞仿*蝷箸餈蝡詻
閬雿輻典拙賣 ,蝚砌臬批遣 wordpress shortcode _ atts ( ) 賢 , 摰冽嗥凋誨蝣澆惇扯砍啣惇抒其韏 , 銝血‵亙唳唾雿蝵柴 蝚砌 PHPextract() 賣 , 憿批蝢 , 摰箇凋誨蝣潔葉撅祆扼
撅餈 , 啣銝 $atts, 摰臭,敺銝剖臭誑唳閬蝡詻 亥岷鞈摨思敺摰貊桃蝡 , 銝血喳銝銵 :
  1. function recent_posts_function($atts){
    4 h5 |3 e, y, O7 Y1 r7 {
  2.         extract(shortcode_atts(array(
    ) P- c4 \% R7 y+ ^
  3.                 'posts' => 1,
    , o8 }& B, u& o3 b( K- N3 N" X4 m
  4.         ), $atts));
    ) s! c2 u. a" |! `$ _9 S6 ?9 K

  5. 1 n3 a" r1 g0 t/ w
  6.         $return_string = '<ul>';
    . S/ }$ L6 R+ v* O0 Q1 F  M+ c' V# A
  7.         query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
    4 a. S2 H9 ^  O
  8.         if (have_posts()) :1 ]; c$ h8 Y, m  \/ R+ u3 I
  9.                 while (have_posts()) : the_post();7 I: o8 F3 B" Y3 m, M
  10.                         $return_string .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';/ r; ?/ d) x3 D4 {1 @  L$ J
  11.                 endwhile;
    8 i8 {6 c, U( D: x& U
  12.         endif;1 v- o% H6 B/ S
  13.         $return_string .= '</ul>';
    & u- y; p8 x5 l! n3 v9 G
  14. ) Q# w# d1 ^# x2 t1 \" J. q5 Y4 X
  15.         wp_reset_query();
    + s% o! ~+ f4 S* D" O0 h) Y( Y1 U
  16.         return $return_string;+ Y' g# E* t# R8 R
  17. }
銴鋆賭誨蝣
憒雿輻刻芣摰甇日賊 , 1 撠舫閮剖潦 臭誑亙撅祆找蝙凋誨蝣潭亙游詻 雿輻券撘瑕賣 , 撠勗臭誑摰隤輻冽唳蝡賊 :
  1. [recent-posts posts="5"]
銴鋆賭誨蝣
園*蝷箸潛閬賢 , 典停臭誑唳餈鈭蝭蝡銵
$ @- |1 u  R! J* k$ U; ?
2.2 凋誨蝣潔葉憓摰
臭誑蝜潛游凋誨蝣潦啣銝鈭批捆雿箏 靘喲, 靘憒"唳蝡銵函璅憿" 亥甇斤桃 , 閬刻賣訾葉啣蝚砌$content , 銝行摰憿舐內典銵典Y銝 <h3> 璅蝪賭葉啁賣詨銝嚗
  1. function recent_posts_function($atts, $content = null) {
    ( ^% F& Z& q/ i& O" j+ a5 a& N" F
  2.         extract(shortcode_atts(array(
    8 G, c+ d0 f, \- E/ n
  3.                 'posts' => 1,+ r4 ?( C& p  d
  4.         ), $atts));
    ) r6 Y# X$ z; E5 F( P

  5. ) E+ O2 m: Q' w, W7 V
  6.         $return_string = '<h3>'.$content.'</h3>';! M* y6 p- f2 p6 P- y3 _' A9 b
  7.         $return_string .= '<ul>';
    ( C+ L1 Z4 R  }! D* g& F4 G7 ?! h
  8.         query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
    $ X8 m! b+ |6 H1 L
  9.         if (have_posts()) :- ?# K" ]* `& B# K" {
  10.                 while (have_posts()) : the_post();
    0 k) B6 P' m' I0 Y9 q7 w: E
  11.                         $return_string .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    ; |0 `! R* f$ n/ c. k
  12.                 endwhile;
    . Y0 z1 I/ h' l+ K, V
  13.         endif;1 s1 r- i1 O$ h9 F
  14.         $return_string .= '</ul>';7 b& c# e3 R" G8 a
  15. 5 D6 h. E" _6 g0 F
  16.         wp_reset_query();
    ) v& y6 M( f8 n  y
  17.         return $return_string;& O" b1 E. k- ?
  18. }
銴鋆賭誨蝣
蝔桃凋誨蝣潮隡潭潔HTML璅蝪踝
  1. [recent-posts posts="5"]This is the list heading[/recent-posts]
銴鋆賭誨蝣
支蝡銵典鈭銝璅憿嚗園批捆銝銝蝷箔臭璅嚗
1 o1 p* x# @0 L- G8 H  A$ X7 O3 P% z
3. 其遙雿唳寥*蝷箇凋誨蝣
3.1 典湧撠撌亙瑚葉雿輻函凋誨蝣
閮剜瘜銝 , 湧甈撠撌亙瑟臬蕭亦凋誨蝣潛典臭誑撠甇斤撘蝣潭曉典撌亙
6 T, ~( d, c2 r1 |) D
臭誑∠其銵蝔撘蝣潔券賣 , 箔雿踹湧甈撠撌亙瑟舀渡凋誨蝣 , 啣隞乩蝔撘蝣 :
  1. add_filter('widget_text', 'do_shortcode');
銴鋆賭誨蝣
曉其閬靽格嫣遙雿嗡唳
, 瑟, 湧甈撠甇蝣箏圈*蝷

# s; C4 Z2 _" q1 O) V
璅嚗刻隢銝剖函凋誨蝣潘
  1. add_filter( 'comment_text', 'do_shortcode' );
銴鋆賭誨蝣
冽閬銝剖函凋誨蝣潘
  1. add_filter( 'the_excerpt', 'do_shortcode');
銴鋆賭誨蝣
4. TinyMCE蝺刻摩典凋誨蝣潭" R6 f2 T% Y( N2 ~. _

4 K& e" ^# V# u! u嗥凋誨蝣澆臭誑嫣噶箸蝡憓批捆嚗雿舫撠潭桅冽嗡隤芸航賡舀暺銴嚗撠文嗆舐嗅豢頛憭憭批貊冽嗅潮HTML隞蝣潔蒂銝嚗嗉閬雿輻函凋誨蝣潘隞敹閮雿琿隤瘜賂箏喃蝙臭撠撠隤瘜航炊嚗賢航賢湔喃啁蝯
閬閫瘙粹嚗臭誑蝯 TinyMCE蝺刻摩典銝嚗雿輻冽嗅臭誑蝪∪桃暺靘憓凋誨蝣潦撱箇拙甇仿嚗
  • 箸迨撱箇銝 JS 瑼獢
  • 閮餃JS隞; B$ A* E3 Z0 Y$ I6 V
0 n9 W  H8 ?" ~+ O( O, x" Y
4.1 JS隞嗡撱箇
JS隞嗆舫 TinyMCE API 靘閮餃 TinyMCE 隞嗥其蜓憿 js 桅銝(/wp-content/themes/雿銝駁蝔/js/)撱箇 recent-posts.js 嚗銝西票脣颱Y隞蝣潘閬瑼(/wp-content/themes/雿銝駁蝔/js/recentpostsbutton.png)銋曉典銝桅嚗嚗
  1. (function() {" b# J/ G8 W' y, B- u
  2.         tinymce.create('tinymce.plugins.recentposts', {- x7 M1 Q  U: X4 C
  3.                 init : function(ed, url) {: {* E; x1 ?& M6 M8 s
  4.                         ed.addButton('recentposts', {* j7 \$ R# p7 j" p& f
  5.                                 title : 'Recent posts',2 W* r7 r; j8 n, T1 D3 s( m
  6.                                 image : url+'/recentpostsbutton.png',
    - ~: h+ D5 `7 {0 T% M- e
  7.                                 onclick : function() {3 S# m* l3 t8 D( n3 D
  8.                                         var posts = prompt("蝡賊", "1");) n+ x9 ~$ F9 B* p9 O5 I0 G4 g
  9.                                         var text = prompt("隢憛怠亙銵冽憿", "唳蝡");0 \  h2 P( @; B1 P9 r3 U3 ?

  10. ! F& j* q, a0 M8 M0 R8 F
  11.                                         if (text != null && text != ''){+ Z# _& c$ R7 m/ p3 e5 d* n
  12.                                                 if (posts != null && posts != '')9 v+ [% ^/ f. u; g" b& t" Q3 z
  13.                                                 ed.execCommand('mceInsertContent', false, '[recent-posts posts="'+posts+'"]'+text+'[/recent-posts]');5 F! I% H% A% W5 @6 A# {
  14.                                         else3 ]% i& k4 F1 W
  15.                                                 ed.execCommand('mceInsertContent', false, '[recent-posts]'+text+'[/recent-posts]');$ v1 D& }, l, B0 ^/ i
  16.                                         }9 f1 F* Z2 \8 s. L! A& s3 T
  17.                                         else{
    ' z2 ~/ g0 O! _
  18.                                                 if (posts != null && posts != '')
    2 b  _. X* P' K9 E6 T6 A* n; H6 {
  19.                                                         ed.execCommand('mceInsertContent', false, '[recent-posts posts="'+posts+'"]');
    8 y8 K# |" T2 V* B7 X3 e
  20.                                                 else
    9 u3 {/ S8 x' Z5 B
  21.                                                         ed.execCommand('mceInsertContent', false, '[recent-posts]');
    + ~2 D* T4 g# A
  22.                                         }
    5 i% x+ |- V. v0 L7 A
  23.                                 }6 `( c  _  U+ k
  24.                         });
    / b4 Z! k& ?$ ]! R# v/ N
  25.                 },
    ) `8 M7 y" B$ N# z5 I  y/ @9 \
  26.                 createControl : function(n, cm) {
    0 h  {3 p. t: ^0 G9 c( A
  27.                         return null;3 b; F4 Z& |# h/ \6 C
  28.                 },, S  K6 o" V/ M/ Z5 _
  29.                 getInfo : function() {
      D: ~3 I  B( l% C8 L  c
  30.                         return {9 y1 G  g/ Y6 K
  31.                                 longname : "Recent Posts",
    - C: ^- D9 G8 l
  32.                                 author : 'Specs',
    6 j+ }# X& }' T1 _. g
  33.                                 authorurl : 'http://9iphp.com',
    $ F# l! @6 D2 u7 x
  34.                                 infourl : 'http://9iphp.com/opensystem/wordpress/1094.html',* i/ q# b  P8 n1 p
  35.                                 version : "1.0"4 F' \( c5 b, L' Q. j
  36.                         };
    & e& u( R2 r8 T3 c/ z+ }/ S9 \
  37.                 }
    4 ?' }6 l/ J8 O, ^8 O9 W; ^: t
  38.         });) K& A  E7 p! N. b  `/ f. m
  39.         tinymce.PluginManager.add('recentposts', tinymce.plugins.recentposts);
    9 q- `$ ~$ A$ D/ Q9 l9 H2 G
  40. })();
銴鋆賭誨蝣
澆 tinymce.create() 撱箇鈭銝隞嗚隞蝣潔葉閬 init() 賣賂摰蝢拐銝摮嚗銝icon隞嗅 onclick() 鈭隞嗉蝔摨
onclick() 賣貊抵嚗靘摨敶箏拙撠閰望霈冽嗉撓蝡賊銵冽憿拙賂嗅寞冽嗉撓伐凋誨蝣潭亙啁楊頛臬其葉
敺嚗TinyMCE隞園 add() 賣詨 PluginManager曉冽撌脩游鈭 [recent-posts] 凋誨蝣澆訖ordpress銝准

# l4 s7 `& [5 G. D  s
4.2 閮餃TinyMCE隞
; f5 k; D: I: G8 X

% g8 c( [# w( h4 Q  y  z
嗆典撱箇JS 瑼 , 曉券閬閮餃摰凋誨蝣潭 甇斗撱箇鈭拙賣訾蒂摰蝜怎喲拍嗥 wordpress 瞈曉其葉
蝚砌怠 register_button() 賣豢凋誨蝣澆唳銝哨函暹唳銋憓脩
  1. function register_button( $buttons ) {
    * {) y. {5 Y- I- D% t8 I! f, O
  2.         array_push( $buttons, "|", "recentposts" );* b. @; F2 c0 I3 q4 c% e
  3.         return $buttons;& T( B  V2 s/ q5 L8 X# S/ `9 O2 T' H
  4. }
銴鋆賭誨蝣
蝚砌賣 add_plugin() 摰JS隞嗥頝臬隞嗅
, S4 _$ \( M3 |' Y& t6 n
  1. function add_plugin( $plugin_array ) {: T+ z* L' {  V: h
  2.         $plugin_array['recentposts'] = get_template_directory_uri() . '/js/recent-posts.js';3 {3 b$ A7 K+ r9 F! `6 X  G: F  |4 |
  3.         return $plugin_array;
    5 x3 L; N5 s  ^0 P
  4. }
銴鋆賭誨蝣
銝銝甇交臬怠W拙賣貊瞈曉具register_button() 賣賊蝯 mce_buttons 瞈曉剁函楊頛臬刻交隞嗥瑁嚗 add_plugin() 賣賊蝯 mce_external_plugins 瞈曉剁嗉交瑁/ E* c! g, ~9 c; a' g
  1. function my_recent_posts_button() { 1 Z1 u1 B! ^- s6 q1 ^  \
  2.         if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {& R: f" L9 r) c+ C
  3.                 return;
    7 U) P! Q! f/ N
  4.         }
    6 W$ `( D1 d$ t7 g( M0 p
  5. 0 W; [6 t# h8 Q$ e0 O
  6.         if ( get_user_option('rich_editing') == 'true' ) {, M5 V: @3 k- Y6 h7 ^% h
  7.                 add_filter( 'mce_external_plugins', 'add_plugin' );
    ' K. {7 i! J- b: m$ b# w
  8.                 add_filter( 'mce_buttons', 'register_button' );
    ! W9 N5 I! L4 ^  j( I
  9.         } & i" Q$ a$ ?  r' }# |
  10. }
銴鋆賭誨蝣
嗥冽嗆撠蝡航蝺刻摩其葉蝺刻摩甈嚗Y賣訾瑁3 w0 [/ p0 {+ o3 B/ |* L1 e
敺賣詨曉訖ordpress憪賣
  1. add_action('init', 'my_recent_posts_button');
銴鋆賭誨蝣
7 h) _% Z& l+ Z4 |
4.3 冽

  K- b6 w& x) d- l& u! j6 y
箔皜祈岫蝔撘蝣潭臬行迤蝣綽銝蝭啁蝡嚗銝摰蝢拍臭臬歇蝬箇曉函洵銝銵怠偏鈭嚗憒銝蝷綽

% }6 P! m" p* ]. W# q4 c7 ?
暺嚗敶箏閰望霈頛詨交蝡賊嚗
% Y1 }' b; H; E1 `! l: w
頛詨亙暺蝣箏敺嚗敶箇洵鈭撠閰望嚗霈頛詨亙銵函璅憿嚗
1 K) J. W' ^2 F& B, o
貊蝛箇閰梧銝箇曉冽敺隞蝣潔葉敺嚗凋誨蝣潭啣啁楊頛臬其葉嚗
& m; ]' C$ ?2 k0 F4 |3 o/ f
唳迨撠勗之鈭唾憓嗡賜凋誨蝣澆臭誑銝Y摮嚗憒瘜株ˊ銝銝嚗訾縑臭誑鋆賭箇泵雿瘙凋誨蝣澆
蝡: 1 2

雿輻券

祉蝛閬

砍憛批捆靘餉衣雯頝臬批捆蝝颲行粹嗥蝬脩嚗摰撟湔遛嚗嚗甇脖誑銝嗅啣摰嗆摰撟湧翩鈭箏ㄚ孵舫脣伐銝憿亙祉璇甈橘芣遛18甇 雓蝯脣亦閬賬粹脩芣遛18甇脖芣撟渡雯閬賜雯頝臭嗥批捆鞈閮嚗撱箄降典舫脰蝬脰楝批捆蝝蝯蝜ICRA蝝摰鋆閮剖 (粹蝯行霅 祉蝬脣銝蝝瘛函隢憯啣嚗祉閮剜蝞∠)

QQ|撠暺撅||52AV璈A

GMT+8, 2026-3-29 07:28 , Processed in 0.105039 second(s), 22 queries .

蝯∠.撱

52avtv@gmail.com | QQ:2405733034     since 2015-01

鋆貉憒 敹恍敺 餈銵