cleaned up code and unified the calls for short content and excerpt

This commit is contained in:
jorge-vitrubio 2022-09-23 19:09:38 +02:00
parent 5a096b4e4e
commit a63aa3d923
4 changed files with 169 additions and 189 deletions

View File

@ -1,8 +1,4 @@
<li id="post-<?php the_ID(); ?>" <?php echo 'class ="boxentry ' . $tipus; if (in_category("destacado")) echo ' destacat'; echo '"'; ?>>
<?php //echo $category; ?>
<?php //echo $tipus; ?>
<!-- les pàgines fixes (no categories ni artistes) -->
<?php if ((!$category) and ($tipus == 'pag')) : ?>
<article class="not-category tipus-pag">
@ -10,12 +6,10 @@
<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>
<div class="contingut plus">
<?php
//funció que està a functions.php permet mostrar links i html del contingut, client ho volia
// $contingut = get_the_content_with_formatting();
$contingut = the_excerpt();
echo $contingut;
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php the_excerpt(); ?>
</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>
@ -43,7 +37,7 @@
<br />
<?php echo __(get_post_meta($post->ID, 'autor_data_resid', true)) ?>
</p>
<?php else : ?>
<?php else : ?>
<p class="meta box novista"></p>
<?php endif; ?>
<?php else : ?>
@ -51,14 +45,14 @@
<?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>
<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';?>" />
<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; ?>
@ -72,7 +66,7 @@
<?php endif; ?>
</div>
</article>
<!-- EQUIP i MATRONAT -->
<!-- EQUIP i MATRONAT -->
<?php elseif ((!$category) and ($tipus == 'equip')):
$lang = qtrans_getLanguage();
if($lang == 'ca'): $carrec = get_post_meta($post->ID, 'carrec', true);
@ -82,116 +76,116 @@
$email = get_post_meta($post->ID, 'email', true);
$telefon = get_post_meta($post->ID, 'telefon', true);
?>
<article class="not-category tipus-eqip tipus-matronat">
<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>
<p class="carrec"><?php echo $carrec; //echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($carrec); ?> </p>
</div>
<p class="boxcurta"><?php echo $telefon; ?> </p>
<p class="meta box"><?php echo $email; ?> </p>
<article class="not-category tipus-eqip tipus-matronat">
<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>
<p class="carrec"><?php echo $carrec; //echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($carrec); ?> </p>
</div>
<p class="boxcurta"><?php echo $telefon; ?> </p>
<p class="meta box"><?php echo $email; ?> </p>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?>
</a>
<?php else : ?>
<img class="noimatge gran" width="200" height="150" title="imatge no disponible" alt="imatge no disponible" src="<?php echo get_template_directory_uri() .'/images/noimatge.jpg';?>" />
<?php endif; ?>
<?php if (has_excerpt()) : ?>
<p class="excerptbox"><?php the_excerpt();//echo get_the_excerpt(); ?></p>
<?php else :?>
<div class="contingut curt"><?php echo hangar_trim_excerpt(); ?></div>
<?php endif; ?>
</article>
<!-- els descarregables -->
<?php elseif ((!$category) and ($tipus == 'desc')): ?>
<article class="not-category tipus-descarregables tipus-desc">
<div class="head-entry">
<?php if (is_home()) : ?>
<span class='cat'>
<a href="<?php echo get_permalink(136);?>"><?php echo get_the_title(136);?></a>
</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>
<?php else : ?>
<img class="noimatge gran" width="200" height="150" title="imatge no disponible" alt="imatge no disponible" src="<?php echo get_template_directory_uri() .'/images/noimatge.jpg';?>" />
<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;?>
</div>
<div class="contingut llarg">
<?php the_content(); ?>
</div>
<!-- la fletxeta link al post/pàgina -->
<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>
<!-- els quadrets link a la categoria pare -->
<?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 ?>
<?php endif; ?>
</div>
<?php if (has_excerpt()) : ?>
<p class="excerptbox"><?php echo get_the_excerpt(); ?></p>
<?php else :?>
<div class="contingut curt"><?php echo custom_wp_trim_excerpt(); ?></div>
</article>
<!-- resta de categories -->
<?php else :
// echo " category " . $category . " catt2 " . $catt2 . " category 0 " . $category[0]->term_id;?>
<article class="category">
<div class="head-entry">
<?php if (is_home()) : ?>
<span class="cat">
<a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a>
</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 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>
</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>
<?php else : ?>
<?php //echo get_permalink(); ?>
<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; ?>
</article>
<!-- els descarregables -->
<?php elseif ((!$category) and ($tipus == 'desc')): ?>
<article class="not-category tipus-descarregables tipus-desc">
<div class="head-entry">
<?php if (is_home()) : ?>
<span class='cat'>
<a href="<?php echo get_permalink(136);?>"><?php echo get_the_title(136);?></a>
</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>
<?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>
<?php endif;?>
</div>
<div class="contingut llarg">
<?php the_content(); ?>
</div>
<!-- la fletxeta link al post/pàgina -->
<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>
<!-- els quadrets link a la categoria pare -->
<?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 ?>
<?php endif; ?>
</div>
</article>
<!-- resta de categories -->
<?php else :
// echo " category " . $category . " catt2 " . $catt2 . " category 0 " . $category[0]->term_id;?>
<article class="category">
<div class="head-entry">
<?php if (is_home()) : ?>
<span class="cat">
<a href="<?php echo get_category_link( $category[0]->term_id );?>"><?php echo $category[0]->name;?></a>
</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 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>
</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>
<?php else : ?>
<?php //echo get_permalink(); ?>
<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>
</div>
<?php
$lang = qtrans_getLanguage();
if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )):
?>
<p class="meta box">
<?php
$lang = qtrans_getLanguage();
if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )):
echo get_post_meta($post->ID, 'data_activitat', true);
if (get_post_meta($post->ID, 'horari_activitat', true)) echo " / ".get_post_meta($post->ID, 'horari_activitat', true);
if (get_post_meta($post->ID, 'lloc_activitat', true)) echo " - ".get_post_meta($post->ID, 'lloc_activitat', true);
?>
</p>
<?php
elseif($lang == 'es' and (get_post_meta($post->ID, 'data_activitatES', true) )):
?>
<p class="meta box">
<?php
echo get_post_meta($post->ID, 'data_activitat', true);
echo get_post_meta($post->ID, 'data_activitatES', true);
if (get_post_meta($post->ID, 'horari_activitat', true)) echo " / ".get_post_meta($post->ID, 'horari_activitat', true);
if (get_post_meta($post->ID, 'lloc_activitat', true)) echo " - ".get_post_meta($post->ID, 'lloc_activitat', true);
?>
</p>
<?php
elseif($lang == 'es' and (get_post_meta($post->ID, 'data_activitatES', true) )):
elseif($lang == 'en' and (get_post_meta($post->ID, 'data_activitatEN', true) )):
?>
<p class="meta box">
<?php
echo get_post_meta($post->ID, 'data_activitatES', true);
echo get_post_meta($post->ID, 'data_activitatEN', true);
if (get_post_meta($post->ID, 'horari_activitat', true)) echo " / ".get_post_meta($post->ID, 'horari_activitat', true);
if (get_post_meta($post->ID, 'lloc_activitat', true)) echo " - ".get_post_meta($post->ID, 'lloc_activitat', true);
?>
</p>
<?php
elseif($lang == 'en' and (get_post_meta($post->ID, 'data_activitatEN', true) )):
?>
<p class="meta box">
<?php
echo get_post_meta($post->ID, 'data_activitatEN', true);
if (get_post_meta($post->ID, 'horari_activitat', true)) echo " / ".get_post_meta($post->ID, 'horari_activitat', true);
if (get_post_meta($post->ID, 'lloc_activitat', true)) echo " - ".get_post_meta($post->ID, 'lloc_activitat', true);
?>
</p>
<?php else: ?>
<?php else: ?>
<p class="meta box novista"><?php // echo __('Publicat el ','hangar') . the_time('d F Y') ?></p>
<?php endif;?>
@ -207,15 +201,15 @@
<div class="contingut">
<p class="excerptbox">
<?php
// echo get_the_excerpt();
// https://developer.wordpress.org/reference/functions/wp_trim_words/
echo wp_trim_words(get_the_excerpt(), 60,' <a href="'. get_permalink($post->ID) . '">[...]</a>')
?>
</p>
</div>
// echo get_the_excerpt();
// https://developer.wordpress.org/reference/functions/wp_trim_words/
echo wp_trim_words(get_the_excerpt(), 60,' <a href="'. get_permalink($post->ID) . '">[...]</a>')
?>
</p>
</div>
<?php else :?>
<div class="contingut curt">
<?php echo custom_wp_trim_excerpt(); ?>
<?php echo hangar_trim_excerpt(); ?>
</div>
<?php endif; ?>
@ -227,5 +221,5 @@
<?php endif;?>
</div>
<?php endif; ?>
</article>
</li><!-- post .hentry -->
</article>
</li><!-- post .hentry -->

View File

@ -28,17 +28,6 @@ require_once(THEMELIB . '/breadcrumb.php');
// Create custom posts and custom fields
require_once(THEMELIB . '/custom-posts.php');
function hangar_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'hangar_excerpt_length');
function hangar_excerpt_more($more) {
global $post;
return '<a href="'. get_permalink($post->ID) . '"> [...]</a>';
}
add_filter('excerpt_more', 'hangar_excerpt_more');
// 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" />';
@ -52,50 +41,6 @@ echo 'Custom text | Copyright &copy; message';
add_filter('admin_footer_text', 'remove_footer_admin');
//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 = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
// output max 400 characters
$content = substr($content, 0,400);
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
/* Custom CSS styles on WYSIWYG - Start
@ -117,6 +62,8 @@ wp_enqueue_style( 'myCustomStyles', get_template_directory_uri() . '/css/styleHa
}
add_action('init', 'myCustomStyles');
/* Custom CSS styles on WYSIWYG - End
======================================= */
/**
@ -297,11 +244,61 @@ class my_Walker_Nav_Menu extends Walker_Nav_Menu {
}
?>
<?php
/*
* all the_excerpt() and short content to be shown in the theme
*/
// 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 = '') {
// $content = get_the_content($more_link_text, $stripteaser, $more_file);
// $content = apply_filters('the_content', $content);
// $content = str_replace(']]>', ']]&gt;', $content);
// // output max 400 characters
// $content = substr($content, 0,200);
// return $content;
// }
//
// formatting the_excertp()
//
function hangar_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'hangar_excerpt_length');
//
function hangar_excerpt_more($more) {
global $post;
return '<a href="'. get_permalink($post->ID) . '"> [...]</a>';
}
add_filter('excerpt_more', 'hangar_excerpt_more');
//
// https://wordpress.stackexchange.com/a/112651
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><em>'); //write tags allowed removed img so the_post_thumbnail() is shown
$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;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'hangar_html_excerpt');
/* 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='') {
function hangar_trim_excerpt($text='') {
$raw_excerpt = $text;
if ( '' == $text ) {
//Retrieve the post content.
@ -320,7 +317,7 @@ if ( '' == $text ) {
$text = strip_tags($text, $allowed_tags);
$excerpt_word_count = 200; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/
$excerpt_word_count = 20; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/
$excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
$excerpt_end = '<a href="'. get_permalink($post->ID) . '"> [...]</a>'; /*** MODIFY THIS. change the excerpt endind to something else.***/
@ -365,5 +362,5 @@ if ( '' == $text ) {
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');
add_filter('get_the_excerpt', 'hangar_trim_excerpt');
?>

View File

@ -26,7 +26,6 @@ get_header(); ?>
<p class="excerptbox"><?php echo get_the_excerpt(); ?></p>
<?php else : ?>
<div class="contentcurt">
<?php //echo get_the_content_with_formatting(); ?>
<?php the_content(); ?>
</div>
<?php endif; ?>

View File

@ -14,7 +14,7 @@ get_header(); ?>
<div id="main">
<div id="content" class="indexall">
<!-- la primera caixa és la de títol i descripció de la pàgina pare i hi haurà resum del contingut de la pàgina -->
<?php // la primera caixa és la de títol i descripció de la pàgina pare i hi haurà resum del contingut de la pàgina ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
@ -25,22 +25,12 @@ get_header(); ?>
<?php if ( has_post_thumbnail() ) : // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumbnail'); ?>
<p class="excerptbox"><?php echo get_the_excerpt(); ?></p>
<p class="excerptbox"><?php the_excerpt(); ?></p>
<?php else : ?>
<div class="contentcurt"><?php echo get_the_content_with_formatting(); ?></div>
<div class="contentcurt">
<?php echo hangar_trim_excerpt();?>
</div>
<?php endif; ?>
<?php
/* echo '<div class="descseccio">';
global $more;
$more = 0;//The code must be inserted ahead of the call to the content
the_content('Continue Reading');
$more = true;
echo '</div>';*/ ?>
<!--<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 // the_content( sprintf( __( 'Continue reading %1$s', 'hybrid' ), the_title( ' "', '"', false ) ) ); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links pages">' . __( 'Pages:', 'hangar' ), 'after' => '</p>' ) ); ?>
</div><!-- .entry-content -->
</div><!-- post .hentry -->