SHARE
TWEET

WordPress Gems 1 - selected, checked & disabled

ulfben Nov 16th, 2011 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Installation paths and URLs, with SSL support: http://codex.wordpress.org/Determining_Plugin_and_Content_Directories
  3. */
  4.  
  5. /* standard solution to populate a selection drop-down */
  6. <?php $sel = ' selected="selected"'; ?>
  7. <label for="<?= $this->get_field_id('sortby'); ?>"><?php _e('Sort by:', 'wpdtree'); ?></label>  
  8. <select id="<?= $this->get_field_id('sortby'); ?>" name="<?= $this->get_field_name('sortby'); ?>">     
  9.         <option value="post_title" <?php if($conf['sortby'] == 'post_title') echo $sel; ?>>
  10.                 Title
  11.         </option>
  12.         <option value="post_date" <?php if($conf['sortby'] == 'post_date') echo $sel; ?>>
  13.                 Date
  14.         </option>
  15.         <option value="ID" <?php if($conf['sortby'] == 'ID') echo $sel;? >>
  16.                 ID
  17.         </option>
  18. </select>
  19.  
  20. <!-- using WordPress selected(): -->
  21. <label for="<?= $this->get_field_id('sortby'); ?>"><?php _e('Sort by:', 'wpdtree'); ?></label>  
  22. <select id="<?= $this->get_field_id('sortby'); ?>" name="<?= $this->get_field_name('sortby'); ?>">     
  23.         <option value="post_title" <?php selected($conf['sortby'], 'post_title'); ?>>Title</option>
  24.         <option value="post_date" <?php selected($conf['sortby'], 'post_date'); ?>>Date</option>
  25.         <option value="ID" <?php selected($conf['sortby'], 'ID'); ?>>ID</option>
  26. </select>      
  27.  
  28. /*  similar functions:
  29.  checked() - compares two values and output the checked attribute for radio buttons / checkbox
  30.  disabled() - =||= disables a form input field
  31. */
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top