当我没有登录时,Wordpress的functions.php无法检测到网站的语言

时间:2017-10-09 07:42:17

标签: php wordpress function multiple-languages

我在入境营销公司工作,他们使用X theme.co主题。

该网站有两种语言希伯来语和英语。 我尝试使用Ajax和Functions.php创建一个短代码来添加以前的事件。 我登录网站时知道如何检测它是英文还是希伯来文。 但是当我退出网站时,会给我一个希伯来语的主要语言。 顺便说一句,有希伯来事件和英国事件,它不是同一个数据库。 当您第一次进入活动页面时,它会检测到该语言,但在您点击"添加更多活动后,它将无法检测到该语言。这将激活functions.php

中的功能

我不知道为什么会这样做。请帮忙!

function load_events_by_ajax_callback(){

check_ajax_referer('load_more_events','security');
$paged = $_POST['page'];

//Years
$prev_year=$_POST['cos_prev_year'];
$curr_year=$_POST['cos_curr_year'];
//Years

$all_events="";

global $post;

$args = array(

    'post_type'             => 'event',
    'meta_key'              => '_event_date',
    'orderby'           => 'meta_value_num',
    'order'             => 'DESC',
    'posts_per_page'        => '12',
    'paged'                 => $paged,

    'meta_query'            => array(
        array(
            'key'       => '_event_date',
            'type'      => 'numeric',
        ),
    )

);

$featured_query = new WP_Query( $args );

if( $featured_query->have_posts() ):           
    while( $featured_query->have_posts() ) : $featured_query->the_post();

        $date = get_field('_event_date');
        $get_the_date=date_parse_from_format("d.m.Y", $date);
        $display_date=$get_the_date["year"].'/'.$get_the_date["month"].'/'.$get_the_date["day"];
        $month=$get_the_date["month"];
        $month_name=date('F', mktime(0, 0, 0, $month, 10));
        $img_url=get_the_post_thumbnail_url(null,'large');

        //Years
        $curr_year=$get_the_date["day"];
        $dt = DateTime::createFromFormat('y',$curr_year);
        $curr_year=$dt->format('Y');

        if($curr_year != $prev_year){
             $all_events.='<h5 class="h-custom-headline cs-ta-center h5 accent"><span>'.$curr_year.'</span></h5>';
            $prev_year=$curr_year;

        }
        //Years

        $all_events.='<div class="novus_ptBMtYhoMB317wduyTDqor0Ys x-column x-sm cs-ta-center x-1-3" style="margin:1% !important; float:none !important; display:inline-block !important; vertical-align:top !important;" >';
        $all_events.='<div class="x-recent-posts cf horizontal">';
        $all_events.='<a class="x-recent-post1 with-image " href="'.get_permalink($post->ID).'">';
        $all_events.='<article class="event type-event status-publish has-post-thumbnail hentry ">';
        $all_events.='<div class="entry-wrap">';
        //Start - date of the event
                if(time()>strtotime($date)){
                        $all_events.='<div style="background:rgba(128,128,128,0.7) !important;" class="shortcode_event_date">';
                        $all_events.='<i class="fa fa-calendar" aria-hidden="true"></i>';
                            if(ICL_LANGUAGE_CODE == 'he'){
                                $all_events.='<span class="title"> אירוע הסתיים </span>';
                            }

                            else if(ICL_LANGUAGE_CODE == 'en'){
                                $all_events.='<span class="title"> Event ended </span>';
                            }
                        $all_events.='</div>';
                    }
                else{
                    $all_events.='<div style="background:rgba(37,206,190, 0.8) !important;" class="shortcode_event_date">';
                    $all_events.='<i class="fa fa-calendar" aria-hidden="true"></i>';
                    $all_events.='<span class="date"> '.$display_date.' </span>';
                    $all_events.='</div>';
                }
        //End - date of the event
        $all_events.='<div class="x-recent-posts-img" style="background-image: url('.$img_url.');"> </div>';
        $all_events.='<div class="x-recent-posts-content">';
        $all_events.='<h3 class="h-recent-posts">'.get_the_title().'</h3>';
        $all_events.='</div>';
        $all_events.="</div>";
        $all_events.='</article>';
        $all_events.='</a>';
        $all_events.='</div>';
        $all_events.="</div>";

        endwhile;


    endif; wp_reset_query();

    //Years
    $all_events.='<script>';
    $all_events.='jQuery(document).ready(function($){';
    $all_events.='$("#curr-year").val("'.$curr_year.'");';
    $all_events.='$("#prev-year").val("'.$prev_year.'");';
    $all_events.='});';
    $all_events.='</script>';
    //Years

    echo $all_events;
    wp_die();

}

1 个答案:

答案 0 :(得分:0)