Come fare in modo che il filtro excerpt_more si applichi all'effettivo estratto del post?
Nella funzione get_blog_excerpt() qui sotto, il filtro excerpt_more funziona perfettamente quando l'estratto del post non è presente, tuttavia, quando il post ha un estratto, non ottengo il link "Leggi tutto".
Capisco che the_excerpt prima controlla se è presente un estratto del post, il che va bene, ma voglio che anche ad esso venga applicato il link "Leggi tutto".
Cosa devo cambiare per fare in modo che excerpt_more si applichi in tutti i casi?
function get_blog_excerpt(){
add_filter('excerpt_length', 'ce4_excerpt_length');
add_filter('excerpt_more', 'ce4_excerpt_more');
return the_excerpt();
}
function ce4_excerpt_length($length) {
return 150;
}
function ce4_excerpt_more($more) {
global $post;
return '...<a href="'. get_permalink($post->ID) . '">Leggi tutto</a>';
}
function get_blog_links(){
global $post;
setup_postdata($post);
$myposts = get_posts($args);echo '<div id="menuFooterRecent" class="blog">';
echo '<ul>';
foreach($myposts as $idx=>$post){ ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
echo get_blog_excerpt();
echo '<div style="clear:both"> </div>';?></li>
<?php } echo '</ul></div>';
}
Il codice sopra si trova all'interno di functions.php
Il codice qui sotto si trova all'interno di archive.php
<?php
if(is_category()){
if (get_query_var('cat') == get_category_by_slug('blog')->term_id){
get_blog_links();
}
else
{
get_category_links();
}
} ?>

Suppongo che tu stia chiamando get_blog_excerpt()
da qualche parte nel tuo template?
Se è così, cosa succede se chiami semplicemente the_excerpt()
e poi estrai le due chiamate add_filter()
dalla funzione contenitore? Cioè functions.php
avrebbe questo aspetto:
function ce4_excerpt_length($length) {
return 150;
}
add_filter('excerpt_length', 'ce4_excerpt_length');
function ce4_excerpt_more($more) {
global $post;
return '...<a href="'. get_permalink($post->ID) . '">Continua a leggere</a>';
}
add_filter('excerpt_more', 'ce4_excerpt_more');
E nel tuo template, dovresti semplicemente chiamare the_excerpt()
.
Se questo funziona, allora sospetto che il problema sia che i tuoi filtri non vengono applicati - probabilmente perché sono racchiusi nella funzione contenitore.

Chip, grazie per il suggerimento. Ma spostare i filtri al di fuori del contenitore non sembra avere alcun effetto sullo script. Funziona allo stesso modo in ogni caso.

get_blog_excerpt viene chiamato da una funzione all'interno di functions.php, che a sua volta viene chiamata da una funzione al di fuori del loop in archive.php
