WPML Trick
-
Hi Guys,
This problem was big headache for me but ı find a trick way finally..
// posts array $posts_data = array(); $countpost = 0; if ( !is_array($mostpopular) || empty($mostpopular) ) { // no posts to show $content .= "<p>".__('Sorry. No data so far.', 'wordpress-popular-posts')."</p>"."\n"; } else { // list posts // HTML wrapper if ($instance['markup']['custom_html']) { $content .= htmlspecialchars_decode($instance['markup']['wpp-start'], ENT_QUOTES) ."\n"; } else { $content .= "<ul class=\"wpp-list\">" . "\n"; } foreach($mostpopular as $p) { $countpost++; $stats = ""; $thumb = ""; $title = ""; $title_sub = ""; /** WPML COMPATIBLE **/ global $sitepress; if (ICL_LANGUAGE_CODE==en) { $current_main_id = icl_object_id( $p->id, 'post', true, $sitepress->get_default_language() ); $current_slug = get_post( $current_main_id ); $slug = $current_slug->post_name; } else { $current_main_id = icl_object_id( $p->id, 'post', true, 'ko' ); $current_slug = get_post( $current_main_id ); $slug = $current_slug->post_name; } $permalink = get_permalink( $current_main_id); $author = ($instance['stats_tag']['author']) ? get_the_author_meta('display_name', $p->uid) : ""; $date = date_i18n( $instance['stats_tag']['date']['format'], strtotime($p->date) ); $pageviews = ($instance['order_by'] == "views" || $instance['order_by'] == "avg" || $instance['stats_tag']['views']) ? (($instance['order_by'] == "views" || $instance['order_by'] == "comments") ? $p->pageviews : $p->avg_views ) : 0; $comments = ($instance['order_by'] == "comments" || $instance['stats_tag']['comment_count']) ? $p->comment_count : 0; $post_cat = ""; $excerpt = ""; $rating = ""; $data = array(); // TITLE $title = ($this->qTrans) ? qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($p->title) : $p->title; $title = strip_tags(get_the_title($current_main_id)); $title_sub = strip_tags($title); // truncate title if ( $instance['shorten_title']['active'] ) { if ( isset($instance['shorten_title']['words']) && $instance['shorten_title']['words'] ) { // by words $words = explode(" ", $title, $instance['shorten_title']['length'] + 1); if ( count($words) > $instance['shorten_title']['length'] ) { array_pop($words); $title_sub = implode(" ", $words) . "..."; } } else { // by characters if ( strlen($title) > $instance['shorten_title']['length'] ) { $title_sub = mb_substr($title, 0, $instance['shorten_title']['length'], $this->charset) . "..."; } } } $title = htmlspecialchars( $title, ENT_QUOTES, $this->charset ); $title_sub = htmlspecialchars( $title_sub, ENT_QUOTES, $this->charset ); $title = apply_filters('the_title', $title, $p->id); $title_sub = apply_filters('the_title', $title_sub, $p->id);
But this is just trick if current language is EN,
I can change title and link with current language..Anyway ı hope this can be useful for you.
I hope plugin owner will make this plugin compatible with WPML..THANKS.
SERHAT EVREN
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘WPML Trick’ is closed to new replies.