changed howto show excerpt and length in caixes/secions

This commit is contained in:
jorge 2022-09-23 12:32:45 +02:00
parent f92276c903
commit 5a096b4e4e
3 changed files with 168 additions and 118 deletions

View File

@ -5,78 +5,84 @@
<!-- les pàgines fixes (no categories ni artistes) --> <!-- les pàgines fixes (no categories ni artistes) -->
<?php if ((!$category) and ($tipus == 'pag')) : ?> <?php if ((!$category) and ($tipus == 'pag')) : ?>
<h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h2> <article class="not-category tipus-pag">
<?php $contingut = get_the_content_with_formatting(); //funció que està a functions.php permet mostrar links i html del contingut, client ho volia ?> <h2 class="box <?php echo $tipus;?>">
<div class="contingut plus"> <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a>
<?php echo $contingut; ?> </h2>
</div> <div class="contingut plus">
<div class="boxpeu" > <?php
<a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a> //funció que està a functions.php permet mostrar links i html del contingut, client ho volia
</div> // $contingut = get_the_content_with_formatting();
$contingut = the_excerpt();
echo $contingut;
?>
</div>
<div class="boxpeu" >
<a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a>
</div>
</article>
<!-- els artistes --> <!-- els artistes -->
<?php elseif ((!$category) and (($tipus == 'art')) or ($tipus == 'obra')): ?> <?php elseif ((!$category) and (($tipus == 'art')) or ($tipus == 'obra')): ?>
<article class="not-category tipus-art tipus-obra tipus-artistes">
<div class="head-entry"> <div class="head-entry">
<?php if (is_home()) : ?> <?php if (is_home()) : ?>
<span class='cat'> <span class='cat'>
<a href="<?php echo get_permalink(2);?>"><?php echo get_the_title(2);?></a> <a href="<?php echo get_permalink(2);?>"><?php echo get_the_title(2);?></a>
</span> </span>
<h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h2> <h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h2>
<?php else : ?> <?php else : ?>
<h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h3> <h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h3>
<?php endif;?> <?php endif;?>
</div>
<?php if ($tipus == 'art') :?>
<?php if(get_post_meta($post->ID, 'autor_tipo_resid', true) && get_post_meta($post->ID, 'autor_data_resid', true)): ?>
<p class="meta box">
<?php echo __(get_post_meta($post->ID, 'autor_tipo_resid', true)) ?>
<br />
<?php echo __(get_post_meta($post->ID, 'autor_data_resid', true)) ?>
</p>
<?php else : ?>
<p class="meta box novista"></p>
<?php endif; ?>
<?php else : ?>
<p class="meta box"><?php echo get_post_meta($post->ID, 'data_obra', true) ?></p>
<?php endif; ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="contingut">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('artists-thumb'); ?>
<?php //the_post_thumbnail('thumbnail'); ?>
</a>
</div>
<?php else : ?>
<div class="contingut curt">
<img class="noimatge gran" width="200" height="230" title="imatge no disponible" alt="imatge no disponible" src="<?php echo get_template_directory_uri() .'/images/noimatgegran.jpg';?>" />
</div> </div>
<?php endif; ?>
<div class="boxpeu" > <?php if ($tipus == 'art') :?>
<!-- la fletxeta link al post/pàgina --> <?php if(get_post_meta($post->ID, 'autor_tipo_resid', true) && get_post_meta($post->ID, 'autor_data_resid', true)): ?>
<a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a> <p class="meta box">
<?php echo __(get_post_meta($post->ID, 'autor_tipo_resid', true)) ?>
<?php if (is_home()) : ?> <br />
<!-- els quadrets link a la categoria pare --> <?php echo __(get_post_meta($post->ID, 'autor_data_resid', true)) ?>
<a href="<?php echo get_permalink(2); ?>" class="peudret" title="<?php echo get_the_title(2); ?>" rel="bookmark"><img alt="enllaç a la categoria" src="<?php echo get_template_directory_uri() . '/images/totslink.png';?>" /></a> </p>
<?php else : ?>
<p class="meta box novista"></p>
<?php endif; ?>
<?php else : ?>
<p class="meta box"><?php echo get_post_meta($post->ID, 'data_obra', true) ?></p>
<?php endif; ?>
<?php if ( has_post_thumbnail() ) : ?>
<div class="contingut">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('artists-thumb'); ?>
<?php //the_post_thumbnail('thumbnail'); ?>
</a>
</div>
<?php else : ?>
<div class="contingut curt">
<img class="noimatge gran" width="200" height="230" title="imatge no disponible" alt="imatge no disponible" src="<?php echo get_template_directory_uri() .'/images/noimatgegran.jpg';?>" />
</div>
<?php endif; ?> <?php endif; ?>
</div> <div class="boxpeu" >
<!-- la fletxeta link al post/pàgina -->
<a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a>
<?php if (is_home()) : ?>
<!-- els quadrets link a la categoria pare -->
<a href="<?php echo get_permalink(2); ?>" class="peudret" title="<?php echo get_the_title(2); ?>" rel="bookmark"><img alt="enllaç a la categoria" src="<?php echo get_template_directory_uri() . '/images/totslink.png';?>" /></a>
<?php endif; ?>
</div>
</article>
<!-- EQUIP i MATRONAT --> <!-- EQUIP i MATRONAT -->
<?php elseif ((!$category) and ($tipus == 'equip')): <?php elseif ((!$category) and ($tipus == 'equip')):
$lang = qtrans_getLanguage(); $lang = qtrans_getLanguage();
if($lang == 'ca'): if($lang == 'ca'): $carrec = get_post_meta($post->ID, 'carrec', true);
$carrec = get_post_meta($post->ID, 'carrec', true); elseif($lang == 'es'): $carrec = get_post_meta($post->ID, 'carrecES', true);
elseif($lang == 'es'): elseif($lang == 'en'): $carrec = get_post_meta($post->ID, 'carrecEN', true);
$carrec = get_post_meta($post->ID, 'carrecES', true); endif;
elseif($lang == 'en'): $email = get_post_meta($post->ID, 'email', true);
$carrec = get_post_meta($post->ID, 'carrecEN', true); $telefon = get_post_meta($post->ID, 'telefon', true);
endif; ?>
$email = get_post_meta($post->ID, 'email', true); <article class="not-category tipus-eqip tipus-matronat">
$telefon = get_post_meta($post->ID, 'telefon', true);
?>
<div class="head-entry"> <!-- els equips només són índex, no tenen enllça a pàgina ni peu--> <div class="head-entry"> <!-- els equips només són índex, no tenen enllça a pàgina ni peu-->
<h3 class="equip <?php echo $tipus;?>"><?php the_title() ;?> </h3> <h3 class="equip <?php echo $tipus;?>"><?php the_title() ;?> </h3>
<p class="carrec"><?php echo $carrec; //echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($carrec); ?> </p> <p class="carrec"><?php echo $carrec; //echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($carrec); ?> </p>
@ -97,60 +103,66 @@
<?php else :?> <?php else :?>
<div class="contingut curt"><?php echo custom_wp_trim_excerpt(); ?></div> <div class="contingut curt"><?php echo custom_wp_trim_excerpt(); ?></div>
<?php endif; ?> <?php endif; ?>
</article>
<!-- els descarregables --> <!-- els descarregables -->
<?php elseif ((!$category) and ($tipus == 'desc')): ?> <?php elseif ((!$category) and ($tipus == 'desc')): ?>
<article class="not-category tipus-descarregables tipus-desc">
<div class="head-entry"> <div class="head-entry">
<?php if (is_home()) : ?> <?php if (is_home()) : ?>
<span class='cat'> <span class='cat'>
<a href="<?php echo get_permalink(136);?>"><?php echo get_the_title(136);?></a> <a href="<?php echo get_permalink(136);?>"><?php echo get_the_title(136);?></a>
</span> </span>
<h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h2> <h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h2>
<?php else : ?> <?php else : ?>
<h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h3> <h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title() ;?> </a> </h3>
<?php endif;?> <?php endif;?>
</div>
</div> <div class="contingut llarg">
<div class="contingut llarg"> <?php the_content(); ?>
<?php the_content(); ?> </div>
</div>
<!-- la fletxeta link al post/pàgina --> <!-- la fletxeta link al post/pàgina -->
<div class="boxpeu"> <div class="boxpeu">
<a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a> <a href="<?php the_permalink(); ?>" class="peubox" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><img alt="enllaç" src="<?php echo get_template_directory_uri() . '/images/fletxalink.png';?>" /></a>
<!-- els quadrets link a la categoria pare --> <!-- els quadrets link a la categoria pare -->
<?php if (is_home()) : ?> <?php if (is_home()) : ?>
<a href="<?php echo get_permalink(136); ?>" class="peudret" title="<?php echo get_the_title(136); ?>" rel="bookmark"><img alt="enllaç a la categoria" src="<?php echo get_template_directory_uri() . '/images/totslink.png';?>" /></a> <?php ?> <a href="<?php echo get_permalink(136); ?>" class="peudret" title="<?php echo get_the_title(136); ?>" rel="bookmark"><img alt="enllaç a la categoria" src="<?php echo get_template_directory_uri() . '/images/totslink.png';?>" /></a> <?php ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
</article>
<!-- resta de categories --> <!-- resta de categories -->
<?php else : <?php else :
// echo " category " . $category . " catt2 " . $catt2 . " category 0 " . $category[0]->term_id;?> // echo " category " . $category . " catt2 " . $catt2 . " category 0 " . $category[0]->term_id;?>
<div class="head-entry"> <article class="category">
<?php if (is_home()) : ?>
<span class="cat"> <div class="head-entry">
<a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a> <?php if (is_home()) : ?>
</span> <span class="cat">
<h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h2>
<?php else : ?>
<?php if (has_subcategories($catt2)) : ?>
<span class="cat"> <!-- atenció cal assingar cada post a la subcategoria, sinó sortirà la categoria pare -->
<a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a> <a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a>
</span> </span>
<h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h3> <h2 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h2>
<?php else : ?> <?php else : ?>
<?php //echo get_permalink(); ?> <?php if (has_subcategories($catt2)) : ?>
<h3 class="box nosub<?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h3> <span class="cat"> <!-- atenció cal assingar cada post a la subcategoria, sinó sortirà la categoria pare -->
<?php endif;?> <a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a>
<?php endif; ?> </span>
</div> <h3 class="box <?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h3>
<?php <?php else : ?>
$lang = qtrans_getLanguage(); <?php //echo get_permalink(); ?>
if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )): <h3 class="box nosub<?php echo $tipus;?>"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'hangar' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo the_title();?> </a> </h3>
<?php endif;?>
<?php endif; ?>
</div>
<?php
$lang = qtrans_getLanguage();
if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )):
?> ?>
<p class="meta box"> <p class="meta box">
<?php <?php
@ -184,20 +196,23 @@
<?php endif;?> <?php endif;?>
<?php if ( has_post_thumbnail() ) : ?> <?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <div class="contingut">
<?php the_post_thumbnail('thumbnail'); ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
</a> <?php the_post_thumbnail('thumbnail'); ?>
</a>
</div>
<?php endif; ?> <?php endif; ?>
<?php <?php if (has_excerpt()) : ?>
if (has_excerpt()) : ?> <div class="contingut">
<p class="excerptbox"> <p class="excerptbox">
<?php <?php
// echo get_the_excerpt(); // echo get_the_excerpt();
// https://developer.wordpress.org/reference/functions/wp_trim_words/ // https://developer.wordpress.org/reference/functions/wp_trim_words/
echo wp_trim_words(get_the_excerpt(), 60,' <a href="'. get_permalink($post->ID) . '">[...]</a>') echo wp_trim_words(get_the_excerpt(), 60,' <a href="'. get_permalink($post->ID) . '">[...]</a>')
?> ?>
</p> </p>
</div>
<?php else :?> <?php else :?>
<div class="contingut curt"> <div class="contingut curt">
<?php echo custom_wp_trim_excerpt(); ?> <?php echo custom_wp_trim_excerpt(); ?>
@ -212,5 +227,5 @@
<?php endif;?> <?php endif;?>
</div> </div>
<?php endif; ?> <?php endif; ?>
</article>
</li><!-- post .hentry --> </li><!-- post .hentry -->

View File

@ -53,14 +53,49 @@ add_filter('admin_footer_text', 'remove_footer_admin');
//per imprimir el content sense que ens tregui l'html //per imprimir el content sense que ens tregui l'html
//https://www.wordpressaddicted.com/wordpress-get-content-with-formatting/
function get_the_content_with_formatting ($more_link_text = '(...)', $stripteaser = 0, $more_file = '') { function get_the_content_with_formatting ($more_link_text = '(...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file); $content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content); $content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content); $content = str_replace(']]>', ']]&gt;', $content);
// output max 400 characters
$content = substr($content, 0,400); $content = substr($content, 0,400);
return $content; return $content;
} }
// formatting the excertp
// https://wordpress.stackexchange.com/a/112651
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
function hangar_html_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]&gt;', $text);
$text = strip_tags($text, '<p><b><img><em>'); //write tags allowed
$excerpt_length = 55;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return $text;
}
add_filter('get_the_excerpt', 'hangar_html_excerpt');
/**
* Filter the except length to 20 words.
* https://developer.wordpress.org/reference/functions/the_excerpt/#comment-325
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function hangar_custom_excerpt_length( $length ) {
return 10;
}
add_filter( 'excerpt_length', 'hangar_custom_excerpt_length', 999 );
//afegir estils a l'editor //afegir estils a l'editor
/* Custom CSS styles on WYSIWYG - Start /* Custom CSS styles on WYSIWYG - Start

View File

@ -797,7 +797,7 @@ span.cat a{text-transform: uppercase; letter-spacing:normal}
.boxentry .curt, .boxentry p.excerptbox {max-height: 5.6rem; height: auto/*60px*/; font-size:11.5px;} .boxentry .curt, .boxentry p.excerptbox {max-height: 5.6rem; height: auto/*60px*/; font-size:11.5px;}
.boxentry .mig {height: 195px;} .boxentry .mig {height: 195px;}
.boxentry .llarg {height: 225px;} .boxentry .llarg {height: 225px;}
.boxentry .plus {height: 331px;} .boxentry .plus {height:327px;/*height: 331px;*/}
.boxentry .plus p{display:inline;} .boxentry .plus p{display:inline;}
/* special setting for showing excerpt image */ /* special setting for showing excerpt image */