Support » Plugin: Alphabetic Pagination » Styling:Disable Empty Alphabets doesn’t work

  • Resolved newkidintheblock

    (@newkidintheblock)


    Hello,
    it seems the disabling empty alphabet function still doesn’t work. I switch the function on/off but the result is just the same: the url still appears for empty alphabets. When I click on such charachter I get directed to a “search result not found” page.
    Or should it work only in pro version?
    thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • @newkidintheblock please share the link of the page where you are using pagination.

    Thread Starter newkidintheblock

    (@newkidintheblock)

    Hello,
    sure, here it is:
    http://novenyek.com/location/croatia/
    thanks!

    Thread Starter newkidintheblock

    (@newkidintheblock)

    sorry, I’ve forgotten to say that “W” is a good example. There isn’t post within that Char.

    Plugin Author Fahad Mahmood

    (@fahadmahmood)

    @newkidintheblock I hope you got the new version with improvements. Can you please reach us through our demo website so we can test it together somewhere?

    Thread Starter newkidintheblock

    (@newkidintheblock)

    Hi Mahmood,
    thanks for your help.
    I finally ended up with an own solution. I replaced the plugin with a snippet.
    I share it here for those who also looking for such functionality.
    It works in category.php(or archive-php). Where you want the ABC navigation to be shown, insert this: alphabet_navi();

    And this coding goes into the functions.php:

    if($_GET[“alphabet”])
    {
    add_filter(‘posts_where’,’alphabet_selection’, 10 , 2 );
    function alphabet_selection( $where )
    {
    global $wpdb;
    $where .= “AND LEFT({$wpdb->prefix}posts.post_title, 1) = ‘”.$_GET[“alphabet”].”‘ “;

    return $where;
    }
    }
    function alphabet_navi() {

    // Collecting all posts within current category into an array

    $cat_id = get_queried_object_id();

    $args = array(
    ‘cat’ => $cat_id,
    ‘orderby’ => ‘post_title’,
    ‘order’ => ‘ASC’,
    ‘nopaging’ => true,//get all posts
    ‘posts_per_page’ => -1); //get all posts
    $posts = get_posts($args);

    $existing_chars_only = array(); //collecting in that the first characters from post titles-only those which exist in the category

    foreach ($posts as $post) :
    $ltr_group = substr($post->post_title, 0, 1);
    if(!in_array($ltr_group, $existing_chars_only)){ //Add CHAR only if new
    $existing_chars_only[] = $ltr_group;
    }
    endforeach;

    //Collecting all posts within current category into an array-END

    //echo ABC list
    $wp_alphabet = range(“A”,”Z”);
    echo ‘<div class=”alphabet_navi-wrap”>’;
    echo ‘<div class=”alphabet_navi-letters”>’;

    echo ‘<ul class=”alphabet_navi-links”>’;
    foreach ($wp_alphabet as $wp_aplha){
    if(in_array($wp_aplha,$existing_chars_only)){ //if this CHAR exist among the posts
    if($_GET[“alphabet”] == $wp_aplha){ //if we are on a page of the selected CHAR
    echo ‘<li class=”alphabet_navi-hasposts alphabet_navi-selected”>‘.$wp_aplha.’‘;
    }
    else{
    echo ‘<li class=”alphabet_navi-hasposts”>‘.$wp_aplha.’‘;
    }
    }
    else{ //if there isn’t such CHAR among the posts
    echo ‘<li class=”alphabet_navi-noposts”>’.$wp_aplha.’‘;
    }
    }
    //echo ‘‘;
    echo ‘</div>’;
    echo ‘</div>’;
    }`

    richiewatson

    (@richiewatson)

    @newkidintheblock please update your script with the suggested improvements

    Plugin Author Fahad Mahmood

    (@fahadmahmood)

    @newkidintheblock please properly sanitize the global variables. It would be a security risk using your code snippet and visitors might will think it is a suggestion from plugin author. I am not recommending this code snippet in any case, whoever want to use this code snippet, he should simply understand the following action hook.

    add_filter(‘posts_where’,’alphabet_selection’, 10 , 2 );

    These support forums are for bug reporting and suggestions but provided code snippets by other users are not tested or recommended by the plugin author.

    Thanks,
    Fahad

    Thread Starter newkidintheblock

    (@newkidintheblock)

    Hi Fahad,
    you are right. thank you for your suggestion, I am still learning.
    Kr,
    newkidintheblock

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.