I wonder if its possible to change the description of one category to be just after the products.
Example here:
http://www.theprinterdepo.com/refurbished-printers/monochrome-laser-refurbished-printers
I suppose there is one phtml file somewhere that I could change easily for this
I found the file, and the code is as follow
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php
//$currentPage = $this->getCollection()->getCurPage();
echo $_helper->categoryAttribute($_category, $_description, 'description')
?>
</div>
<?php endif; ?>
Howver the getCurPage gives an error
// get category id
$category = $category->load($category_id);
// get collection
$category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*');
// print out the description
echo $category->getDescription();
// get current page
$currentPage = $this->getCollection()->getCurPage();
if($currentPage = 1) {
// show Description Here
echo $category->getDescription();
} else {
// Show category name instead of description
echo $category->getName();
-- EDIT --
try this instead of above
$currentPage->getSelect()->getCurPage();
the file you are looking for is located in theme folder under catelog/category/view.phtml. so if have any custom theme installed locate the file first in your theme, if the file is not there then you can copy the file from the base folder and put in your theme folder, be sure to put the file in the correct folder otherwise it will not going to work. Like
if file is located in
app/design/frontend/base/default/template/catalog/category/view.phtmlput the file in
app/design/frontend/default/YOUR_THEME/template/catalog/category/view.phtml.This way if you upgrade the magento to newer version, the changes you made will not be over written by the system
If you want to put Category description after product listing, you just need to move elements around.
The template you need to modify is this:
app/design/frontend/{package}/{theme}/template/catalog/category/view.phtml.
Take this code:
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php endif; ?>
and move it at the bottom of the file. That's it.
Related
I'm working on a website that is using Woocommerce (and its plugin Sensei, which supports courses, lessons, quizzes, etc.). I'm running into trouble changing a small piece of info.
Within the Sensei plugin there if a file (woothemes-sensei > includes > class-sensei-course.php). In this file, there is one line of code that I want to change without editing the core file. I understand that I probably need to do this in my child theme's functions.php files, but I'm not quite sure what to do. I need to change the $course_page_url to a custom url in the following code:
<div id="active-courses">
<?php if ( '' != $active_html ) {
echo $active_html;
} else { ?>
<div class="sensei-message info">
<?php echo $no_active_message; ?>
<a href="<?php echo $course_page_url; ?>">
<?php _e( 'Start a Course!', 'woothemes-sensei' ); ?>
</a>
</div>
<?php } // End If Statement ?>
</div>
Can anyone tell me the best way to go about doing that? I don't know how to hook into a filter to change that url.
And the entire class-sensei-course.php file can be found here. The code that I included above begins on line 1596.
I would like to make a custom module with a list of tags. When a tag is clicked the visitor would be navigated to a category page that would show articles with that tag.
I am not a joomla expert, I was thinking about a solution like a hyperlink like this that I would add to the tags inside the module:
href="http://mywebsite.com/index.php/itemlist/tag/tokio%20city?category=places"
Is this possible? Or how could I achieve this result?
Thanks!
This is a bit more complicated than just a query string in the URL as you also need to tweak a template.
If you want to keep it as simple as possible, I'd would recommend creating a new K2 template using template overrides and editing the category template so that it would read the query string parameters and show only articles already filtered by the category and furthermore by the tag via a query string.
That's just a brief how-to, now with a lil bit more details:
1) Create a new K2 template using template overrides.
In your template, if it doesn't exist already, create a folder structure /templates/your_template/html/com_k2/templates/default. The "default" can be replaced with any name if you want to have more K2 templates, but you have to set the new template to each category you have manually.
Now take the content from "/components/com_k2/templates/default" and copy it to the new folder in your template. Now, K2 is using the templates from your /templates/your_template/html/com_k2/ folder. Feel free to google more details if you don't understand template overrides, it's pretty important thing when customizing a template.
2) Edit your category view file to accommodate the list to your query strings
The file that interests you now is in /templates/your_template/html/com_k2/templates/default/category.php. Open this file and try to understand what's important there:
Line 141
<?php foreach($this->leading as $key=>$item): ?>
Line 169
<?php foreach($this->primary as $key=>$item): ?>
Line 197
<?php foreach($this->secondary as $key=>$item): ?>
Line 226
<?php foreach($this->links as $key=>$item): ?>
This is what matters. In these four foreach loops, there are all the items. Then, you can wrap the content of each of these loops into an if-condition to check whether it has the desired tag that is specified in the URL.
To show you an example, this is the code for <div id="itemListPrimary">. You can replace this whole div in the category.php file with the following code and it will work flawlessly. I've just written and tested it.
<div id="itemListPrimary">
<?php foreach ($this->primary as $key=>$item): ?>
<?php
# Get the value of the "tag" query string
$jInput = JFactory::getApplication()->input;
$myTag = $jInput->get('tag', null, 'STRING'); // Joomla 1.6+
//$myTag = JRequest::getVar('tag'); // for Joomla 1.5
# If the tag is empty, the query string is not specified and we'll go standard way without any tag filter
if (empty($myTag)) {
// Define a CSS class for the last container on each row
if ((($key+1)%($this->params->get('num_secondary_columns'))==0) || count($this->secondary)<$this->params->get('num_secondary_columns'))
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->secondary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_secondary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_secondary_columns'))==0): ?>
<div class="clr"></div>
<?php endif;
# Otherwise the tag is set so we'll filter the articles by the tag
} else {
# Get an array of all the tags that the current article in the loop has
$articleTags = array();
foreach ($item->tags as $tag) {
$articleTags[] = $tag->name;
}
# Check if the article has the tag specified in the URL as a query string
if (in_array($myTag, $articleTags)) {
# Now the default content of the foreach loop comes as written in the default K2 category.php template
// Define a CSS class for the last container on each row
if ((($key+1)%($this->params->get('num_secondary_columns'))==0) || count($this->secondary)<$this->params->get('num_secondary_columns'))
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->secondary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_secondary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_secondary_columns'))==0): ?>
<div class="clr"></div>
<?php endif;
}
} ?>
<?php endforeach; ?>
</div>
3) Understand how the URLs will work
My typical category URL is:
http://mywebsite.com/category-name
To show only articles with a specified tag, use:
http://mywebsite.com/category-name?tag=your-tag
For instance, if you want to show only articles with the "Tokio City" tag, use:
http://mywebsite.com/category-name?tag=Tokio City
Done.
That's the basics of what you needs. It's all you need if you use primary articles only (no leading and secondary or links). Of course there are plenty more things you might want to take care of:
a notice if there is no article with the specified tag
no redundant code, I've written it like this for the sake of simplicity and readability
SEO - spaces and special characters in URLs
making sure no empty div will be printed
But that would be way more code and I wanted to keep it simple & readable for you. I think I gave you more than enough for a start, so go ahead and get it done, good luck :)
I'm pretty new in PHP and what I would like to do is for PHP to check if a certain image file with a specific name exists in a specific directory, then echo the name of the file, but if it doesn't exist, then just show XXX.png.
I currently have a page (http://powerplantv2.jehzlau.net/ppm-deals) that echoes all product names from a certain attribute in Magento.
This page calls all images based on the attribute name. For example in my page there's an attribute name called "cool haan". So it automatically calls the image named "coolhaan.png". If there's an attribute name called "levis" then it will show an image named levis.png.
But I don't know how to add a condition if levis.png doesn't exist in the directory, I just want to call XXX.png.
How can I let PHP check first if the image exists that matches the certain attribute in the directory, then show attributename.png, if now, XXX.png.
Currently, below is my code:
<?php
$name ='deals';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem(); $attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); $ppmtenants =
$attribute ->getSource()->getAllOptions(false); ?>
<?php foreach ($ppmtenants as $ppmtenant): ?>
<img src="<?php echo $this->getUrl() ?>media/wysiwyg/Deals/<?php echo strtolower($ppmtenantclean); ?>.png">
<?php endforeach; ?>
The code above gets all the options from a certain attribute then displays all the images with the attribute name. What I want to do is to check for the image name first before showing it.
To simplify my question, I just want to add a placeholder image with the name XXX.png for attributes with no images yet. :D
You can use file_exists() http://php.net/manual/en/function.file-exists.php to check if the file exists and then display the image, otherwise output the placeholder image.
<?php if(file_exists(path_to_your_file)) {
// Image does exist, fetch the image
} else {
// Image doesn't exist, output xxx.png
}
?>
Both the answers posted so far are correct, but to make things easier for you, you can do something like this:
<?php foreach ($ppmtenants as $ppmtenant):
if(file_exists($this->getUrl()."media/wysiwyg/Deals/".strtolower($ppmtenantclean).".png"))
{ ?>
<img src="<?php echo $this->getUrl() ?>media/wysiwyg/Deals/<?php echo strtolower($ppmtenantclean); ?>.png">
<?php
}
else
{
echo '<img src="xxx.png" alt="No image" />';
}
?>
<?php endforeach; ?>
<?php
if (!file_exists("PATH_TO_IMAGE") {
//display xxx.png
} else {
//load the image
}
I'm looking for a way to remove the product(s) link in the mod_virtuemart_cart. I want the product name - just no link. I'm stuck on line 34 of the default.php page under mod_virtuemart_cart/tmpl/:
<div class="product_row">
<span class="quantity"><?php echo $product['quantity'] ?></span> x <span class="product_name"><?php echo $product['product_name'] <-- RIGHT HERE ?></span>
</div>
Any ideas? Below is an URL to an image to help better show what I'm trying to accomplish.
http://superiordash.com/images/templatehelp.png
Thanks,
Michael
in file JRoot/components/com_virtuemart/helpers/cart.php
on line 1663:
change this:
$this->data->products[$i]['product_name'] = JHTML::link($url, $product->product_name);
to this:
$this->data->products[$i]['product_name'] = $product->product_name;
or other method is to use jQuery to remove the link.
FYI adding the following code at about line 20 to an override module template file in your template directory:
/templates/(name)/html/mod_virtuemart_cart/default.php
will result in a better manner to avoid breaking in the future:
// Remove links from products
foreach ( $data->products as &$product ) {
$product['product_name'] = strip_tags( $product['product_name'] );
}
Pull the default.php file from your /modules/mod_virtuemart_cart/tmpl folder and copy it to your template/html folder and edit.
Normaly in Drupal 7 we have node.tpl.php:
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>>
<?php print $title; ?>
</h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
It is taking $node_url and putting it on a Title in every Node.
I do have 5 nodes (pages) displayed:
First
Second
Third etc
I have created images First.gif, Second.gif and I want to load that images instead of Title.
I did check various implementation, but didn't find any resolution for me.
[Update] I did try to edit template.php file and to add functions for replacing title with image-if images exists. I need this in Drupal 7 - please see here - http://drupal.org/node/221854
Is there any help? Thanks..
Since each node has it's own id then what I'd suggest to you, is to have in your specific files folder images such as node-12, node-13 etc.
In your node.tpl.php
<?php
// path to our file depending on node id
$file = "path/to/file/node-{$node->nid}.gif";
// check if file exists
if (file_exists($file)) {
// theme $title as image with theme_image()
$title = theme('image', array('path' => $file));
}
?>
<h2<?php print $title_attributes; ?>>
<?php print $title; ?>
</h2>
However I'm sure this is not the best way of development but it work for your question.