@alexander This is something that we talked about right when PRO was released, and you pointed us in the right direction for us to create a solution for it. It’s similar to #1, and it works by hooking into the Filter that you already have in place in the architecture (cs_match_header_assignment). Here is the code to review for anyone interested, in full plugin form,and can be copied and pasted should anyone want to use it.
This solution is so that we could have multilingual headers for the taxonomy pages, but this should work for any page. To make it more “user friendly” you could use WPMLs “get langauges” api functionality, create a drop down box in each header or footer, and assign an existing language. But, despite no WYSIWYG interface, the naming convention works quite well. Note that our solution allows for headers to be localized not just translated. This is huge in that different content, including layout, message, images, etc, can be served per language and not just translated content.
<?php
/*
Plugin Name: Tourism Builder Custom Archive Pages
Plugin URI: http://tourismbuilder.com
Description: Dynamically generated taxonomy pages
Version: 1.0
Author: Blue Presley
Author URI: http://tourismbuilder.com
Text Domain: tb_custom_archive_pages
Domain Path: /languages
License: GPL-2.0+
*/
// https://codex.wordpress.org/Function_Reference/get_queried_object
function tb_category_header_assignment($match, $assignments, $post) {
if (is_archive()) {
$term = get_queried_object();
//var_dump($term);
// get posts of type cs_header
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'cs_header',
'post_status' => 'tco-data' // <-- IMPORTANT - custom post status!!
);
$cs_headers = get_posts($args);
//var_dump($cs_headers);
// First check to see if there is an exact match for the header
// If so, this allows for a header to be "localized" rather than
// just translated; meaning, it's possible to deliver completely
// different header content on a per language basis, including even images and layout.
//
// This is not for just multilingual capability. This funtionality
// allows category pages to also have custom headers created via the
// wysiwyg editor
foreach ($cs_headers as $key => $header) {
// print $header->post_title;
if (strtolower($header->post_title) == strtolower($term->name)) {
//print $term->name;
$match = $header->ID;
return $match;
}
}
// If a match is NOT found, then check to see if a header already exists
// in any language (most likely the source language). If so, use that
// header. This eliminates the need to duplicate headers for each language
// Also, this function should not fire if WPML is not enabled
// get a list of all currently active languages
// We're looking for the Key here since WPML returns the lang as the
// key.
$langauges = apply_filters('wpml_active_languages', NULL);
global $sitepress;
foreach ($langauges as $key => $language) {
// for each language check to see if a translation is available
// if so, use it as the match and return
// https://codex.wordpress.org/Function_Reference/get_category
// watch out for gotcha: https://wpml.org/forums/topic/how-to-get-the-translated-taxonomy-object/
$foreign_cat_id = apply_filters('wpml_object_id', $term->term_id, 'category', TRUE, $key);
//echo "$foreign_cat_id, ";
remove_filter('get_term', array($sitepress, 'get_term_adjust_id'), 1, 1);
$category_object = get_category($foreign_cat_id);
add_filter('get_term', array($sitepress, 'get_term_adjust_id'), 1, 1);
//var_dump($category_object);
foreach ($cs_headers as $key => $header) {
//print $header->post_title;
if (strtolower($header->post_title) == strtolower($category_object->name)) {
//print $category_object->name;
$match = $header->ID;
return $match;
}
}
}
add_filter('get_term', array($sitepress, 'get_term_adjust_id'), 1, 1);
}
return $match;
}
add_filter('cs_match_header_assignment', 'tb_category_header_assignment', 10, 3);
With that said PLEASE code functionality into PRO architecture that allows assignment of headers to category pages!! :slight_smile
Getting multilingual headers to work was pretty simple for simple applications. You can see it in action here with PRO http://dev.bluepresley.com/ozora/category/accommodations/
What has been a problem, and what ultimately has led us to have to advise clients to stick with X is the lack of translation support for the new WYSWYG interface. Also, in places where there were text boxes, these were not coded in a way that WPML could detect. (that may have changed though since this install is a few months old.) Hope this helps let me know if you have any questions. We’ve played with quite a few hacks to try to get ready to transition our clients from X to PRO.