Skip to content

Instantly share code, notes, and snippets.

@ockham
Created December 29, 2012 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ockham/4409258 to your computer and use it in GitHub Desktop.
Save ockham/4409258 to your computer and use it in GitHub Desktop.
I've produced a patch that enables a `numbers` option to the [alphabet] shortcode which defaults to 'true', but when set to false, makes the shortcode result in displaying only letters, not numbers, i.e. ABCDEFGHIJKLMNOPQRSTUVWXYZ instead of 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ I've also simplified generation of numbers and letters by usage of r…
Gemeinsame Unterverzeichnisse: my-content-management/images und my-content-management-nums/images.
Gemeinsame Unterverzeichnisse: my-content-management/lang und my-content-management-nums/lang.
diff -u my-content-management/my-content-management.php my-content-management-nums/my-content-management.php
--- my-content-management/my-content-management.php 2012-10-27 20:27:18.000000000 +0200
+++ my-content-management-nums/my-content-management.php 2012-12-29 21:27:34.000000000 +0100
@@ -700,7 +700,7 @@
if ( $value == 'mcm_glossary' && function_exists('mcm_set_glossary') ) { $extension = "<h4>Glossary Extension</h4>
<p>".__('The glossary extension to My Content Management is enabled.','my-content-management')."</p>
<ul>
- <li><code>[alphabet]</code>: ".__('displays list of linked first characters represented in your Glossary. (Roman alphabet only.)','my-content-management')."</li>
+ <li><code>[alphabet numbers='true']</code>: ".__('displays list of linked first characters represented in your Glossary. (Roman alphabet only, including numbers 0-9 by default.)','my-content-management')."</li>
<li><code>[term id='' term='']</code>: ".__('displays value of term attribute linked to glossary term with ID attribute.','my-content-management')."</li>
<li><strong>".__('Feature','my-content-management').":</strong> ".__('Adds links throughout content for each term in your glossary.','my-content-management')."</li>
<li><strong>".__('Feature','my-content-management').":</strong> ".__('Adds character headings to each section of your glossary list.','my-content-management')."</li>
diff -u my-content-management/my-glossary-filter.php my-content-management-nums/my-glossary-filter.php
--- my-content-management/my-glossary-filter.php 2012-10-27 20:27:18.000000000 +0200
+++ my-content-management-nums/my-glossary-filter.php 2012-12-29 21:25:28.000000000 +0100
@@ -28,24 +28,32 @@
add_action('admin_notices', create_function( '', "echo \"<div class='error'><p>My Content Management must be activated to use MCM Glossary Filter. <a href='$activate'>Visit your plugins page to activate</a>.</p></div>\";" ) );
}
-function mcm_glossary_alphabet() {
+function mcm_glossary_alphabet($atts) {
+ extract(shortcode_atts(array(
+ 'numbers' => 'true',
+ ), $atts));
+
$return = '';
- $letters = explode( ',','0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z' );
- $words = get_option( 'mcm_glossary' );
- if ( !is_array( $words ) ) {
- $words = mcm_set_glossary();
- }
- foreach ( $words as $key=>$value ) {
- $this_letter = strtolower( substr( $key, 0, 1 ) );
- $live[]=$this_letter;
- }
- foreach ( $letters as $letter ) {
- if ( in_array( $letter, $live ) ) {
- $return .= "<li><a href='#glossary$letter'>$letter</a></li>";
- } else {
- $return .= "<li class='inactive'>$letter</li>";
- }
+ $nums = range('0','9');
+ $letters = range('a','z');
+ if ($numbers != 'false')
+ $letters = array_merge($nums, $letters);
+
+ $words = get_option( 'mcm_glossary' );
+ if ( !is_array( $words ) ) {
+ $words = mcm_set_glossary();
+ }
+ foreach ( $words as $key=>$value ) {
+ $this_letter = strtolower( substr( $key, 0, 1 ) );
+ $live[]=$this_letter;
+ }
+ foreach ( $letters as $letter ) {
+ if ( in_array( $letter, $live ) ) {
+ $return .= "<li><a href='#glossary$letter'>$letter</a></li>";
+ } else {
+ $return .= "<li class='inactive'>$letter</li>";
}
+ }
return "<ul class='glossary-alphabet' id='alpha'>".$return."</ul>";
}
add_shortcode('alphabet','mcm_glossary_alphabet');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment