apply_filters( 'wpml_element_link', int $element_id, string $element_type, string $link_text, array $optional_parameters, string $anchor, bool $echo, bool $return_original_if_missing )
- ประเภท
- filter
- เวอร์ชันของ WPML
- 3.2
คำอธิบาย
คืนค่าลิงก์ประเภทโพสต์หรือลิงก์เทอมอนุกรมวิธานในภาษาปัจจุบัน
* หมายเหตุ: มีวิธีอื่นในการดึงข้อมูลลิงก์ของอิลิเมนต์ ซึ่งช่วยให้นักพัฒนาสามารถควบคุมเอาต์พุต HTML ได้อย่างเต็มที่มากขึ้น
WordPress มีฟังก์ชันหลายอย่างสำหรับทำสิ่งนี้ เช่น get_permalink(), get_term_link() เป็นต้น
หากคุณวางแผนที่จะใช้ฟังก์ชันที่ต้องการประเภทโพสต์หรือ ID ของเทอมเป็นพารามิเตอร์ คุณอาจสนใจดูที่ฟิลเตอร์ wpml_object_id
อาร์กิวเมนต์
- $element_id
- (int) (จำเป็น) ID ของประเภทโพสต์ (post, page, attachment, custom post) หรือคำในอนุกรมวิธาน (tag, category, custom taxonomy) ที่จะลิงก์ไป
- $element_type
- (string) (ไม่บังคับ) ประเภทขององค์ประกอบที่จะลิงก์ไป สามารถเป็น ‘post’, ‘page’, ‘attachment’, '{custom post}', ‘tag’, ‘category’, '{custom taxonomy}' ค่าเริ่มต้นคือ ‘post’
- $link_text
- (string) (ไม่บังคับ) ข้อความลิงก์ ค่าเริ่มต้นคือชื่อขององค์ประกอบ
- $optional_parameters
- (array) (ไม่บังคับ) อาร์กิวเมนต์สำหรับลิงก์
- $anchor
- (string) (ไม่บังคับ) แองเคอร์สำหรับลิงก์
- $echo
- (bool) (ไม่บังคับ) 0|false เพื่อส่งคืนค่า หรือ 1|true เพื่อแสดงผลลิงก์ที่แปลแล้ว ค่าเริ่มต้นคือ true
- $return_original_if_missing
- (bool) (ไม่บังคับ) หากตั้งค่าเป็น true จะส่งคืนค่าเสมอ (ส่งคืนค่าต้นฉบับ หากไม่มีการแปล) ค่าเริ่มต้นคือ TRUE
ตัวอย่างการใช้งาน
ตัวอย่าง
//produces: <a href="/hello-world/">Hello World!</a> apply_filters( 'wpml_element_link', 1 ); //produces: <a href="/sample-page/">Custom link text for the sample page</a> apply_filters( 'wpml_element_link', 2, 'page', __( 'Custom link text for the sample page' ) ); //produces: <a href="/sample-page/?category=foo&bar=baz">Sample Page</a> apply_filters( 'wpml_element_link', 2, 'page', '', array( 'category'=>'foo', 'bar'=>'baz' ) ); //produces: <a href="/sample-page/#contact">Sample Page</a> apply_filters( 'wpml_element_link', 2, 'page', '', '', 'contact' ); //produces: <a href="/category/uncategorized/">Uncategorized</a> apply_filters( 'wpml_element_link', 1, 'category' ); //produces: <a href="/th/?attachment_id=25">'Attachment image title</a> apply_filters( 'wpml_element_link', 25, 'attachment', __( 'Attachment image title' ) );
ฮุกที่เกี่ยวข้อง
wpml_media_url, wpml_media_id, force_suppress_filters, wpml_get_translated_slug, wpml_home_url, wpml_translate_single_string, wpml_translate_string, wpml_elements_without_translations, wpml_permalink, wpml_unfiltered_admin_string
ฮุก การดึงเนื้อหาที่ปรับให้เข้ากับท้องถิ่น ทั้งหมด 12 รายการ →