• Hi,
    first symbol is not a letter. It is ” or ?. These titels goes in A-Z all to the # section. Looks not so good, looks not alphabetical. Is there a way to ignore this first symbol? Maybe “A-Z Listing Search and Replace extension”?
    best,
    dknut

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    The best way to ignore the first character is to use the a_z_listing_item_index_letter filter. This can be added to your theme or child-theme’s functions.php and will ignore any non-alphabetical letter:

    add_filter( 'a_z_listing_item_index_letter', 'ignore_a_z_non_alphabetical_letters_at_start_of_title', 10, 3 );
    function ignore_a_z_non_alphabetical_letters_at_start_of_title( $index_letters, $item, $type ) {
        // if we already have an alphabetical letter, return it immediately
        if ( preg_match( '/^[A-Za-z]$/', $index_letters[0] ) ) {
            retrun $index_letters;
        }
    
        // loop through the title letters and return the first alphabetical letter
        for ( $i = 0; $i < mb_strlen( $item->title ); $i++ ) {
            $letter = mb_substr( $i, 1 );
            if ( preg_match( '/^[A-Za-z]$/' $letter ) ) {
                return array( $letter );
            }
        }
    
        // if we get here, then there are no alphabetical letters in the title so return the original index
        return $index_letters;
    }
    • This reply was modified 4 years, 1 month ago by Dani Llewellyn. Reason: add missing regex `//` characters
    Plugin Author Dani Llewellyn

    (@diddledani)

    You can allow numbers to be separated by changing both instances of /^[A-Za-z]$/ to /^[A-Za-z0-9]$/.

    Thread Starter dknut

    (@dknut)

    Okay, thanks you, Daniel. I’ll try it. But need some time for that.

    Thread Starter dknut

    (@dknut)

    Hi Daniel,
    there is something wrong in this code. I’m not a developer but I think it is in the line

    for ( $i = 0; $i < mb_strlen( $item->title ); $i++ ) {

    Thanks.

    dknut

    • This reply was modified 4 years, 1 month ago by dknut.
    Plugin Author Dani Llewellyn

    (@diddledani)

    You’re quite right, I think the $item->title should be $item->post_title.

    Thread Starter dknut

    (@dknut)

    Did not work. If I add above filter to my theme the whole site will be dead until I remove it.

    Plugin Author Dani Llewellyn

    (@diddledani)

    When the site dies there should be some logged errors in a file on your server somewhere. This is likely called “Error Log” or “error.log” or “error_log”. It is possible that the functions.php file had an error with your changes that caused the site to stop, which the error log would help us to isolate. I suspect I probably made a mistake in the code sample above.

    Thread Starter dknut

    (@dknut)

    Thanks, @diddledan ! Its not necessary to waste more time on this. Its not so important to use it. It was nice but no more.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Ignoring first symbol/letter’ is closed to new replies.