簡體   English   中英

僅當URL大小寫正確時,Wordpress小部件才處於活動狀態

[英]Wordpress widget only active if url case is correct

我的wordpress網站上的小部件有問題。 基本上,它是一個Ajax導航(過濾器)側欄,使用戶可以通過單擊所需選項來過濾結果。 我遇到的問題是,小部件似乎區分大小寫,並且僅在url大小寫正確時才會顯示。

例如

如果網址是這樣,則該窗口小部件將不會顯示:

mysite.com/product-category/mens

但如果網址是此網址,則會出現(注意大寫的M):

mysite.com/product-category/Mens

我試過在服務器中激活mod_spelling,並在.htaccess中嘗試CheckSpelling,但這並沒有改變。 我必須手動輸入URL才能顯示小部件。

有人有什么想法嗎?

謝謝

克里斯

這是我的小部件的代碼:

    /* FIX TO WOOCOMMERCE 2.1 */

    if ( function_exists( 'wc_attribute_taxonomy_name' ) ) {

        $taxonomy = wc_attribute_taxonomy_name($instance['attribute']);

    } else {

        $taxonomy = $woocommerce->attribute_taxonomy_name($instance['attribute'] );

    }

    if ( ! taxonomy_exists( $taxonomy ) )

        return;

    $terms = yit_get_terms( $terms_type_list, $taxonomy );


    if ( count( $terms ) > 0 ) {

        ob_start();

        $found = false;

        echo $before_widget . $before_title . $title . $after_title;

        // Force found when option is selected - do not force found on taxonomy attributes

        if ( ! $_attributes_array || ! is_tax( $_attributes_array ) )


            if ( is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) )

                $found = true;

        if ( $display_type == 'list' ) {



            // List display

            echo "<ul class='yith-wcan-list yith-wcan'>";


            $topten = array_slice($terms,0,10);
            usort($topten,"cmp");
            $terms = array_slice($terms,10);
            usort($terms,"cmp");
            $terms = array_merge((array)$topten,(array)$terms);


            foreach ( $terms as $term ) {


                // Get count based on current view - uses transients

                $transient_name = 'wc_ln_count_' . md5( sanitize_key( $taxonomy ) . sanitize_key( $term->term_id ) );

                if ( false === ( $_products_in_term = get_transient( $transient_name ) ) ) {

                    $_products_in_term = get_objects_in_term( $term->term_id, $taxonomy );

                    set_transient( $transient_name, $_products_in_term );

                }

                $option_is_set = ( isset( $_chosen_attributes[ $taxonomy ] ) && in_array( $term->term_id, $_chosen_attributes[ $taxonomy ]['terms'] ) );

                // If this is an AND query, only show options with count > 0

                if ( $query_type == 'and' ) {

                    $count = sizeof( array_intersect( $_products_in_term, $woocommerce->query->filtered_product_ids ) );

                    // skip the term for the current archive

                    if ( $current_term == $term->term_id )

                        continue;

                    if ( $count > 0 && $current_term !== $term->term_id )

                        $found = true;

                    if ( ( $terms_type_list != 'hierarchical' || ! yit_term_has_child($term, $taxonomy) ) && $count == 0 && ! $option_is_set ){

                        continue;

                    }

                // If this is an OR query, show all options so search can be expanded

                } else {

                    // skip the term for the current archive

                    if ( $current_term == $term->term_id )

                        continue;

                    $count = sizeof( array_intersect( $_products_in_term, $woocommerce->query->unfiltered_product_ids ) );

                    if ( $count > 0 )

                        $found = true;

                }

                $arg = 'filter_' . sanitize_title( $instance['attribute'] );

                $current_filter = ( isset( $_GET[ $arg ] ) ) ? explode( ',', $_GET[ $arg ] ) : array();

                if ( ! is_array( $current_filter ) )

                    $current_filter = array();

                $current_filter = array_map( 'esc_attr', $current_filter );

                if ( ! in_array( $term->term_id, $current_filter ) )

                    $current_filter[] = $term->term_id;

                // Base Link decided by current page

                if ( defined( 'SHOP_IS_ON_FRONT' ) ) {

                    $link = home_url();

                } elseif ( is_post_type_archive( 'product' ) || is_page( function_exists( 'wc_get_page_id' ) ? wc_get_page_id('shop') : woocommerce_get_page_id('shop') ) ) {

                    $link = get_post_type_archive_link( 'product' );

                } else {

                    $link = get_term_link( get_query_var('term'), get_query_var('taxonomy') );

                }

*****更新****

為了避免搜索大量代碼,我認為我需要沿着.htacess路線,用“ / Mens”替換“ / mens”。 誰能建議這是否可以解決問題?

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^mens [NC]
RewriteRule ^ %{REQUEST_URI}/Mens [R,L]

不知道您的代碼是什么樣子,但是如果您使用$ _GET ['key']之類的東西從URL中獲取“ Mens”,則可以使用php函數ucfirst();。

對於javascript,您需要制作自己的函數。 我使用了我從另一個stackoverflow問題得到的函數:

function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}

如何在JavaScript中將字符串的首字母大寫?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM