Arthemia-Premium theme with Wpml

If you run a multilingual wordpress site with wmpl you’ll probably need to customize your theme files.

Adapting the basic Arthemia theme is covered on an article on wpml.org. Here you can find instructions to make Arthemia-Premium work with WPML.

If this helped you can always

If this helped, but not enough, you can try hiring me for help.

This post is based on the Arthemia customizations used in the Vino Valencia site.

Home Page Link

Relative links and links to the home page  should be fixed as per the wpml site recommendations.

This is a Search&Replace operation. In any of the theme’s files we need to replace occurences of:

  • either `get_option(’home’)` or `get_settings(’home’)`
  • with `icl_get_home_url()`

Category links

The function `get_category_link()` is replaced and extended in wpml with `icl_link_to_element()`; this function prints not only the link but also the wrapping html.

Here’s a sample patch from footer.php showing how we must make the `get_category_link` substitutions

(`-` denotes original line, `+` denotes updated line)

-       <h3 class="cat_title"><a href="<?php echo get_category_link($ar_video);?>"><?php _e('Latest Video Post','arthemia');?></a></h3>

+       <h3 class="cat_title"><?php icl_link_to_element($ar_video, 'category'); ?></h3>

`icl_link_to_element` uses the name of the category as title (i.e. instead of the original ‘Latest Video Post’). To customize the title use an additional parameter:


icl_link_to_element($ar_video, 'category', __('Latest Video Post','arthemia'))

Category listings

A few componentes of Arthemia Premium use a foreach loop over an array of categories. To get the translated categories instead of the categories of the default language we need to add some wpml magic.

Here’s a sample substitution from the category bar in header.php :

(using the same patch notation as before)


sort($postcat);

foreach ($postcat as $cp_pC ) { ?>

-

-    <?php query_posts("showposts=1&cat=$cp_pC"); ?>

+

+    <?php $cp_pC = icl_object_id($cp_pC, 'category');

+     query_posts("showposts=1&cat=$cp_pC"); ?>

<div id="cat-<?php echo $cp_pC; ?>" class="category" onclick="window.location.href='<?php echo get_category_link($cp_pC);?>';">

We tell WPML to get the Id of the translated category before moving on with the `query_posts()` call. Places that need this fix applied can be found searching for occurrences of `foreach ($postcat as $cp_pC )`. The category bar and the spoilers are two of such places (in header.php and sidebar.php respectively).

Random posts

Random posts are selected in arthemia using a customized sql query. We must  join that query with wpml tables to limit the selected post to the current language. These changes serve as templates  for any other custom sql query a custom Arthemia-Premium may have implemented. Here is the patch for this change (taken from the `filter_queries` function in the sitepress class):

-    <?php $randompost = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY RAND() LIMIT 12");

+    <?php $randompost = $wpdb->get_results("SELECT ID FROM $wpdb->posts p

+            JOIN ".$wpdb->prefix."icl_translations t ON p.ID = t.element_id

+            WHERE p.post_status = 'publish' AND p.post_type = 'post' AND t.language_code='".ICL_LANGUAGE_CODE."'

+            LIMIT 12");

+

+    shuffle($randompost);

We `shuffle()` the posts array instead of including `ORDER BY RAND()` in the query.

Colors on the category bar

A tricky change. It can get confusing as the colors are only linked to the category ids in the default language; so you must translate some of the category id and let others unchanged.

I advise to replace the full `for` loop in header.php with the updated one  here:


for( $cp_i = 1; $cp_i <= $cp_max; $cp_i ++ ) {

$cp_catCol = get_settings( "cp_catColor" );

$cp_iCol = get_settings( "cp_hexColor_" . $cp_i );

$cp_tCol = get_settings( "cp_textColor_" . $cp_i );

$cp_hCol = get_settings( "cp_hoverColor_" . $cp_i );

if( ($cp_iCol != "") || ($cp_tCol != "")  ) { ?>

/* category bar */

#cat-<?php echo icl_object_id(get_settings( "cp_colorCategory_" . $cp_i ),'category'); ?> { border-top:8px solid <?php echo $cp_iCol ?>; color:<?php echo

$cp_tCol ?>; }

#cat-<?php echo icl_object_id(get_settings( "cp_colorCategory_" . $cp_i ),'category'); ?>:hover { background:<?php echo $cp_iCol ?>; color:<?php echo $cp

_hCol ?>; }

/* sidebar */

#sidebar h3.catt-<?php echo icl_object_id(get_settings( "cp_colorCategory_" . $cp_i ),'category'); ?>  {background:<?php echo $cp_iCol ?>; color:<?php ec

ho $cp_catCol ?>; }

#sidebar h3.catt-<?php echo icl_object_id(get_settings( "cp_colorCategory_" . $cp_i ),'category'); ?> a { color:<?php echo $cp_catCol ?>; }

<?php } } ?>

Note how `icl_object_id` is used only to complete the css class `catt-`.

This entry was posted in Notes and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared.

Subscribe without commenting