wordpress/php-fpm/wordpress_files/themes/sustrai-twentytwelve/functions.php

122 lines
4.4 KiB
PHP
Raw Normal View History

2020-05-22 03:40:23 +02:00
<?php
/* Overwrite polylang default query that just query posts in current language.
// We also show just a language, but we include post in other language without traslation to current.
// at index.php and other templates.
*/
//add_filter('parse_query', 'show_mixed_languages');
//function show_mixed_languages($query) {
// $query->set( 'lang', '' );
// $query->set( 'cat', '-29, -94' );
//}
// DEBUG QUERY
//add_filter( 'posts_request', 'dump_request' );
//
//function dump_request( $input ) {
// var_dump($input);
// return $input;
//}
// MIXED LANGUAGES STRATEGY
// When in not default language, We show post in that language and
//the post in default language that do no have translation.
/* Polylang uses the action parse_query which is fired before pre_get_posts so $query->set( 'lang', '' ); can't work. */
//add_filter('pre_get_posts', 'get_default_language_posts', 1);
/* So parse_query */
add_filter('parse_query', 'get_default_language_posts', 1);
function get_default_language_posts($query) {
if ($query->is_main_query() && function_exists('pll_default_language') && !is_admin()) {
$terms = get_terms('post_translations'); //polylang stores translated post IDs in a serialized array in the description field of this custom taxonomy
$defLang = pll_default_language(); //default lanuage of the blog
$curLang = pll_current_language(); //current selected language requested on the broswer
//echo ".....".$defLang;
//echo ".....".$curLang;
$filterPostIDs = array(); // discarded posts
foreach ($terms as $translation) { // if there is no translations $terms has no elements, and do not exclude any.
$transPost = unserialize($translation->description);
//if the current language is not the default, lets pick up the default language post
if ($defLang != $curLang) {
$filterPostIDs[] = $transPost[$defLang];
}
}
if ($defLang != $curLang) {
/*echo "_";*/
$query->set( 'lang', '' );
//$query->set('lang', $curLang . ',' . $defLang); //select both default and current language post
$query->set('post__not_in', $filterPostIDs); // remove the duplicate post in the default language
}
}
# Discard some cats
if ( $query->is_main_query() && $query->is_home() ) {
$query->set( 'cat', '-29, -94' ); // Discard some categories (boletin and boletina).
}
}
if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
/**
* Set up post entry meta.
* Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
* Create your own twentytwelve_entry_meta() to override in a child theme.
* @since Twenty Twelve 1.0
*/
function twentytwelve_entry_meta($ID) {
// Translators: used between list items, there is a space after the comma.
$categories_list = '<span class="post-cats">'.get_the_category_list( __( ', ', 'twentytwelve' ) ).'</span>';
// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
$date = sprintf( '<span class="the_date">%1$s</span>', esc_html( get_the_date() ) );
$author = sprintf( '<span class="author vcard">%1$s</span>', get_the_author() ) ;
$curr_l = pll_current_language();
if ($curr_l == 'es'):
$alt_l = 'eu';
else:
$alt_l = 'es';
endif;
$translations = pll_the_languages( array( 'raw' => 1 , 'post_id' => $ID ) );
$home_alt = pll_home_url($alt_l);
$link_alt = $translations[$alt_l]['url'];
if ($link_alt != $home_alt):
$link_translation = sprintf('<a href="%1$s"><span class="langsw-post"><span class="langsw-post">%2$s</span></a>',$link_alt, $alt_l);
endif;
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
if ( $tag_list ) {
$utility_text = __( 'Ths entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
} elseif ( $categories_list ) {
$utility_text = __( '%5$s %3$s - %1$s ' , 'twentytwelve' );
} else {
$utility_text = __( 'his entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
}
printf(
$utility_text,
$categories_list,
$tag_list,
$date,
$author,
$link_translation
);
}
endif;
add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li id="searchli" >' . get_search_form( false ) . '</li>';
return $items;
}