From a63aa3d9234213196f202cdd9f57939197f12437 Mon Sep 17 00:00:00 2001
From: jorge-vitrubio
Date: Fri, 23 Sep 2022 19:09:38 +0200
Subject: [PATCH] cleaned up code and unified the calls for short content and
excerpt
---
caixes.php | 224 +++++++++++++++----------------
functions.php | 113 ++++++++--------
page-templates/seccions-wide.php | 1 -
page-templates/seccions.php | 20 +--
4 files changed, 169 insertions(+), 189 deletions(-)
diff --git a/caixes.php b/caixes.php
index cb0acaa..ef3ff5f 100644
--- a/caixes.php
+++ b/caixes.php
@@ -1,8 +1,4 @@
>
-
-
-
-
@@ -10,12 +6,10 @@
@@ -43,7 +37,7 @@
ID, 'autor_data_resid', true)) ?>
-
+
@@ -51,14 +45,14 @@
+
+
+
+
+
-
+
@@ -72,7 +66,7 @@
-
+
ID, 'carrec', true);
@@ -82,116 +76,116 @@
$email = get_post_meta($post->ID, 'email', true);
$telefon = get_post_meta($post->ID, 'telefon', true);
?>
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+term_id;?>
+
+
+
+
+
+ name;?>
+
+
+
+
+
+ name;?>
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- term_id;?>
-
-
-
-
-
- name;?>
-
-
-
-
-
- name;?>
-
-
-
-
-
-
-
-
+
+ ID, 'data_activitat', true) )):
+ ?>
+
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);
+ ?>
+
+ ID, 'data_activitatES', true) )):
?>
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);
?>
ID, 'data_activitatES', true) )):
+ elseif($lang == 'en' and (get_post_meta($post->ID, 'data_activitatEN', true) )):
?>
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);
?>
- ID, 'data_activitatEN', true) )):
- ?>
-
- 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);
- ?>
-
-
+
@@ -207,15 +201,15 @@
ID) . '">[...]')
- ?>
-
-
+ // echo get_the_excerpt();
+ // https://developer.wordpress.org/reference/functions/wp_trim_words/
+ echo wp_trim_words(get_the_excerpt(), 60,' [...] ')
+ ?>
+
+
-
+
@@ -227,5 +221,5 @@
-
-
+
+
diff --git a/functions.php b/functions.php
index bdb7a4f..ec8e63c 100644
--- a/functions.php
+++ b/functions.php
@@ -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 ' [...] ';
-}
-add_filter('excerpt_more', 'hangar_excerpt_more');
-
// custom login screen i peu de l'admin
function custom_login() {
echo ' ';
@@ -52,50 +41,6 @@ echo 'Custom text | Copyright © 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(']]>', ']]>', $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('\]\]\>', ']]>', $text);
- $text = strip_tags($text, ''); //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 {
}
?>
', ']]>', $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 ' [...] ';
+}
+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('\]\]\>', ']]>', $text);
+ $text = strip_tags($text, ''); //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 = ' [...] '; /*** 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');
?>
diff --git a/page-templates/seccions-wide.php b/page-templates/seccions-wide.php
index c56d5ff..9a9c78d 100644
--- a/page-templates/seccions-wide.php
+++ b/page-templates/seccions-wide.php
@@ -26,7 +26,6 @@ get_header(); ?>
-
diff --git a/page-templates/seccions.php b/page-templates/seccions.php
index f311d7c..457392e 100644
--- a/page-templates/seccions.php
+++ b/page-templates/seccions.php
@@ -14,7 +14,7 @@ get_header(); ?>
-
+
@@ -25,22 +25,12 @@ get_header(); ?>
-
+
-
+
+
+
-
- ';
- global $more;
- $more = 0;//The code must be inserted ahead of the call to the content
- the_content('Continue Reading');
- $more = true;
- echo '
';*/ ?>
-
-
-
'
' . __( 'Pages:', 'hangar' ), 'after' => '
' ) ); ?>