Individual Excerpt lengths in BranfordMagazine 4
BranfordMagazine uses the excerpt template tag for auto-shortening texts on the homepage and in other areas. This is nothing spectacular since many themes do it like that. But BranfordMagazine (as of version 4.1) uses the power of WordPress 2.9x to provide a function for individual excerpt lengths. Be aware that this doesn´t work with WP versions prior to 2.9. By default this is used for shorter excerpts in the featured articles section.
How to use individual excerpt lengths
Open your functions.php file in the theme directory and look up line 38. You will see this function:
//modify the excerpt lenght in the "featured articles" section on the homepage
add_filter(‘excerpt_length’, ‘my_excerpt_length’);
function my_excerpt_length($length) {
if(in_category(4)) { // put here the ID (4 by default) of the category used for the "featured" articles
return 25; // put the number of words (default 25)
} else {
return 55; // show 55 words for any other excerpt (or change this number also)
}
}
?>
I think it´s more or less self explaining. By default (and based on my demo site) it means that the excerpt of category 4 (featured articles) is limited to 25 words. The excerpt of any other category is limited to 55 words which is the WordPress default. Now you can easily change the lenght of your excerpts just by changing the numbers 25 and/or 55 to whatever you like.
Extending the function
You can also extend this function to archieve other categories to display different excerpt lengths. Try something like this:
//modify the excerpt lenght in the "featured articles" section on the homepage
add_filter(‘excerpt_length’, ‘my_excerpt_length’);
function my_excerpt_length($length) {
if(in_category(4)) { // put here the ID (4 by default) of the category used for the "featured" articles
return 25; // put the number of words (default 25)
}
elseif(in_category(1)) { // put here the ID of the category
return 75; // put the number of words (default 25)
}
else {
return 55; // show 55 words for any other excerpt (or change this number also)
}
}
?>
It´s up to you now. Play around with it.
More Stuff from Elsewhere
Leave a Reply
Do not use this comment section for support requests. Please use the support forum for this purposes only. Comments containing support topics will be deleted without further notice!
Recent Comments
Social Media on Theme Customization easy as 1,2,3 with Firebug:
Michael, Your theme looks nice. I'm gonna play with it for a spell and ...
Michael Oeser on Setup the homepage of WyntonMagazine with categories and images:
Pardon mais je ne parle pas de francais. Please use the support forum and e...
DER PRiNZ on Setup the homepage of WyntonMagazine with categories and images:
So schwer ist das nicht, wenn man sich diesen Weg einmal angewöhnt hat. Da...
Michael Oeser on Magazine style theme for WordPress “WyntonMagazine”:
Eine Weiterentwicklung ist grundsätzlich geplant, aber es gibt noch keinen...
Ansar on Setup the homepage of WyntonMagazine with categories and images:
Oh, das ist zu schwer zu nutzen :)) Soll man jedes mal diese Aktion durch...
Ansar on Magazine style theme for WordPress “WyntonMagazine”:
Hallo, Ich woltte fragen, ob es noch weiter entwickelt werden oder nicht...
Michael Oeser on Using images on the homepage of BranfordMagazine:
As always mentioned (right here on top of the comment section) I do not pro...
Jens on Using images on the homepage of BranfordMagazine:
Is there a method to use a slideshow with the Lead Story? I've installed Ne...
Michael Oeser on How to edit the tabed interface of BranfordMagazine:
Well but I do give an example and this works similar for any tab: "This is ...
Wilfried Voss on How to edit the tabed interface of BranfordMagazine:
The options allow me to define the content of the first tab, and that's gre...