2022-07-19 00:27:21 +02:00
< ? php
2021-02-18 14:09:56 +01:00
2022-07-08 16:30:53 +02:00
//wp_set_password( 'testhangar', 1 );
load_theme_textdomain ( 'hangar' , TEMPLATEPATH . '/languages' );
/* add support for thumbnails */
2021-02-18 14:09:56 +01:00
if ( function_exists ( 'add_theme_support' ) )
add_theme_support ( 'post-thumbnails' );
if ( function_exists ( 'add_image_size' ) ) {
add_image_size ( 'artists-thumb' , 200 , 230 , true ); //200x230
add_image_size ( 'obres-thumb' , 136 , 102 , true ); //per a les galeries de les obres
}
// Path constants
define ( 'THEMELIB' , TEMPLATEPATH . '/library' );
// Create widgetitzed sidebars
require_once ( THEMELIB . '/widgetized-sidebars.php' );
// Comments extensions
require_once ( THEMELIB . '/comments-extensions.php' );
// Comments extensions
require_once ( THEMELIB . '/breadcrumb.php' );
// Create custom posts and custom fields
require_once ( THEMELIB . '/custom-posts.php' );
2022-07-19 00:27:21 +02:00
function hangar_excerpt_length ( $length ) {
2021-02-18 14:09:56 +01:00
return 20 ;
}
2022-07-19 00:27:21 +02:00
add_filter ( 'excerpt_length' , 'hangar_excerpt_length' );
2021-02-18 14:09:56 +01:00
2022-07-19 00:27:21 +02:00
function hangar_excerpt_more ( $more ) {
2021-02-18 14:09:56 +01:00
global $post ;
return '<a href="' . get_permalink ( $post -> ID ) . '"> [...]</a>' ;
}
2022-07-19 00:27:21 +02:00
add_filter ( 'excerpt_more' , 'hangar_excerpt_more' );
2021-02-18 14:09:56 +01:00
// custom login screen i peu de l'admin
function custom_login () {
echo '<link rel="stylesheet" type="text/css" href="' . get_template_directory_uri () . '/custom-login/custom-login.css" />' ;
}
add_action ( 'login_head' , 'custom_login' );
function remove_footer_admin () {
echo 'Custom text | Copyright © message' ;
}
add_filter ( 'admin_footer_text' , 'remove_footer_admin' );
//per imprimir el content sense que ens tregui l'html
function get_the_content_with_formatting ( $more_link_text = '(...)' , $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 = substr ( $content , 0 , 400 );
return $content ;
}
//afegir estils a l'editor
/* Custom CSS styles on WYSIWYG - Start
======================================= */
if ( ! function_exists ( 'myCustomTinyMCE' ) ) :
function myCustomTinyMCE ( $init ) {
$init [ 'theme_advanced_buttons2_add_before' ] = 'styleselect' ; // Adiciona os botões no incio da linha. (theme_advanced_buttons2_add adiciona-os no fim da linha)
$init [ 'theme_advanced_styles' ] = 'Centrar text=centertext,Text blau=textblau,Lletra petita=petita,Icona PDF=pdficon' ; // Especifica os estilos a aplicar pela selectbox acima criada, e que já estão definidos no mycustomstyles.css, altere e/ou acrescente os seus.
return $init ;
}
endif ;
add_filter ( 'tiny_mce_before_init' , 'myCustomTinyMCE' );
add_filter ( 'mce_css' , 'tdav_css' );
// incluir o CSS no tema.
function mycustomStyles (){
// time stamp for caching
// https://developer.wordpress.org/reference/functions/wp_enqueue_style/#comment-2056
wp_enqueue_style ( 'myCustomStyles' , get_template_directory_uri () . '/css/styleHangar.css' , array (), filemtime ( get_template_directory () . '/css/styleHangar.css' ), false );
}
add_action ( 'init' , 'myCustomStyles' );
/* Custom CSS styles on WYSIWYG - End
======================================= */
/**
* Tests if any of a post ' s assigned categories are descendants of target categories
*
* @ param int | array $cats The target categories . Integer ID or array of integer IDs
* @ param int | object $_post The post . Omit to test the current post in the Loop or main query
* @ return bool True if at least 1 of the post ' s categories is a descendant of any of the target categories
* @ see get_term_by () You can get a category by name or slug , then pass ID to this function
* @ uses get_term_children () Passes $cats
* @ uses in_category () Passes $_post ( can be empty )
* @ version 2.7
* @ link http :// codex . wordpress . org / Function_Reference / in_category #Testing_if_a_post_is_in_a_descendant_category
*/
function post_is_in_descendant_category ( $cats , $_post = null )
{
foreach ( ( array ) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children ( ( int ) $cat , 'category' );
if ( $descendants && in_category ( $descendants , $_post ) )
return true ;
}
return false ;
}
//end function testing descendent categories
function is_page_child ( $post , $idp )
{
//497 = artistes residents
$prova = $post -> post_parent ;
if ( $prova == $idp ) :
return true ;
else :
return false ;
endif ;
$idp = null ;
}
//per saber si una categoria té subcategories
function has_subcategories ( $catt )
{
$child_cats = get_term_children ( $catt , 'category' );
$childs = count ( $child_cats );
if ( $childs > 0 ) :
return true ;
else :
return false ;
endif ;
}
2022-07-19 00:27:21 +02:00
//construim un panell de control a l'administració per a que vegin les que estan marcades per a sortir a la home
2021-02-18 14:09:56 +01:00
function menu_control_home (){
add_menu_page ( " Control Home " , " Control Home " , " add_users " , " control_home " , " control_home " , " " , 6 );
}
function control_home (){
global $wpdb ;
$querystr = "
SELECT wposts . post_name , wposts . ID , users . user_login , m1 . meta_value as inicio , m2 . meta_value as orden
FROM $wpdb -> posts wposts
INNER JOIN $wpdb -> postmeta m1 ON wposts . ID = m1 . post_id
INNER JOIN $wpdb -> postmeta m2 ON wposts . ID = m2 . post_id
INNER JOIN $wpdb -> users users ON wposts . post_author = users . ID
WHERE ( wposts . post_type = 'post' OR wposts . post_type = 'page' )
AND m1 . meta_key = 'Inici'
AND m1 . meta_value = '1'
AND m2 . meta_key = 'Ordre_inici'
GROUP BY ID
ORDER BY inicio DESC , CAST ( orden AS SIGNED ) ASC
" ;
echo ' < div id = " wpbody-content " >
< div class = " wrap " >< h2 > Control Home </ h2 >< br /></ div > ' ;
$pageposts = $wpdb -> get_results ( $querystr , OBJECT );
if ( $pageposts ) :
global $post ;
echo " <table class= \" wp-list-table widefat fixed posts \" cellspacing= \" 0 \" >
< thead >
< tr >
< th scope = 'col' width = '150' class = 'manage-column column-slug sortable desc' > Nombre Post </ th >
< th scope = 'col' class = 'manage-column column-slug sortable desc' > Id </ th >
< th scope = 'col' class = 'manage-column column-slug sortable desc' > Autor Post </ th >
< th scope = 'col' class = 'manage-column column-slug sortable desc' > Inicio </ th >
< th scope = 'col' class = 'manage-column column-slug sortable desc' > Orden </ th >
</ tr >
</ thead >
< tbody id = \ " the-list \" > " ;
foreach ( $pageposts as $post ) :
$nom = $post -> post_name ;
$id = $post -> ID ;
$autor = $post -> user_login ;
$inici = $post -> inicio ;
$ordre = $post -> orden ;
echo " <tr>
< td >< a href = 'post.php?post=$id&action=edit' class = \ " row-tittle \" > $nom </a></td>
< td > $id </ td >
< td > $autor </ td >
< td > $inici </ td >
< td > $ordre </ td >
</ tr > " ;
endforeach ;
echo " </tbody></table></div> " ;
endif ;
}
add_action ( " admin_menu " , " menu_control_home " );
// Filtre que modifica la funcio que mostra els menús, per poder seleccionar mitjançant el camp title, quines seràn links i quines no.
// title= no_link -> no es un link
// title != no_link -> es un link
// wp_includes -> nav-menu-template.php, es on es trova la clase que s'esta modificant
class my_Walker_Nav_Menu extends Walker_Nav_Menu {
/**
* @ see Walker :: start_el ()
* @ since 3.0 . 0
*
* @ param string $output Passed by reference . Used to append additional content .
* @ param object $item Menu item data object .
* @ param int $depth Depth of menu item . Used for padding .
* @ param int $current_page Menu item ID .
* @ param object $args
*/
function start_el ( & $output , $item , $depth = 0 , $args = array (), $id = 0 )
{
global $wp_query ;
$indent = ( $depth ) ? str_repeat ( " \t " , $depth ) : '' ;
$class_names = $value = '' ;
$classes = empty ( $item -> classes ) ? array () : ( array ) $item -> classes ;
$classes [] = 'menu-item-' . $item -> ID ;
$class_names = join ( ' ' , apply_filters ( 'nav_menu_css_class' , array_filter ( $classes ), $item , $args ) );
$class_names = ' class="' . esc_attr ( $class_names ) . '"' ;
$id = apply_filters ( 'nav_menu_item_id' , 'menu-item-' . $item -> ID , $item , $args );
$id = strlen ( $id ) ? ' id="' . esc_attr ( $id ) . '"' : '' ;
$output .= $indent . '<li' . $id . $value . $class_names . '>' ;
if ( ! empty ( $item -> attr_title ) && ( $item -> attr_title == 'no_link' ))
{
$attributes = '' ;
}
else
{
$attributes = ! empty ( $item -> attr_title ) ? ' title="' . esc_attr ( $item -> attr_title ) . '"' : '' ;
$attributes .= ! empty ( $item -> target ) ? ' target="' . esc_attr ( $item -> target ) . '"' : '' ;
$attributes .= ! empty ( $item -> xfn ) ? ' rel="' . esc_attr ( $item -> xfn ) . '"' : '' ;
$attributes .= ! empty ( $item -> url ) ? ' href="' . esc_attr ( $item -> url ) . '"' : '' ;
}
$item_output = $args -> before ;
$item_output .= '<a' . $attributes . '>' ;
$item_output .= $args -> link_before . apply_filters ( 'the_title' , $item -> title , $item -> ID ) . $args -> link_after ;
$item_output .= '</a>' ;
$item_output .= $args -> after ;
$output .= apply_filters ( 'walker_nav_menu_start_el' , $item_output , $item , $depth , $args );
}
}
?>
< ? php
/* Code that preserves HTML formating to the automatically generated Excerpt. */
/* Also modifies the default excerpt_length and excerpt_more filters. */
// https://stackoverflow.com/questions/15283948/wordpress-html-tags-strip-on-manual-excerpt
function custom_wp_trim_excerpt ( $text = '' ) {
$raw_excerpt = $text ;
if ( '' == $text ) {
//Retrieve the post content.
$text = get_the_content ( '' );
//Delete all shortcode tags from the content.
$text = strip_shortcodes ( $text );
$text = apply_filters ( 'the_content' , $text );
$text = str_replace ( ']]>' , ']]>' , $text );
$allowed_tags = '<strong>,<em>,<b>,<i>,<p>,<a>' ; /*** MODIFY THIS. Add the allowed HTML tags separated by a comma.***/
$twopart_tags = '<strong>,<em>,<b>,<i>,<p>,<a>' ; /*** MODIFY THIS. Add the twopart HTML tags separated by a comma.***/
/* turn tag list into one big search pattern */
$search_patterns = " / " . str_replace ( " , " , " | " , str_replace ( " > " , " [^>]*> " , $twopart_tags )) . '/' ;
$text = strip_tags ( $text , $allowed_tags );
$excerpt_word_count = 200 ; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/
$excerpt_length = apply_filters ( 'excerpt_length' , $excerpt_word_count );
2022-07-19 00:27:21 +02:00
$excerpt_end = '<a href="' . get_permalink ( $post -> ID ) . '"> [...]</a>' ; /*** MODIFY THIS. change the excerpt endind to something else.***/
2021-02-18 14:09:56 +01:00
$excerpt_more = apply_filters ( 'excerpt_more' , ' ' . $excerpt_end );
$words = preg_split ( " /[ \n \r \t ]+/ " , $text , $excerpt_length + 1 , PREG_SPLIT_NO_EMPTY );
if ( count ( $words ) > $excerpt_length ) {
array_pop ( $words );
$text = implode ( ' ' , $words );
$text = $text . $excerpt_more ;
} else {
$text = implode ( ' ' , $words );
};
/* if fragment ends in open tag, trim off */
preg_replace ( " /<[^>]* $ / " , " " , $text );
/* search for tags in excerpt */
preg_match_all ( $search_patterns , $text , $matches );
/* if any tags found, check for matching pairs */
$tagstack = array ( " " );
$tagsfound = $matches [ 0 ];
while ( count ( $tagsfound ) > 0 ) {
$tagmatch = array_shift ( $tagsfound );
/* if it's a closing tag, hooray; but if it's not, then look for the closer */
if ( ! strpos ( $tagmatch , " </ " ) && ! strpos ( $tagmatch , " /> " ) ) {
preg_match ( " / \ pL+/ " , $tagmatch , $tagwords );
$endtag = " </ " . $tagwords [ 0 ] . " > " ;
/* if this tag was not closed, put the closing tag on the stack */
if ( ! in_array ( $endtag , $tagsfound ) ) {
array_push ( $tagstack , $endtag );
};
};
};
/* if any unbalanced tags were found, add the closing tags */
while ( count ( $tagstack ) > 1 ) {
$text = $text . array_pop ( $tagstack );
}
}
return apply_filters ( 'wp_trim_excerpt' , $text , $raw_excerpt );
}
remove_filter ( 'get_the_excerpt' , 'wp_trim_excerpt' );
add_filter ( 'get_the_excerpt' , 'custom_wp_trim_excerpt' );
?>