Joomla / Add category description to Article Category modules - joomla

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.

Related

add blog picture to user profile page in joomla contact page

I want to add the article's pictures before the articles titles in the contact (user profile page ) like so:
Also, I have created an ovveride into a template html/com_contact/contact
and I have added this code but it gives a warning:
"Notice: Undefined property: stdClass::$images"
and no image.
Code:
/ Create a shortcut for params.
$images = json_decode($this->item->images);
$introImage = $images->image_intro;
?>
<?php if ($this->params->get('show_articles')) : ?>
<div class="contact-articles">
<ul class="nav nav-tabs nav-stacked">
<?php foreach ($this->item->articles as $article) : ?>
<li>
<?php echo JHtml::_('link',
JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article-
>catid, $article->language)), htmlspecialchars($article->title, ENT_COMPAT,
'UTF-8')); ?>
<?php echo $introImage; ?>
</li>
How can I get this fixed?
i have fixed it by using this cod ;
// Create a shortcut for params.
$article_id = $article->id; // get article id
//aticle_id = JFactory::getApplication()->input->get('id'); // get article
id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
//var_dump($intro_image);
//echo $intro_image;
echo "<img src=\"".$intro_image."\" alt=\"icon\" >";

What changes would need to be made to show posts with future created dates?

I'm at a bit of a loss on this one. I'm using the AheadWorks blog extension to add event posts for the current calendar year to my page. The extension also creates a feed of these posts, which I am feeding to Google Calendar. It is because of this that I use the dates of the events as the created dates, so they feed correctly to the Google Calendar. However, I can't figure out how to get Magento to display all posts; it only dislpays those with created dates from either the current day or sooner. I understand this is the default; how can I work around it so that all posts regardless of the created_time show?
I've seen several suggestions about changing the store time, and some that mention editing the created.php file, but I'm really not sure where to begin?
Could someone please give me an idea of what needs to be done?
Here's the app/code/community/AW/Blog/Block/Blog.php:
<?php
/**
* aheadWorks Co.
*
* NOTICE OF LICENSE
*
* This source file is subject to the EULA
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://ecommerce.aheadworks.com/AW-LICENSE.txt
*
* =================================================================
* MAGENTO EDITION USAGE NOTICE
* =================================================================
* This software is designed to work with Magento community edition and
* its use on an edition other than specified is prohibited. aheadWorks does not
* provide extension support in case of incorrect edition use.
* =================================================================
*
* #category AW
* #package AW_Blog
* #version 1.3.4
* #copyright Copyright (c) 2010-2012 aheadWorks Co. (http://www.aheadworks.com)
* #license http://ecommerce.aheadworks.com/AW-LICENSE.txt
*/
class AW_Blog_Block_Blog extends AW_Blog_Block_Abstract
{
public function getPosts()
{
$collection = parent::_prepareCollection();
$tag = $this->getRequest()->getParam('tag');
if ($tag) {
$collection->addTagFilter(urldecode($tag));
}
parent::_processCollection($collection);
return $collection;
}
protected function _prepareLayout()
{
if ($this->isBlogPage() && ($breadcrumbs = $this->getCrumbs())) {
parent::_prepareMetaData(self::$_helper);
$tag = $this->getRequest()->getParam('tag', false);
if ($tag) {
$tag = urldecode($tag);
$breadcrumbs->addCrumb(
'blog',
array(
'label' => self::$_helper->getTitle(),
'title' => $this->__('Return to ' . self::$_helper- >getTitle()),
'link' => $this->getBlogUrl(),
)
);
$breadcrumbs->addCrumb(
'blog_tag',
array(
'label' => $this->__('Tagged with "%s"', self::$_helper->convertSlashes($tag)),
'title' => $this->__('Tagged with "%s"', $tag),
)
);
} else {
$breadcrumbs->addCrumb('blog', array('label' => self::$_helper->getTitle()));
}
}
}
}
Here's the app/design/frontend/[theme]/[theme]/template/aw_blog/blog.phtml:
<?php
/**
* aheadWorks Co.
*
* NOTICE OF LICENSE
*
* This source file is subject to the EULA
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://ecommerce.aheadworks.com/AW-LICENSE.txt
*
* =================================================================
* MAGENTO EDITION USAGE NOTICE
* =================================================================
* This software is designed to work with Magento community edition and
* its use on an edition other than specified is prohibited. aheadWorks does not
* provide extension support in case of incorrect edition use.
* =================================================================
*
* #category AW
* #package AW_Blog
* #version 1.3.4
* #copyright Copyright (c) 2010-2012 aheadWorks Co. (http://www.aheadworks.com)
* #license http://ecommerce.aheadworks.com/AW-LICENSE.txt
*/
?><?php $posts = $this->getPosts(); ?>
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
</div>
<?php echo $this->getChildHtml('aw_blog_comments_toolbar'); ?>
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
<h3><?php echo $post->getCreatedTime(); ?></h3>
</div>
<div class="postContent">
<?php echo $post->getPostContent(); ?>
</div>
<?php echo $this->getBookmarkHtml($post) ?>
<div class="tags"><?php echo $this->getTagsHtml($post) ?></div>
<div class="postDetails">
<?php if ($this->getCommentsEnabled()): ?>
<?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" > <?php echo Mage::helper('blog')->__('Comments'); ?></a> |
<?php endif; ?>
<?php $postCats = $post->getCats(); ?>
<?php if (!empty($postCats)): ?>
<?php echo Mage::helper('blog')->__('Posted in'); ?>
<?php foreach ($postCats as $data): ?>
<?php echo $data['title']; ?>
<?php endforeach; ?>
<?php else: ?>
<?php echo Mage::helper('blog')->__('Posted'); ?>
<?php endif; ?><?php echo $this->__("By"); ?> <?php echo $post->getUser(); ?></div>
</div>
<?php endforeach; ?>
<?php echo $this->getChildHtml('aw_blog_comments_toolbar'); ?>
You were close, just change;
public function addPresentFilter()
{
$this->getSelect()->where('main_table.created_time<=?', now());
return $this;
}
to
public function addPresentFilter()
{
$this->getSelect()->where('main_table.update_time<=?', now());
return $this;
}
Works perfectly.
Just an update - I think I found the filter I needed to edit here:
app/code/community/AW/Blog/Model/Mysg14/Blog/Collection.php
public function addPresentFilter()
{
$this->getSelect()->where('main_table.created_time<=?', now());
return $this;
}
I changed to:
public function addPresentFilter()
{
$this->getSelect()->where('main_table.created_time>=?', now());
return $this;
}
I tried commenting it out entirely, but...whitescreen; so I'm still working on modifying to show all--and jhgraphics thank you for getting it there!

Magento - Display product count views?

I am using magento 1.9 and i am trying to display the views of the product in the product view page.
Here is what code i am using right now but it's not displaying anything:
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?PHP echo $_product->getViews();?>
Is it possible to display the number of the views of the displayed product or where i am doing wrong.
Thanks in advance!
You could create an observer for catalog_product_load_after and add views to the $_data array with
$product = $observer->getEvent()->getProduct();
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$select = $read->select()
->from(
$resource->getTableName('log/url_info_table'),
'COUNT(*) views'
)
->where('url LIKE "%catalog/product/view/id/' . $product->getId() . '"');
$result = $read->query($select)->fetch();
$product->setData('views', $result['views']);

Joomla load module on extra place?

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

How to make second root category navigation in magento?

Other than the normal navigation I get when I add subcategories to the main root category, I want to be able to make a new root category, assign subcategories to it and have it display as a separate menu.
Is this possible?
May this can help you :Link 1Link 2
To retrieve another root category
<?php
echo '<pre>';
$id=9;
$catagory_model = Mage::getModel('catalog/category');
$categories = $catagory_model->load($id); // where $id will be the known category id
if(!empty($categories))
{
echo 'category name->'.$categories->getName(); //get category name
echo '<br>';
echo 'category image url->'.$categories->getImageUrl(); //get category image url
echo '<br>';
echo 'category url path->'.$categories->getUrlPath(); //get category url path
echo '<br>';
}
?>
now $id=9; is my new root category id.
To retrieve sub categories of these new root category ($id=9;) below is the following reference code.Customize it according to your requirements.
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php foreach($categories as $category): ?>
<?php $subcategories = $category->getChildren() ?>
<?php foreach($subcategories as $subcategory): ?>
<?php $subsubcategories = $subcategory->getChildren() ?>
<?php foreach($subsubcategories as $subsubcategory): ?>
<?php endforeach; ?><!-- end foreach subsubcategories -->
<?php endforeach; ?><!-- end foreach subcategories -->
<?php endforeach; ?><!-- end foreach categories -->
In an ideal world you would have found the answer by now, but in case you didn't I modified Nikhil's answer to work for me to basically do what you describe, minus any convenience at all...
$id=9;
$catagory_model = Mage::getModel('catalog/category');
$categories = $catagory_model->load($id);
if(!empty($categories))
{
$cats = explode(",", $categories->getChildren());
foreach($cats AS $c)
{
$cat = $catagory_model->load(trim($c));
echo ''.$cat->getName().'';
}
}
I'm just pasting what I used. The reality is you will have to build the html to make this do whatever you want it to do. If you have subcategories within your loop, you will have to run another fetch in the foreach part.
I am not familiar with magento enough to know what methods you can run on the $cat object. I did a print_r($cat) to examine the object and made a lucky guess that getUrlKey would be available.
Magento... pfft! you'd think ebay would have higher standards than this.

Resources