I am just creating a custom mod_menu in Joomla 3
I wonder if anyone could be so kind and explain what this block of code means since I can not find any reference to the parameter $item->params->get('aliasoptions) also what does this block of code actually do to the menu item? - (line 37 - code taken from default.php in tmpl folder from mod_menu)
$aliasToId = $item->params->get('aliasoptions');
if (count($path) > 0 && $aliasToId == $path[count($path) - 1])
{
$class .= ' active';
}
elseif (in_array($aliasToId, $path))
{
$class .= ' alias-parent-active';
}
Any explanation to this would be most helpful, I am wondering if it's actually needed?
Thats the corresponding function from the helper.php
case 'alias':
// If this is an alias use the item id stored in the parameters to make the link.
$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
break;
So if you look at the function in default.php you will see this piece of code:
foreach ($list as $i => &$item) :
$class = 'item-'.$item->id;
and following with an if clause and after that the code you are asking for.
So what it basically does (in my understanding):
Use the item id defined in itemparameters (basically its just the item id xD ) if the link is just an alias for another menu item. Without it Joomla shouldnt be able to set the correct active menu links.
You can set Menu Item Aliases by choosing them in the Menu Item Type selection: "System Links -> Menu Item Alias", when creating or editing menu items ;)
I hope this helps ^^
Related
I have a Drupal commerce website with about 100 000 products. Now customer wants me to change product image filenames and add alternative(alt) texts to images for all existing products - based product names and colors.
File field paths seemed to be great to changing the file names of image files. But I just cannot figure out how to add alt texts to images automatically. I've been trying hook_file_update, hook_file_presave, hook_entity_presave etc. I'm trying to add alt text during File field paths' batch update and all of the hooks are running but for some reason alt text data is not saved to entity.
Product image field is type of Image with Media browser widget.
Any help for this?
Here's hook_entity_presave() code:
if ($entity->type == 'image' && (empty($entity->alt) || empty($entity->field_file_image_alt_text))) {
$product = _get_referenced_product($entity->fid);
if ($product) {
$full_product = commerce_product_load($product->product_id);
$title = $full_product->title;
if (!empty($full_product->field_search_color)) {
$search_color = $full_product->field_search_color[LANGUAGE_NONE][0]['tid'];
$search_color = taxonomy_term_load($search_color);
$color_name = $search_color->name;
}
$entity->alt = $title . ' ' .ucfirst($color_name);
$entity->field_file_image_alt_text = $title . ' ' .ucfirst($color_name);
object_log('Entity', $entity);
object_log('Type', $type);
}
}
I had the same issue and I updated the alt tag of all images in my articles. Note, in my case I wanted to updated nodes.
And, I used following code:
https://www.gyanblog.com/gyan/34-how-add-alt-attribute-images-all-my-drupal-articles-or-other-content-type/
Actually the problem in my case was that I was trying to set alt field value in wrong way. "Field_file_image_alt_text" field the image element is using is a normal textfield so it clearly needs the following data structure.
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['value'] = $title . ' ' .ucfirst($color_name);
$file->field_file_image_alt_text[LANGUAGE_NONE][0]['safe_value'] = $title . ' ' .ucfirst($color_name);
So just a stupid mistake by me! And btw, I ended up using hook_file_presave() hook.
How can I show the full text of a leading article (even if it contains a read more) on a Category Blog Layout?
Is there a back-end setting I can change or which PHP file do I need to overwrite? I only want the leading article's fulltext to show, intro articles should still display the readmore with only intro text.
Thanks in advance.
You don't specify which version of Joomla! so this reply is based on 2.5.x
You will need to create a layout override for com_content, specifically for the category view tmpl file blog.php or blog_item.php.
If your template already has an override installed for com_content you will find it at this location:
/templates/your-template/html/com_content/category/
If not you can copy the original files from your Joomla! 2.5's component directory at /components/com_content/views/category/tmpl/
In that directory you will find a series of files starting with blog and ending with .php - you can override 1 or all of these by coping them to the first path listed above. N.B. Only copy the files you need to change Joomla! is smart enough to look in the default directory if it doesn't find a version in the overrides location.
The default Joomla! 2.5 installation has these blog files:
blog_children.php
blog_item.php
blog_links.php
blog.php
Basically blog.php is the main file and it includes the sub-layouts like blog_item.php as required.
If you're working from the default Joomla! 2.5 files, to achieve your goal you will probably have to override blog.php and blog_item.php and find a way to check whether you are in the leading item. Once you know that your in a leading item you will then want to echo out the full text of the item.
blog_item.php normally just outputs the intro text with a line like this:
<?php echo $this->item->introtext; ?>
You'll want to have the full text echo'd so after you've wrapped the line above in an if to check if you're doing the leading item your output line will look something like this:
<?php echo $this->item->introtext.$this->item->fulltext; ?>
Note: I've haven't check this works it's just speculation and relies on the $item having the full row from the #__content table.
So the articles full text isn't added to the article item in a standard install i.e. you can simply echo $this->item->fulltext.
There are two ways to get the full text.
The simplest & first is to modify the core file at /components/com_content/models/articles.php starting with the first $query->select() in the function getListQuery() which starts on/near line 153. Add ' a.fulltext,' after the a.introtext and before the single apostrophe, so the line looks like this:
function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' .
'a.checked_out, a.checked_out_time, ' .
The second way, and the Joomla! update proof way (& therefore probably the better way) is to load the entire article in the override (ugly but it's not a hack) and concatenate the fulltext to the introtext of the first article.
To do this you simply use getTable to load the article using the $this->item->id in blog.php for the first leading item, so at about line 54, between the <?php and the $this->item = &$item; put:
if($leadingcount == 0) {
$contentTable = JTable::getInstance('Content');
if($contentTable->load($item->id)) {
$item->introtext .= $contentTable->fulltext;
}
}
N.B. The if just limits it to the first leading article, if you remove the if it will attach the full text for all leading articles.
This works on my dev installation of Joomla! 2.5.6 so you should be able to do it as well.
Considering the two answers above, there are three changes required to blog.php and blog_item.php. This works in Joomla 3.1 The best is to copy these files to the template override
copy blog.php and blog_item.php
from components/com_content/views/category/tmpl/
to [my template]/html/com_content/category/
In blog.php in the loop for the leading items add one single line:
<?php foreach ($this->lead_items as &$item) : ?>
<div class="leading-<?php echo ...?>">
<?php
$this->item = &$item;
$this->item->leadingItem = true; //ADD THIS LINE !!!
echo $this->loadTemplate('item');
?>
</div>
<div class="clearfix"></div>
<?php
$leadingcount++;
?>
<?php endforeach; ?>
In the blog_item.php replace "echo $this->item->introtext;" with
if ($this->item->leadingItem){
//this is a leading article - show full text and remove "Read more..." button
$itemID = $this->item->id;
$db =& JFactory::getDBO();
$query = "SELECT `fulltext` FROM `#__content` WHERE `id` =" . $itemID;
$db->setQuery($query);
$fulltext = $db->loadResult();
echo $this->item->introtext . $fulltext;
}else{
echo $this->item->introtext;
}
Finally in the blog_item.php do not to show the "Read more..." button at the bottom of each article
Edit line
if ($params->get('show_readmore') && $this->item->readmore)
into
if ($params->get('show_readmore') && $this->item->readmore &&
!$this->item->leadingItem)
Joomla 2.5.x, in your template blog_item.php:
$itemID = $this->item->id;
$db =& JFactory::getDBO();
$query = "
SELECT `fulltext`
FROM `#__content`
WHERE `id` = $itemID;
";
$db->setQuery($query);
$fulltext = $db->loadResult();
and you can use the $fulltext string variable.
I have custom Joomla(v1.5) component and currently working with component's router. The problem is I can't remove id numbers from SEF url. I get:
http://myaddress.com/componentalias/17-city-alias/130-item-alias
What I want to get:
http://myaddress.com/componentalias/city-alias/item-alias
Take a look at router.php methods below:
function ComponentnameBuildRoute(&$query) {
$segments = array();
if(isset($query['city_id'])){
$segments[] = $query['city_id'];
unset($query['city_id']);
}
if(isset($query['item_id'])){
$segments[] = $query['item_id'];
unset($query['item_id']);
}
if(isset($query['task'])){
switch($query['task']){
case 'pay':
$segments[] = JText::_('payment');
unset($query['task']);
break;
}
}
unset($query['view']);
return $segments;
}
/*
* Function to convert a SEF URL back to a system URL
*/
function ComponentnameParseRoute($segments) {
$var = array();
if(isset($segments[0])){
$cityData = explode(':',$segments[0]);
if(isset($cityData[0])){
$vars['city_id'] = $cityData[0];
}
}
if(isset($segments[1])){
$itemData = explode(':',$segments[1]);
if(isset($itemData[0])){
$vars['item_id'] = $itemData[0];
}
}
if(isset($segments[2])){
switch($segments[2]){
case JText::_('payment'):
$vars['task'] = 'pay';
break;
}
}
return $vars;
}
Any ideas? Your help would be appreciated.
The best place to start with your router.php file is reading this article (it's a bit dated but still good) and then reviewing the com_content's router.php file (components/com_content/router.php). You will notice that articles do achieve what you want so best to look at working code and got from there.
Longer answer:
You can only get rid of the item ID variables in a path to a content element if a menu item exists that points directly to the item, otherwise there is no way to find the item.
SEF URLs in Joomla! 1.5 etc are made from the alias' of the individual elements
eg. If I have this menu structure:
Recipes (The menu)
-- Seafood (<-- Category blog where category alias is `seafood` )
-- Grilled Snapper (<-- Recipe Item where item alias is `grilled-snapper` )
-- 'Other category' (<-- Another Category blog )
Full ID Removal
In the case where you're building the SEF URL for a recipe you can build the route by looking for the menu item it might appear in by getting the site menu $menu = &JSite::getMenu(); and comparing the query id in the current menu item against id value in the $query array passed in.
If you have a match you can build the segments up using the alias from the menu path and the recipe alias. (And reverse the process in your ParseRoute($segments) method).
So, from this example above you could build a SEF URL to the Grilled Snapper recipe that looks something like: recipes/seafood/grilled-snapper.
Partial ID Removal
Now say you also have another recipe (e.g. 'Garlic Prawns' alias garlic-prawns) that isn't directly linked to a menu but will appear in the 'Seafood' category blog page. In this situation you would end up with recipes/seafood/2:garlic-prawns
If you don't have a match (like the Garlic Prawns), you can build up partial match if your component has list views like category blogs or in our example Recipe category pages... Essentially in this case you look at the current menu item and determine if it's a list/category view that would contain the content item.
If it is then the path to the category/list view form you initial segments, but as there is no menu item for the article you will still have to use the ID of the item in the last element of the URL.
No Menu Item for content item or a list/category view
When the content item is being linked to directly (e.g. from an article, module or search result) and there are no menu items that point to it or could contain it then you can still create a URL without id's in it but you will be providing the path in the form of direct component access URL.
eg. /component/recipes/recipe/ice-cream-sundae where recipes is the name of the component, recipe is the view and ice-cream-sundae is the alias of the article.
We know that Joomla 1.6 and up has access levels groups settings but this little hack could help everyone from 1.5 and up
this there outputs the params from specific Joomla menu item
$menus = &JSite::getMenu();
print_r($menus ->_items[170]);
where 170 are the parameters for menu item id 170 , now
there is a setting called published , what I am trying to achieve is show menu item to visitors only by globally setting the $menus ->_items[170]->published to 0 instead 1 when user is logged in
but changing that array value is hard so if you could please just check if you can change the value output from 1 to 0 by using provided info.
f we can get that to work than code snippet could be something like
if ( !$user->id ) {
$menus = &JSite::getMenu(); $menus ->_items[170]->set('published',0); }
but set() does not work for menu item id's
Thank you!
Why not just set the menu item access to registered in the menu parameters? Then the item only displays when the user is logged in. This is a built in behavior in Joomla.
I have my website working on social engine, I have a Main page named as articles.tpl, and in that I have a sub-page named as article.tpl, article.tpl is used to show the entire article, and articles.tpl is used to show topics of articles not the content,
My concern is with articles.tpl(pretty confusing articles and article)
In articles.tpl, 3 articles title, author of article and date is displayed, but I also want to display the category of that article,
For that I tried the following code,
$article_category = "";
$parent_category = "";
$article_category_query = $database->database_query("SELECT articlecat_id, articlecat_title, ".
"articlecat_dependency FROM se_articlecats WHERE articlecat_id='".
$rc_article->article_info[article_articlecat_id]."' LIMIT 1");
if($database->database_num_rows($article_category_query) == 1) {
$article_category_info = $database->database_fetch_assoc($article_category_query);
$article_category = $article_category_info[articlecat_title];
if($article_category_info[articlecat_dependency] != 0) {
$parent_category = $database->database_fetch_assoc(
$database->database_query("SELECT articlecat_id, articlecat_title".
" FROM se_articlecats WHERE articlecat_id='".
$article_category_info[articlecat_dependency]."' LIMIT 1"));
}
}
$smarty->assign('article_category', $article_category);
and in articles.tpl file I called it in this way
<span class="tahoma11_blue">| {$article_category}</span>
But when I check I get nothing, that space is blank, I am just able to see
|
How can I display the category?
i think you have to change
$smarty->assign('categories', $categories);
to
$smarty->assign('article_category', $article_category);
(in your example, you assign the (apparently empty) php variable $categories to the smarty variable categories. then, in the template, you use a smarty variable article_category - which never got assigned)