I tested categories on really advanced stuff
I don't ask for adding new fields to the category table because this can be easily done with a little change of category name shortcode.
Default
After hover
This is code from the theme template (working code after that change in shortcode):
$COOKBOOK_CATEGORIESMENU_TEMPLATE = array();
$COOKBOOK_CATEGORIESMENU_TEMPLATE['default']['caption'] = '{COOKBOOK_CATEGORIESMENU_CAPTION}';
$COOKBOOK_CATEGORIESMENU_TEMPLATE['default']['start'] = '<div class="recipe-categories justify-content-center">';
$COOKBOOK_CATEGORIESMENU_TEMPLATE['default']['item'] = '
<a href="{COOKBOOK_CATEGORY_NAME=link}" data-animate="fadeInUp" data-delay="{THEME_DELAY}" class="recipe-category" style="background-image: url(\'{THEME_PATH}/recipes/demo/images/categories/{COOKBOOK_CATEGORY_NAME=sef}.jpg\');">
<div class="recipe-category-inner">
<div class="recipe-category-icon"><img src="{THEME_PATH}/recipes/demo/images/icons/{COOKBOOK_CATEGORY_NAME=sef}.svg" alt="{COOKBOOK_CATEGORY_NAME=title}"></div>
<div class="recipe-category-info">{COOKBOOK_CATEGORY_NAME=title}</div>
</div>
</a> ';
$COOKBOOK_CATEGORIESMENU_TEMPLATE['default']['end'] = '</div>';
Some question/suggestion:
1. I couldn't use theme shortcode in this template**
{THEME_PATH} - it is the path in the theme folder. I was used to using it (it is a global shortcode) in any template with hardcoded images. It didn't work in your template/plugin. No idea why. This is an indication that something is wrong.
Solved. The second parameter has to be true. Could you change it, please? Code above changed,
// Return render item from template
$text .= e107::getParser()->parseTemplate($this->template['item'], true, $sc);
2. your parameters naming
This type of stuff (return different values) is common and the rule should be:
- if the shortcode name is NAME (or title) then return the clean name without the parameter
- if you want to return something different, use the parameter
3. you should use the new way of parameters - array
f.e. you add class as next parameter in the future and you will need to rewrite everything
4. use common name for parameter, f.e. like in news
"link" - it is for name shortcode that returns title as link
"anchor/sef" - it is for sef url field
"title" - it is for title/name field
"no-url' is not common at all, you will never guess it without looking in the code
This is the shortcode I used:
function sc_cookbook_category_name($parm = array())
{
$category = e107::getDb()->retrieve('cookbook_categories', 'c_id, c_name, c_name_sef', 'c_id = '.$this->var['r_category']);
if($parm == 'no_url')
{
return $category['c_name'];
}
if ($parm == 'title')
{
return $category['c_name'];
}
if ($parm == 'sef')
{
return $category['c_name_sef'];
}
$urlparms = array(
'c_id' => $category['c_id'],
'c_name_sef' => $category['c_name_sef'],
);
$url = e107::url('cookbook', 'category', $urlparms);
if ($parm == 'link')
{
return $url;
}
return '<a href="'.$url.'">'.$category['c_name'].'</a>';
}
Do you know what I mean?
If you want the same result, your shortcode should be named (COOKBOOK_CATEGORY) and using the parameters to return different values.
Sometimes is full code enough, sometimes you need to split it into the name, URL, unique field etc...
If you want to split this into more shortcodes, CATEGORY_ANCHOR is the name for the shortcode that returns sef field.
This was the original HTML code for the category:
<a href="demos/recipes/recipes.html" data-animate="fadeInUp" data-delay="500" class="recipe-category" style="background-image: url('demos/recipes/images/categories/seafood.jpg');">
<div class="recipe-category-inner">
<div class="recipe-category-icon"><img src="demos/recipes/images/icons/seafood.svg" alt="Seafood"></div>
<div class="recipe-category-info">Seafood</div>
</div>
</a>