changed excerpt in category when long length goes out of the box, specially in arxives category

This commit is contained in:
jorge 2022-07-19 00:27:21 +02:00
parent d8adf6c3a6
commit b2c2e3cd65
3 changed files with 239 additions and 351 deletions

View File

@ -1,7 +1,7 @@
<li id="post-<?php the_ID(); ?>" <?php echo 'class ="boxentry ' . $tipus; if (in_category("destacado")) echo ' destacat'; echo '"'; ?>> <li id="post-<?php the_ID(); ?>" <?php echo 'class ="boxentry ' . $tipus; if (in_category("destacado")) echo ' destacat'; echo '"'; ?>>
<!-- <?php echo $category; ?> --> <?php //echo $category; ?>
<!-- <?php echo $tipus; ?> --> <?php //echo $tipus; ?>
<!-- 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')) : ?>
@ -127,30 +127,54 @@
// 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"> <div class="head-entry">
<?php if (is_home()) : ?> <?php if (is_home()) : ?>
<span class='cat'> <span class="cat">
<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>
<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> <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 if (has_subcategories($catt2)) : ?> <?php if (has_subcategories($catt2)) : ?>
<span class='cat'> <!-- atenció cal assingar cada post a la subcategoria, sinó sortirà la categoria pare --> <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> <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 else : ?>
<!-- <?php echo get_permalink(); ?> --> <?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> <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;?>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php $lang = qtrans_getLanguage(); <?php
$lang = qtrans_getLanguage();
if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )): if($lang == 'ca' and (get_post_meta($post->ID, 'data_activitat', true) )):
?><p class="meta box"><?php 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 ?>
<p class="meta box">
<?php
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) )): elseif($lang == 'es' and (get_post_meta($post->ID, 'data_activitatES', true) )):
?><p class="meta box"><?php 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 ?>
<p class="meta box">
<?php
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 == 'en' and (get_post_meta($post->ID, 'data_activitatEN', 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_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: ?> <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: ?>
<p class="meta box novista"><?php // echo __('Publicat el ','hangar') . the_time('d F Y') ?></p> <p class="meta box novista"><?php // echo __('Publicat el ','hangar') . the_time('d F Y') ?></p>
<?php endif;?> <?php endif;?>
@ -158,14 +182,19 @@
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail'); ?> <?php the_post_thumbnail('thumbnail'); ?>
</a> </a>
<?php else : ?>
<!--<img class="noimatge" 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 endif; ?>
<?php if (has_excerpt()) : ?>
<p class="excerptbox"><?php echo get_the_excerpt(); ?></p> <?php
if (has_excerpt()) : ?>
<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>
<?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; ?>
<div class="boxpeu" > <div class="boxpeu" >

View File

@ -29,13 +29,15 @@ get_header(); ?>
</div><!-- .entry-content --> </div><!-- .entry-content -->
</div><!-- post .boxentry --> </div><!-- post .boxentry -->
</div><!-- .indexall.wide --> </div><!-- .indexall.wide -->
<?php $catt2 = get_query_var('cat'); ?> <?php $catt2 = get_query_var('cat'); ?>
<div id="content" class="indexall fills"> <div id="content" class="indexall fills">
<ul> <ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $tipus = 'catt'; <?php
$tipus = 'catt';
$category = get_the_category(); $category = get_the_category();
?> ?>
@ -44,18 +46,18 @@ get_header(); ?>
<?php endwhile; ?> <?php endwhile; ?>
</ul> </ul>
</div><!-- .indexall.fills -->
<?php wp_pagenavi(); /* kriesi_pagination();*/?> <?php wp_pagenavi(); /* kriesi_pagination();*/?>
<?php else: ?> <?php else: ?>
<p class="no-data"> <p class="no-data">
<?php _e( 'Apologies, but no results were found.', 'hangar' ); ?> <?php _e( 'Apologies, but no results were found.', 'hangar' ); ?>
</p><!-- .no-data --> </p><!-- .no-data -->
</div><!-- .indexall.fills -->
<?php endif; ?> <?php endif; ?>
</div><!-- .indexall.fills -->
</div><!--end #main--> </div><!--end #main-->

View File

@ -28,123 +28,29 @@ require_once(THEMELIB . '/breadcrumb.php');
// Create custom posts and custom fields // Create custom posts and custom fields
require_once(THEMELIB . '/custom-posts.php'); require_once(THEMELIB . '/custom-posts.php');
function new_excerpt_length($length) { function hangar_excerpt_length($length) {
return 20; return 20;
} }
add_filter('excerpt_length', 'new_excerpt_length'); add_filter('excerpt_length', 'hangar_excerpt_length');
function new_excerpt_more($more) { function hangar_excerpt_more($more) {
global $post; global $post;
return '<a href="'. get_permalink($post->ID) . '"> [...]</a>'; return '<a href="'. get_permalink($post->ID) . '"> [...]</a>';
} }
add_filter('excerpt_more', 'new_excerpt_more'); add_filter('excerpt_more', 'hangar_excerpt_more');
// custom login screen i peu de l'admin // custom login screen i peu de l'admin
function custom_login() { function custom_login() {
//echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('template_directory').'/custom-login/custom-login.css" />';
// time stamp for caching
// https://developer.wordpress.org/reference/functions/wp_enqueue_style/#comment-2056
echo '<link rel="stylesheet" type="text/css" href="'. get_template_directory_uri() .'/custom-login/custom-login.css" />'; echo '<link rel="stylesheet" type="text/css" href="'. get_template_directory_uri() .'/custom-login/custom-login.css" />';
} }
add_action('login_head', 'custom_login'); add_action('login_head', 'custom_login');
//function change_wp_login_url() {
//echo bloginfo('url');
//}
//add_filter('login_headerurl', 'change_wp_login_url');
//function change_wp_login_title() {
//echo 'Powered by ' . get_option('blogname');
//}
//add_filter('login_headertitle', 'change_wp_login_title');
function remove_footer_admin () { function remove_footer_admin () {
echo 'Custom text | Copyright &copy; message'; echo 'Custom text | Copyright &copy; message';
} }
add_filter('admin_footer_text', 'remove_footer_admin'); add_filter('admin_footer_text', 'remove_footer_admin');
// THIS GIVES US SOME OPTIONS FOR STYLING THE ADMIN AREA
function custom_controls() {
// echo '<style type="text/css">
// label.lateral{width: 100px;}
// input.lateral{width: 150px; border-color: #ddd;}
// .petit {width: 20px!important;}
// label.dd{float:left; width:250px;}
// input.dd{width:450px;}
// </style>';
}
add_action('admin_head', 'custom_controls');
/* create calendar event when saving post with dates */
// function create_event( $post_id ) {
//
// // If this is just a revision, don't send the email.
// if ( wp_is_post_revision( $post_id ) )
// return;
//
// $myPost = get_post($post_id);
// if (has_category(array('news', 'activitats-dels-residents'), $post_id) &&
// !$update &&
// $myPost->post_modified_gmt == $myPost->post_date_gmt) {
//
// //The URL that we want to send a PUT request to.
// $uid = get_the_guid( $post_id );
// $url = 'https://cloud.hangar.org/remote.php/dav/calendars/hangar/hangar_activitats/neu.ics';
// $headers = array('Content-Type: text/calendar', 'charset=utf-8');
// $userpwd = 'hangar:AV63xlklCuOJgYTnHz5smX4chiAaDpJo';
// $description = get_the_content( $post_id );
// $summary = get_the_title( $post_id );
// $tstart = gmdate("Ymd\THis\Z", strtotime("-2 days"));
// $tend = gmdate("Ymd\THis\Z", strtotime("-2 days"));
// $tstamp = gmdate("Ymd\THis\Z");
//
// // vcalendar
// $body = 'BEGIN:VCALENDAR
// VERSION:2.0
// BEGIN:VEVENT
// DTSTAMP:$tstamp
// DTSTART:$tstart
// DTEND:$tend
// UID:$uid
// DESCRIPTION:$description
// LOCATION:Hangar
// SUMMARY:$summary
// END:VEVENT
// END:VCALENDAR';
//
// //Initiate cURL
// $ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
// //curl_setopt($ch, CURLOPT_PUT, true);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
// curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//
// //Execute the request.
// $response = curl_exec($ch);
// curl_close($ch);
//
// // send confirmation mail
// $post_title = $summary;
// $post_excerpt = $description;
// $post_url = get_permalink( $post_id );
// $subject = 'A new EVENT post has been saved';
//
// $message = "A new post has been created on your website:\n\n";
// $message .= $post_title . ": " . $post_url . "\n\n";
// $message .= $post_excerpt . "\n\n";
// $message .= $uid . "\n\n";
// $message .= print_r($response);
//
// // Send email to admin.
// wp_mail( 'gerald@hangar.org', $subject, $message );
// }
// }
// add_action( 'save_post', 'create_event', 10, 3 );
//per imprimir el content sense que ens tregui l'html //per imprimir el content sense que ens tregui l'html
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 = '') {
@ -154,24 +60,6 @@ function get_the_content_with_formatting ($more_link_text = '(...)', $striptease
$content = substr($content, 0,400); $content = substr($content, 0,400);
return $content; return $content;
} }
//per imprimir l'excerpt indicant un nombre de caràcters màxim
// function the_excerpt_max_charlength($charlength) {
// $excerpt = get_the_excerpt();
// $charlength++;
// if(strlen($excerpt)>$charlength) {
// $subex = substr($excerpt,0,$charlength-5);
// $exwords = explode(" ",$subex);
// $excut = -(strlen($exwords[count($exwords)-1]));
// if($excut<0) {
// echo substr($subex,0,$excut);
// } else {
// echo $subex;
// }
// echo "[...]";
// } else {
// echo $excerpt;
// }
// }
//afegir estils a l'editor //afegir estils a l'editor
@ -248,7 +136,7 @@ function has_subcategories($catt)
endif; endif;
} }
//contruim un panell de control a l'administració per a que vegin les que estan marcades per a sortir a la home //construim un panell de control a l'administració per a que vegin les que estan marcades per a sortir a la home
function menu_control_home(){ function menu_control_home(){
add_menu_page( "Control Home","Control Home", "add_users", "control_home", "control_home", "", 6 ); add_menu_page( "Control Home","Control Home", "add_users", "control_home", "control_home", "", 6 );
} }
@ -374,37 +262,6 @@ class my_Walker_Nav_Menu extends Walker_Nav_Menu {
<?php <?php
/* Code that preserves HTML formating to the automatically generated Excerpt. */ /* Code that preserves HTML formating to the automatically generated Excerpt. */
/* Also modifies the default excerpt_length and excerpt_more filters. */ /* Also modifies the default excerpt_length and excerpt_more filters. */
/*function custom_wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]&gt;', $text);
//Add the allowed HTML tags separated by a comma.
$allowed_tags = '<p>,<a>,<em>,<strong>';
$text = strip_tags($text, $allowed_tags);
//Change the excerpt word count.
$excerpt_word_count = 60;
$excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
//Change the excerpt ending.
$excerpt_end = ' <a href="'. get_permalink($post->ID) . '">' . '&raquo; Continue Reading.' . '</a>';
$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);
}
}*/
// https://stackoverflow.com/questions/15283948/wordpress-html-tags-strip-on-manual-excerpt // https://stackoverflow.com/questions/15283948/wordpress-html-tags-strip-on-manual-excerpt
function custom_wp_trim_excerpt($text='') { function custom_wp_trim_excerpt($text='') {
@ -429,7 +286,7 @@ if ( '' == $text ) {
$excerpt_word_count = 200; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/ $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); $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
$excerpt_end = '[...]'; /*** MODIFY THIS. change the excerpt endind to something else.***/ $excerpt_end = '<a href="'. get_permalink($post->ID) . '"> [...]</a>'; /*** MODIFY THIS. change the excerpt endind to something else.***/
$excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);