';
}
}
add_action( 'wp_head', 'bastille_pingback_header' );
/**
* Override the default title length on the front_page
*/
function bastille_max_title_length( $title ) {
if ( is_front_page() ) {
$max = 60;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). " …";
} else {
return $title;
}
}
return $title;
}
add_filter( 'the_title', 'bastille_max_title_length');
/**
* Override the default excerpt length
* @link https://wordpress.org/support/topic/changing-excerpt-length/
*/
function new_excerpt_length($length) {
return 25;
}
add_filter('excerpt_length', 'new_excerpt_length');
function bastille_new_excerpt_length($max_char, $more_link_text = '...',$notagp = false, $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);
/*
* USEFUL IN TEST MODE
*
if (""==$content) {
$content = "Non a vel turpis tincidunt rhoncus magna mattis! Integer ac, lacus, elit. Et ac est cursus, etiam mus adipiscing auctor, elit vel mid mattis! Pid facilisis! Tincidunt. Lorem dictumst dapibus, tincidunt placerat vel dolor rhoncus rhoncus mid velit massa. Scelerisque! Porttitor placerat auctor a, turpis adipiscing et magna eros pulvinar aliquam aliquam enim pulvinar cum lorem tempor pulvinar cum. Dolor, a magnis, ultrices dis, tincidunt sed, adipiscing vel ridiculus. In augue tristique";
}
*
*/
if (isset($_GET['p']) && strlen($_GET['p']) > 0) {
if($notagp) {
echo $content;
}
else {
// echo '
';
echo $content;
// echo "
";
}
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
if($notagp) {
echo $content;
echo $more_link_text;
}
else {
echo $content;
echo $more_link_text;
}
}
else {
if($notagp) {
echo $content;
}
else {
echo $content;
}
}
}
/**
* Dealig with submenu items
*/
class Multilevel_Menu extends Walker_Nav_Menu
{
function start_lvl(&$output, $depth = 0, $args = array())
{
$indent = str_repeat("\t", $depth);
$output .= "\n$indent\n";
}
function end_lvl(&$output, $depth = 0, $args = array())
{
$indent = str_repeat("\t", $depth);
$output .= "$indent
\n";
}
// adding arrow to top-menu
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
if ( !$element )
return;
$id_field = $this->db_fields['id'];
//display this element
if ( is_array( $args[0] ) )
$args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
//Adds the 'parent' class to the current item if it has children
if( ! empty( $children_elements[$element->$id_field] ) ) {
array_push($element->classes,'has-dropdown not-click');
//$element->title .= ' ';
}
$cb_args = array_merge( array(&$output, $element, $depth), $args);
call_user_func_array(array(&$this, 'start_el'), $cb_args);
$id = $element->$id_field;
// descend only when the depth is right and there are childrens for this element
if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
foreach( $children_elements[ $id ] as $child ){
if ( !isset($newlevel) ) {
$newlevel = true;
//start the child delimiter
$cb_args = array_merge( array(&$output, $depth), $args);
call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
}
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
}
unset( $children_elements[ $id ] );
}
if ( isset($newlevel) && $newlevel ){
//end the child delimiter
$cb_args = array_merge( array(&$output, $depth), $args);
call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
}
//end this element
$cb_args = array_merge( array(&$output, $element, $depth), $args);
call_user_func_array(array(&$this, 'end_el'), $cb_args);
}
}
/**
* This functions prints a group of button for browsing through the other pages
* The pagination logic is inspired from WP Page Numbers plugin and and article of * Codular.
*
* @link https://wordpress.org/plugins/wp-page-numbers
* @link http://codular.com/implementing-pagination
*/
function bastille_pagination($count_post, $paged)
{
$pagingString = "';
endif;
echo $pagingString;
}
/**
* This functions prints a breadcrumb
* The script is inspired from a Quality Trust article
*
* @link http://www.qualitytuts.com/wordpress-custom-breadcrumbs-without-plugin/
*/
if(!function_exists('bastille_custom_breadcrumbs')) {
function bastille_custom_breadcrumbs() {
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$delimiter = '/'; // delimiter between crumbs
$home = __('Home','bastille'); // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = ''; // tag before the current crumb
$after = ''; // tag after the current crumb
global $post;
$homeLink = home_url();
if (is_home() || is_front_page()) {
if ($showOnHome == 1) echo '' . $home . '';
} else {
echo '' . $home . '';
if ( is_category() ) {
$thisCat = get_category(get_query_var('cat'), false);
if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, '');
echo $before . single_cat_title('', false) . $after;
} elseif ( is_search() ) {
echo $before . '"' . get_search_query() . '"' . $after;
} elseif ( is_day() ) {
echo '' . get_the_time('Y') . '';
echo '' . get_the_time('F') . '';
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo '' . get_the_time('Y') . '';
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
//echo '' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) echo '' . $before . get_the_title() . $after;
} else {
$cat = get_the_category();
if(count($cat)>0){
$cat = $cat[0];
$cats = get_category_parents($cat, TRUE, '');
if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
echo $cats;
}
if ($showCurrent == 1) echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, '');
echo '' . $parent->post_title . '';
if ($showCurrent == 1) echo '' . $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
if ($showCurrent == 1) echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
echo $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) echo '';
}
if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
} elseif ( is_tag() ) {
echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $before . __('Articles posted by ','bastille') . $userdata->display_name . $after;
} elseif ( is_404() ) {
echo $before .__('Error 404','bastille') . $after;
}
}
}
/*
* Print social links
*
*/
function bastille_social_links() {
$socials = array('facebook','twitter','youtube','github');
foreach($socials as $social){
$id = $social.'_url';
if(""!=get_theme_mod($id)){
echo '';
}
}
}
}
/*
* Getters for customizer options
*
*/
function bastille_get_events_label(){
return get_theme_mod( 'events_label' );
}
function bastille_get_events_page(){
return get_theme_mod( 'events_page' );
}
function bastille_get_programmes_label(){
return get_theme_mod( 'programmes_label' );
}
function bastille_get_programmes_page(){
return get_theme_mod( 'programmes_page' );
}
/*
* Override the default post_thumbnail() content
*
*/
function bastille_get_attachment_id_from_src( $image_src ) {
global $wpdb;
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
$id = $wpdb->get_var($query);
return $id;
}
function bastille_get_first_image($post_id) {
$post = get_post($post_id);
$post_content = $post->post_content;
preg_match_all('//i', $post_content, $matches);
if(0';
}
}
return $html;
}
add_filter('post_thumbnail_html', 'bastille_modify_post_thumbnail_html', 10, 5);
/*
* Check if thumbnail or firstImage exist
*
*/
function bastille_has_post_thumbnail_or_image(){
global $post;
$first_img = bastille_get_first_image($post->ID);
if(!has_post_thumbnail())
if (empty( $first_img ) ){
return false;
}
return true;
}
/**
* Add Thumbnail Column to Post Listing
*/
add_image_size( 'admin-list-thumb', 80, 80, false );
function bastille_add_thumbnail_columns( $columns ) {
if ( !is_array( $columns ) )
$columns = array();
$new = array();
foreach( $columns as $key => $title ) {
if ( $key == 'title' ) // Put the Thumbnail column before the Title column
$new['featured_thumb'] = __( 'Image','bastille');
$new[$key] = $title;
}
return $new;
}
function bastille_add_thumbnail_columns_data( $column, $post_id ) {
switch ( $column ) {
case 'featured_thumb':
echo '';
echo the_post_thumbnail( 'admin-list-thumb' );
echo '';
break;
}
}
if ( function_exists( 'add_theme_support' ) ) {
add_filter( 'manage_posts_columns' , 'bastille_add_thumbnail_columns' );
add_action( 'manage_posts_custom_column' , 'bastille_add_thumbnail_columns_data', 10, 2 );
}
/*
* Force WordPress to display future posts
*
*/
function bastille_show_future_posts($posts)
{
global $wp_query, $wpdb;
if(is_single() && $wp_query->post_count == 0)
{
$posts = $wpdb->get_results($wp_query->request);
}
return $posts;
}
add_filter('the_posts', 'bastille_show_future_posts');
/*
* Customize the comments with this fallback
*
*/
function bastille_custom_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
echo '