On my k2 pages I needed module complete on the top area, a module assign is not possible because the pages are dynamicly from the DB selected. So I installed a module like "loadmodule", the difference is simple I can get module with specific id.
For example: {loadmodulefromarticle|97} if I use it in the extra fields or in the content area then it works, but as written I need it in the top area of my page, so I have an if request and try load k2 content on the top. I get content and that's ok. But I see here only plain text and the module is not loaded. My question is, what is to insert here so that I get the module loaded? I think it can be something around to $result;
<?php
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '713') {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('introtext');
$query->from('#__k2_items');
$query->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
?>
<div id="gkHeaderMod">
<div><?php echo $result; ?></div>
</div>
<?php
}
?>
You could do something like the following. It uses Joomla coding standards to get the menu ID and renderModule to display the module.
<?php
$app = JFactory::getApplication();
$menuID = $app->getMenu()->getActive()->id;
if ( $menuID == '713' ) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('introtext')
->from('#__k2_items')
->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
echo '<div id="gkHeaderMod">';
$module = JModuleHelper::getModule( 'mod_example', 'Module Title' );
echo JModuleHelper::renderModule( $module );
echo '</div>';
}
?>
Note that you will have to change mod_example and Module Title to whatever you require
Related
I want to show filter of category on submenu, my code works!!
My problem is that if page are already filtered, my code does not return the options
I believe it has to do something in the code that bypasses the filter page and again bring the options in the submenu even if already have the filter on page
HTML of submenu:
{{block type="core/template" category="3" template="page/html/icons_submenu.phtml"}}
Content of page icons_submenu.phtml:
<?php
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel('catalog/category')->load($this->getCategory());
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Example:
I would really suggest you to actually move all that logic into a proper module, a proper block and a proper model and not in a template like you are doing right now.
If you actually want further help for that, feel free to ask, making something according to the coding guide lines of Magento would make you even happier of your job, I can assure you.
This being said, what you actually want is a current filter model based on the current category and a specify attribute.
You don't need to go by the block catalog/layer_filter_attribute in a way to do this, you can directly go by the model based on the layer you already load.
So, this way of doing it should work, although it should not be in a template or view, once again :
<?php
$category = Mage::getModel('catalog/category')
->load($this->getCategory());
$layer = Mage::getModel('catalog/layer')
->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'color') {
// $filterBlockName = 'catalog/layer_filter_attribute';
/** This is actually your only problem in your code **/
// $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
/** But would work with this line **/
$result = Mage::getModel('catalog/layer_filter_attribute')
->setLayer($layer)
->setAttributeModel($attribute);
echo '<strong>Color:</strong><br />';
foreach($result->getItems() as $option) {
echo ' ' . $option->getValue() . ' - ' . $option->getLabel() . '<br />';
}
}
}
?>
Then you can see it still works based on only the colours I have in the current category
But also when the category is already filtered on a specific colour
How do we render module in joomla with the title. Because now, I am able to render the module based on the position but it does not include the module title.
Here's how I render the module.
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position-3');
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module->title);
echo JModuleHelper::renderModule($module);
}
?>
Many Thanks.
Try this,
Using this method you can pass parameters to the module .
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //This is the way of passing params values
$Module->params = $Params;
echo $renderer->render($Module);
Hope it helps..
Try using the following:
foreach ($modules as $module)
{
echo $module->title;
echo JModuleHelper::renderModule($module);
}
You can also use the following, however you will have to manually enter the module title. This is only assuming you don't want it to be dynamic. You will also need to change mainmenu
$module = JModuleHelper::getModule( 'mainmenu', 'Module Title Goes Here' );
echo JModuleHelper::renderModule( $module );
Try this.
Hope this will work for you.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = '';
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM `#__modules` WHERE id = 'your module id'");
$modules = $db->loadObjectList();
$module = $modules[0];
$contents = $renderer->render($module);
I have inserted the following line into my Joomla template:
<jdoc:include type="component" />
This will bring across the whole post, including the title of the article. How can I bring the featured article title across seperate to it's body/content for styling purposes?
Thank you.
I just tested this code and it seems to work on Joomla 2.5.3:
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
echo $article->get("introtext"); // and/or fulltext
}
$catId = 80;
$query = "SELECT * FROM #__content WHERE catid ='" . $catId . "'";
$db = &JFactory::getDBO();
$db->setQuery($query);
$articles = $db->loadObjectList();
foreach($articles as $article){
$article_id=$article->id;
$article_title=$article->title;
$article_content=$article->get("introtext");
How can I add category description to Article Category modules in Joomla?
The only php call after grouping items is <?php echo $group_name; ?>.
Thanks in advance!
I know this is an old post, but for Joomla! 3.5 and higher you can use...
$category = JCategories::getInstance('Content')->get($item->catid);
Much easier than doing a call to the database in your template override files.
Add this to your default.php override.
<?php
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery('SELECT #__categories.description FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
$category = $db->loadResult();
echo $category;
?>
Put in your default.php override or custom template:
<?php // tested in Joomla 3.1.5 only
$input = JFactory::getApplication()->input;
$idbase = $params->get('catid');
$catID = $idbase[0];
//echo $catID;
$db = JFactory::getDBO();
$db->setQuery("SELECT description FROM #__categories WHERE id = ".$catID." LIMIT 1;");
$catDesc = $db->loadResult();
?>
<div class="catdesc">
<?php echo $catDesc; ?>
</div>
Modified from:
http://www.noxidsoft.com/development/get-the-category-blog-description-in-joomla-3-1-5/
So in: /modules/mod_articles_category/default.php
make sure you create an over ride first, but then add:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('id', 'title', 'description'));
$query->from($db->quoteName('#__categories'));
$query->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
$db->setQuery($query);
$categories = $db->loadObjectList('id');
just after: defined('_JEXEC') or die;
Then in each item you can load it in like:
echo $categories[$item->catid]->description;
If using on the grouping rather than item, it's a little different and here is the whole top snippet replacement:
<?php
/**
* #package Joomla.Site
* #subpackage mod_articles_category
*
* #copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('id', 'title', 'description'));
$query->from($db->quoteName('#__categories'));
$query->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
$db->setQuery($query);
$categories = $db->loadObjectList('title');
?>
<ul class="category-module<?php echo $moduleclass_sfx; ?> mod-list">
<?php if ($grouped) : ?>
<?php foreach ($list as $group_name => $group) : ?>
<li>
<div class="mod-articles-category-group"><?php echo JText::_($group_name); ?></div>
<p><?php echo count($group) > 0 ? $categories[$group_name]->description : ''; ?></p>
Because $group doesn't contain anything but the list, we get the name instead this time and load the categories from the name.
I am trying to display a category name in a module position.
I tried:
<?php echo $listing['Category']['title'];?>
It did not work.
I followed this link, but it shows the article title and I need the category one.
I'm working on Joomla 1.7.
Much more simple answer:
<?php echo $this->escape($this->item->category_title);?>
As per the posters comment in the OP:
<?php
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery('SELECT #__categories.title FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
$category = $db->loadResult();
echo $category;
?>
Travega is really close, his code works on pages, but not on category pages.
When you use $id = JRequest::getString('id'); on a category page (such as a category blog or list page) the id of the category is returned. This means we need more context of the id variable, in this case the 'view'.
Here is my modified version of travega's code:
function getCategoryName() {
//Modified from: http://stackoverflow.com/questions/8928967/joomla-display-catagory-name-in-template
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$view = JRequest::getString('view');
if ($view == 'category') {
$sql = "SELECT title FROM #__categories WHERE #__categories.id = $id";
} else {
$sql = "SELECT #__categories.title FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = $id";
}
$db->setQuery($sql);
$category = $db->loadResult();
return $category;
}
Other relevant info:
I've only tested this on Joomla 2.5.3 on cat blog and cat list pages. I've not tested it on anything other than com_content component. This means it probably won't work on weblink, contact, etc pages as you may again loose the context.