How to retrieve Categories name and children ? Magento - magento

I would like to retrieve the categories of my website in order to build me own Category menu.
but I don't understand how to get all the categories from the class/model. So I've created a file called top.phtml that I've put in template/catalog/navigation ,
First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me .. I add that code to my file top.phtml properly called in the page.xml :
<div class="category-list" style="background-color:white;">
<h2>Nos produits</h2>
<?php
foreach ($this->getStoreCategories() as $_category):
if($_category->getIsActive()):
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer')->setCurrentCategory($_category);
?>
<div class="category-list-view">
<a href="<?php echo $this->getCategoryUrl($_category)?>" title="<?php echo $_category->getName()?>">
<img src="<?php echo $this->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $_category->getName() ?>" />
</a>
<h3><?php echo $_category->getName()?></h3>
</div>
<?php
endif;
endforeach;
?>
</div>
Last : where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
Thanks for your answers, I m a web dev used to work with CodeIgniter or without any template, and I can t clearly see the logic behind Magento way of programming.
EDIT: Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why

First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
You can name your template file whatever you like. However, it's best to follow the nomenclature and established conventions. The template filename is contingent on your layout XML. It should have the template attribute, something like <block name="x" type="x/y" template="catalog/navigation/topmenu.phtml" /> (for example).
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me
The functions available to your template (topmenu.phtml file) depend on the block's type. In your layout XML, you should specify the block type that corresponds to the functionality you need. In your case, you're probably looking for the block type to be catalog/navigation. If you look in ./app/code/core/Mage/Catalog/Block/Navigation.php, you can see what public methods are available to your template. Several of the methods here facilitate generating (nested) category listing. This is where your getStoreCategories() method comes from. Remember that these blocks inherit from several parenting classes, so you have a lot more methods available than you may at first think.
where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
That's a link to the Magento API. What you need is a tutorial on Magento layout XML and the design layer therein. The Magento wiki has some good info, but Google around and you'll find a ton of really helpful resources on understanding Magento's design system.
Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why
A root category is what you'll use to identify the basis of the catalog for the selected store(s). You will never see the root category appear on the frontend (and you shouldn't). Each subcategory within the root category is the top-level category; sub-categories beneath those subcategories (tertiary categories) would appear as your "second-level" categories on the Magento frontend. You might want to look into Magento's GWS ("global, website, store") scope system, and how it manages catalog data in a multi-store setup to better understand why root categories function this way.
Hope this helps!

Related

Processwire Add css class to page

I there a possibility to add a classname to a page?
I can't figure out how to implement such feature or if it already exists.
I'm using Processwire 3.0.42.
Put something like this in your template where the body is:
<body class="<?php echo $page->template->name; ?>">
That will give your page body tag a class equal to page template name.
You can add a page title in the same way.
<body class="<?php echo $page->name; ?>">
Don't be worried about adding a class to every page. The overhead of doing this is negligible.
If you wish to add a different class you would need to add a field to your template and append it to the code above.
As always in ProcessWire, everything is under your control. Alternatives to #ivangretsky's perfectly good answer would include-
Simply include a conditional in your template file. (This doesn't scale well if you need to add other classes to other pages using the same template.)
<?php
$bodyClass = '';
if($page->id == 1021) $bodyClass = 'my-class';
?>
<body class="<?php echo $bodyClass; ?>">
NB Using $page->id is better than $page->name, for example, as the ID doesn't change while the name could.
You could also add a field to the page template definition. Add a field called something like 'Body Class'. Then use the content of that field in your template file.
<body class="<?php echo $page->body-class; ?>">
This will scale better than my other suggestion, and there are options in the ProcessWire backend to hide or partially hide the field during normal use if you don't want users messing with its value.
One 'gotcha' from the CSS spec to be aware of is that CSS identifiers, including class names and IDs cannot start with a digit, so you cannot just use $page->id.
There are lot of options and it depends on your needs and maybe imagination :-).
You can use page name, template name, page id, or maybe combination.
<body class="<?php echo $page->template->name; ?> page-id-<?php echo $page->id; ?>">
// Output
<body class="your-template-name page-id-1234">
This way you can target template, page, or both.
Or, as mentioned by #ivangretsky, you can add custom field to page. And again, you can combine this aproach with template name, etc.
It depends on your needs and what you want to achieve.
Notice:
Using $page->id is better than $page->name, as the ID doesn't change while the name could. #DaveP

How do I manually theme Views in Drupal 7?

I am new to drupal and I am trying to figure out how to theme Views. I currently have a content type called Category with the following fields:Title, Image and Body. I created a view for the above mentioned content type so that I would list view of all the categories I have created.
To custom theme the view I created a folder called views in my theme folder, and created the following view files:
views-view-fields--plugin-categories.tpl.php
views-view--plugin-categories.tpl.php
views-view-unformatted--plugin-categories.tpl.php
This is what I currently have in my first file:
<div class="<?php print $classes; ?>">
<?php if ($rows): ?>
<div class="view-content">
<?php print $rows; ?>
</div>
<?php elseif ($empty): ?>
<div class="view-empty">
<?php print $empty; ?>
</div>
<?php endif; ?>
<?php if ($more): ?>
<?php print $more; ?>
<?php endif; ?>
</div><?php /* class view */ ?>
Instead of $rows, I tired to use print $field['image'] and print $field['body'] but this method does seem to work. Could you kindly advise on how I could theme the three fields, within categories, displayed using view?
You should name your template like this
views-view-fields--<machine-name-of-your-view>.tpl.php
So I'm assuming from the above that your view is called 'plugin-categories'. An easy way to check is to go to edit the view and look at the URL while you're on the edit page. It should have the format /admin/structure/views/view/YOUR-VIEW'S-MACHINE-NAME/edit, so you can get it from there.
Once you're sure it has the right name, clear your cache to make sure Drupal is picking up your new template. You just need the one above, not all three to modify the output of the three fields in question.
Once you've cleared cache, Drupal should be picking up the new template. You didn't mention exactly what isn't working, just that it's not working, so I wanted to cover the naming and caching, just in case. Now, to output particular fields in this view template, call them like this:
$fields['your-field-machine-name']
So $fields['body'] (I think you're missing an 's')
You should have nothing about $rows in this template! If you have anything about $rows, you haven't copied and pasted from the correct views template. Simply output the fields as you want them to appear in your view, in whatever order you want with the syntax above and put in whatever css classes, etc you want.
Let us know if that works!

Joomla Change Modules in Sidebar on diffrent Pages

I'm using Joomla 2.5.7 and want to ask, how I can change a bunch of modules in sidebar, when I change to another Page. An example to clarify my question:
I have 3 Links at the navigation bar:
Events
Shop
Blog
and a Homepage as index.html (logical).
Now, I want display in Events the modules "Where to go" and "About Location" in the sidebar.
In Shop I want to display the modules "About Dealer", "Shipping" and "Images" in the sidebar without the modules "Where to go" and "About location".
In Blog I want to display the module "About Author" in sidebar without the modules above (Where to go, about location...).
So, I know I can do this (or similar):
<?php if ($this->countModules('sidebar-a and sidebar-b and sidebar-c')): ?>
<jdoc:include type="modules" name="sidebar-a" />
<jdoc:include type="modules" name="sidebar-b" />
<jdoc:include type="modules" name="sidebar-c" />
<?php endif; ?>
SIDEBAR-A: "Where to go" and "About Location"
SIDEBAR-B: "About Dealer", "Shipping" and "Images"
SIDEBAR-C: "About Author"
But that is not my plan!
I want just the position "sidebar-a" and that the modules getting hidden (like in countModules) if they are not for this page.
I see this method on the granty framework:
<?php /** Begin Main Body **/ ?>
<?php echo $gantry->displayMainbody
'mainbody','sidebar','standard','standard','standard','standard','standard'); ?>
<?php /** End Main Body **/ ?>
You see just simple code, but with other variables.
So very easy in the index.html but this won't work If I do copy and paste ;)(logical)
I don't know how to do it. I do not prefer to get this framework, just for this single sidebar. But there must be a way like this granty framework, but I can't understand the code very well...I'm just an amateur on php. I guess there must be a JavaScript file, which hide and display this diffrent modules.
You can see a live demo here of the single sidebar with lots of modules, which getting hidden and displayed on each page: http://app.ohanah.com/demo-v2/rt/index.php
Have someone an idea how to run this sidebar?
Thanks for reading and helping!
In the Joomla backend, go to the Module Manager, open the module you want to change, and in the bottom left, you can assign the module to specific pages. This should be what you're looking for and it will save you having to hard code it.
You can , for better handling, use the Module Everywhere extension , look for it in JED.
It helps you a lot assigning modules not only to menulinks, but even to articles.

Using Joomla 1.7 generic categories functions

Since 1.6, I believe, there's a generic way to use 'categories' in your own created components. The default Joomla components also use this. For example: the contacts, newsfeeds and weblinks components all use the generic com_categories functionality to achieve categorized content.
Currently I'm creating a component which also has categories so I'd like to use the generic Joomla category functions to achieve this.
The status: Currently I've got the following:
I've got a submenu 'categories' in my component which links to the generic categories component which some extra options. The options are there so the page will be redirected back to my component on save. This was pretty easy! But..
My problem: Now I'd like to add specific fields to my category, let's say: 'Category Moderator'.
So I've walked to the code of com_categories and in the following file 'administrator\components\com_categories\models\category.php' there is code (line 270) to look for specific component code, like the following:
// Looking first in the component models/forms folder
$path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/models/forms/$name.xml");
So the components looks (in my case) in the folder: administrator/components/mycomponent/models/forms/category.xml for specific component info.
Now, in the default category.xml of com_categories there's information about the edit screen, like the following:
<field
name="title"
type="text"
label="JGLOBAL_TITLE"
description="JFIELD_TITLE_DESC"
class="inputbox"
size="40"
required="true"/>
So the title of the category is apparantly required..
So I thought I add a line to this file:
<field
name="moderator"
type="text"
label="JGLOBAL_MODERATOR"
description="JFIELD_MODERATOR_DESC"
class="inputbox"
size="40"
required="true"/>
Except that's not enough to add the input..
So I've looked in the administrator/components/com_categories/views/category/edit.php template for hints, how to achieve this. But there's no code to add specific inputs for my component (or I'm wrong ;))..
Fields are added pretty specific like:
<li><?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?></li>
I've also looked if I can overide the edit.php somehow, but unfortunately I haven't found it..
Short: Anyone knows how to add generic fields to the category edit page?
You can do it by using plugins ( you can take a look at the built-in user profile plugin for an example: /plugins/user/profile ). But if you want to add a "Category Moderator", I think you could achieve it using ACL.

Magento - showing review links & add-to-compare links on custom pages

I have a custom page as my magento homepage. It's content is hardcoded on the default CMS page (which shows if a CMS homepage isn't enabled in the CMS pages section of the admin).
I have a list of products showing there (pulled from best-selling/highest rated etc). However, the review links and the add-to-compare links don't show on this page. The list of products is displayed using the same code as the default template/catalog/product/list.phtml, and everything else works except for these 2 things.
It seems that both the following code snippets have no effect on pages other than the default category listing page:
<?php $_compareUrl=$this->getAddToCompareUrl($_product); ?>
&
<?php echo $this->getReviewsUrl() ?>
I'm guessing that there's something else that needs to be called in order for these to work, but can't figure out what it is. Everything else from the product collection is available.
I load my product collection using the following code:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
$_productCollection->load();
Any ideas?
OK, so after a while digging around, I found that you can use the following to get the compare url working:
<?php $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ?>
<span class="addto">
<?php echo $this->__('Add to Compare') ?>
</span>
Still not sure about the review urls, but I've made an acceptable workaround for that so I'm gonna mark this as answered.
If anyone comes up with an answer though please do still post it!
I'm guessing it's because the Block that is serving up your product list may not be correct. I believe it should be Mage_Catalog_Block_Catalog_Product_List. How exactly are you loading in the list of products?

Resources