Example #1
0
/**
 * Handle the a-z-listing shortcode.
 * @param  array $atts Provided by WordPress core. Contains the shortcode attributes.
 * @return string      The A-Z Listing HTML.
 */
function a_z_shortcode_handler($atts)
{
    $atts = shortcode_atts(array('column-count' => 1, 'minimum-per-column' => 10, 'heading-level' => 2, 'post-type' => 'page'), $atts, 'a-z-listing');
    $query = array('post_type' => $atts['post-type']);
    $a_z_query = new A_Z_Listing($query);
    return $a_z_query->get_the_listing();
}
Example #2
0
 protected static function get_alphabet()
 {
     if (!empty(self::$alphabet)) {
         return;
     }
     /* translators: List the aphabet of your language in the order that your language prefers. list as groups of identical meanings but different characters together, e.g. in English we group A with a because they are both the same letter but different character-code. Each character group should be followed by a comma separating it from the next group. Any amount of characters per group are acceptible, and there is no requirement for all the groups to contain the same amount of characters as all the others. Be careful with the character you place first in each group as that will be used as the identifier for the group which gets displayed on the page, e.g. in English a group definition of "Aa" will indicate that we display all the posts in the group, i.e. whose titles begin with either "A" or "a", listed under a heading of "A" (the first character in the definition). */
     $alphabet = apply_filters('a-z-listing-alphabet', __('AÁÀÄÂaáàäâ,Bb,Cc,Dd,EÉÈËÊeéèëê,Ff,Gg,Hh,IÍÌÏÎiíìïî,Jj,Kk,Ll,Mm,Nn,OÓÒÖÔoóòöô,Pp,Qq,Rr,Ssß,Tt,UÚÙÜÛuúùüû,Vv,Ww,Xx,Yy,Zz'));
     /* translators: This should be a single character to denote "all entries that didn't fit under one of the alphabet character groups defined". This is used in English to categorise posts whose title begins with a numeric (0 through to 9), or some other character that is not a standard English alphabet letter. */
     $others = apply_filters('a-z-listing-non-alpha-char', __('#', 'a-z-listing'));
     $alphabet_groups = mb_split(',', $alphabet);
     $letters = array_reduce($alphabet_groups, function ($return, $group) {
         $group = A_Z_Listing::mb_string_to_array($group);
         $group_index_character = $group[0];
         $group = array_reduce($group, function ($group, $character) use($group_index_character) {
             $group[$character] = $group_index_character;
             return $group;
         });
         if (!is_array($return)) {
             return $group;
         }
         return array_merge($return, $group);
     });
     self::$alphabet = $letters;
     self::$unknown_letters = $others;
 }
Example #3
0
/**
 * Get the user-visible widget html.
 * @param  Array $args     General widget configuration. Often shared between all widgets on the site.
 * @param  Array $instance Configuration of this Widget. Unique to this invocation.
 * @return  string The complete A-Z Widget HTML ready for echoing to the page.
 */
function get_the_section_a_z_widget($args, $instance)
{
    $instance = wp_parse_args($instance, array('title' => '', 'post' => 0));
    if ($instance['post']) {
        $target = get_post((int) $instance['post']);
    } else {
        return null;
    }
    $title = $instance['title'];
    if (empty($title)) {
        $title = $target->post_title;
    }
    $apply_styling = isset($instance['apply-styling']) && true === $instance['apply-styling'] ? true : false;
    $a_z_query = new A_Z_Listing();
    $ret = $args['before_widget'];
    // WPCS: XSS OK.
    $ret .= $args['before_title'];
    // WPCS: XSS OK.
    $ret .= esc_html($title);
    $ret .= $args['after_title'];
    // WPCS: XSS OK.
    $ret .= '<div class="az-letters">';
    $ret .= $a_z_query->get_the_letters(get_permalink($target), $apply_styling ? 'default-style' : null);
    $ret .= '<div class="clear empty"></div></div>';
    $ret .= $args['after_widget'];
    // WPCS: XSS OK.
    return $ret;
}