In a website I am working on ,there are 50 categories + sub categories, each has a a very long description text, then in an archive page I display all the titles of the categories + their description ,but it makes more sense to show the title of each category + a few words of each description (excerpt?) and a "read more" link ,to the full content of that category .
so I have read the codex and also a lot of articles on the Web, but still I cant understand the reason why this sort of functionality doesn't exist in WordPress by default. It exists only for posts -Function Reference/the excerpt.
Second question is what is the most elegant way to solve it ?
There are a few plugins or snippets of code that enable you to add html editor to the category description in the admin side, but selecting the read more link doesnt work there:(
Is the only solution to write a very long Hook/filter on the category_description() function ?
to elaborate: this is my code in category.php , - what is does is diplaying the parent category and all its children(titles+ full descriptions)
<?php
$CategoryPar = get_category( get_query_var( 'cat' ) );
$cat_id = $CategoryPar->cat_ID;
$args = array(
'orderby' => 'name',
'child_of' => $cat_id,
'hide_empty' => FALSE,
'order' => 'ASC'
);
$Ecategories = get_categories($args);
echo'<div class="cat-sub-title">';
foreach($Ecategories as $Ecategory) {
echo '<p><a href="' . get_category_link( $Ecategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $Ecategory->name ) . '" ' . '>' . $Ecategory->name.'</a> </p> ';
echo '<div class="cat-sub-title-desc">'. $Ecategory->description . '</div>';
}
echo'</div>';
?>
$Ecategory->description
in your code should becategory_description($Ecategory->term_id )
, then @cybmeta solution works. As to why there are not separate functions, I don't know, but my guess is is that it is really not necessary, therefor the filter for the 0.01% that needs to change the description ;-)category_description()
function and you have a working and tested answer. Not sure what more to say to help you.