WPML 筆記

常數

  ICL_LANGUAGE_CODE當前語言的Code
ex:zh-hant、ja、en

Functions

獲取預設語言碼

由翻譯文章取得主要與言文章id

$element_id
(int) (Required) The ID of the post type (post, page, attachment, custom post) or taxonomy term (tag, category, custom taxonomy) to filter
$element_type
(string) (Required) The typ[……]

Read more

WordPress thumbnail default size 預設縮圖尺寸表

WordPress 預設縮圖尺寸表

尺寸名 (字串)大小尺寸說明thumbnail小150 x 150 強制裁剪尺寸medium中等300 x 300 最大高度300像素medium_large中大768 x 無限高 WP4.4增加large 大1024 x 1024 最大高度1024像素full完整尺寸原始大小 

WooCommerce 預設縮圖尺寸表

尺寸名 (字串)大小尺寸說明shop_thumbnail小180 x 180強制裁剪尺寸shop_catalog中300 x 300強制裁剪尺寸shop_[……]

Read more

WPML fix get_posts() shows all languages problem

解決WPML使用get_posts(),會顯示所有文章列表,而不是顯示當前語言文章列表

$list = get_posts(array(
	'showposts' => -1,
	'post_type' => 'wpcf7_contact_form',
	'post_status' => 'publish',
));

解決方法:

在參數中加上 ‘suppress_filters’ => false  即可,原因不明

$list = get_posts(array(
	'showposts' => -1,
	'post_type' => '[......]

Read more

WPML Ajax 無法取得翻譯文章

WPML Ajax 無法取得翻譯文章

使用WPML插件,使用Ajax取得文章,一直都沒辦法取得當前文章,只會取得預設語言文章,在這個問題上花費了好多時間,終於解決了!!!!

推測原因是WPML在 pre_get_posts  這個 hook 會override query_vars值,去對應翻譯文章分類,與得翻譯分類文章,在一般情況下是沒問題的,但使用Ajax要資料的時候,並沒有帶參數給WPML,以致WPML認為是預設語言,在 pre_get_posts  這個 hook 會override query_vars為預設語言,所以無法取得當前翻[……]

Read more

WordPress get_post_type() is Null

主題或插件中有時我們會用同一支程式重複使用,比如說主題的Banner,通常不會每一個頁面寫一次,而是每個頁面都會 include banner.php 檔案,這樣的好處是維護比較方便讓程式的再利用,但在banner.php中,不可能所有頁面banner全都一樣,所以在banner.php需要設定一些判斷條件,依據不同條件做不同的事。

範例:

<?php
$post_type = get_post_type( get_the_ID() );
if ( in_array( $post_type , array('page','post','custom_post_type_nam[......]

Read more

WordPress Fix TypeError: p.easing[this.easing] is not a function

Fix TypeError: p.easing[this.easing] is not a function

function v123_dev_main_scripts() {
        wp_enqueue_script('jquery');
        wp_enqueue_script('jquery-ui-core');
	wp_enqueue_script('jquery-effects-core');
}
add_action('wp_enqueue_scripts', 'v123_dev_main_scripts');

 [……]

Read more

WordPress admin Remove notice and warning

本篇提供一個目前我用覺得很好用的方法,真正的刪除這些惱人的警告,之前有看過有些人的做法是用CSS去 display:none 這些提示與警告,然後假裝看不見,我覺得這樣很蠢,不是個好作法,你可以試試以下方法,也需幫的道你。[……]

Read more