Magento for each loop limit The Next CEO of Stack OverflowLimit for creating storesTop Menu cache problemCreate categories through installerScript to hide empty categories works but not with products without stockHow to change the memory limit for phpPersonal discount for each customerMagento memory Limit for admin reportMagento 2: Set Category Limit in ListLoop Through Magento Categories, Meta Keywords and DescriptionsFor each loop running only once
Complex fractions
How do I go from 300 unfinished/half written blog posts, to published posts?
"In the right combination" vs "with the right combination"?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Contours of a clandestine nature
MessageLevel in QGIS3
Which tube will fit a -(700 x 25c) wheel?
Are there any limitations on attacking while grappling?
Why does the UK parliament need a vote on the political declaration?
How do I make a variable always equal to the result of some calculations?
What is "(CFMCC)" on an ILS approach chart?
Should I tutor a student who I know has cheated on their homework?
How do scammers retract money, while you can’t?
What benefits would be gained by using human laborers instead of drones in deep sea mining?
Elegant way to replace substring in a regex with optional groups in Python?
How to prevent changing the value of variable?
How to safely derail a train during transit?
Real integral using residue theorem - why doesn't this work?
WOW air has ceased operation, can I get my tickets refunded?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Is it ever safe to open a suspicious html file (e.g. email attachment)?
Written every which way
Novel about a guy who is possessed by the divine essence and the world ends?
What's the best way to handle refactoring a big file?
Magento for each loop limit
The Next CEO of Stack OverflowLimit for creating storesTop Menu cache problemCreate categories through installerScript to hide empty categories works but not with products without stockHow to change the memory limit for phpPersonal discount for each customerMagento memory Limit for admin reportMagento 2: Set Category Limit in ListLoop Through Magento Categories, Meta Keywords and DescriptionsFor each loop running only once
Working on the categories for a magento homepage for pulling out categories on the main page.
At the moment it pulls all out of the categories out but I want to limit this too 6 categories.
I have tried a few different options and have not been able to get this working correctly.
What would be the best way to apply the limit? I have included code below.
<ul class="cat-nav">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li class="<?php echo $_category->getName(); ?>">
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li class="<?php echo $_category->getName(); ?>">
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '' . $_categoryChildModel->getProductCollection() . '</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
magento-1.9 category php
add a comment |
Working on the categories for a magento homepage for pulling out categories on the main page.
At the moment it pulls all out of the categories out but I want to limit this too 6 categories.
I have tried a few different options and have not been able to get this working correctly.
What would be the best way to apply the limit? I have included code below.
<ul class="cat-nav">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li class="<?php echo $_category->getName(); ?>">
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li class="<?php echo $_category->getName(); ?>">
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '' . $_categoryChildModel->getProductCollection() . '</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
magento-1.9 category php
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12
add a comment |
Working on the categories for a magento homepage for pulling out categories on the main page.
At the moment it pulls all out of the categories out but I want to limit this too 6 categories.
I have tried a few different options and have not been able to get this working correctly.
What would be the best way to apply the limit? I have included code below.
<ul class="cat-nav">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li class="<?php echo $_category->getName(); ?>">
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li class="<?php echo $_category->getName(); ?>">
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '' . $_categoryChildModel->getProductCollection() . '</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
magento-1.9 category php
Working on the categories for a magento homepage for pulling out categories on the main page.
At the moment it pulls all out of the categories out but I want to limit this too 6 categories.
I have tried a few different options and have not been able to get this working correctly.
What would be the best way to apply the limit? I have included code below.
<ul class="cat-nav">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li class="<?php echo $_category->getName(); ?>">
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<ul>
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li class="<?php echo $_category->getName(); ?>">
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '' . $_categoryChildModel->getProductCollection() . '</a>';
?>
</li>
<?php if($categoryGrandchildren->count()) : ?>
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
<li>
<?php
$currentCategoryId===$_categoryChild->getId() ? $bold="style="font-weight:bold"" : $bold='';
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
</ul>
magento-1.9 category php
magento-1.9 category php
edited 10 mins ago
Teja Bhagavan Kollepara
3,01241949
3,01241949
asked Jul 23 '15 at 11:53
RobertRobert
61
61
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12
add a comment |
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12
add a comment |
1 Answer
1
active
oldest
votes
You can get a list of categories based on the parent id like this:
$parentId = 'Your parent id here';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $parentId)
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->setCurPage(1)->setPageSize(6);//limit to 6 categories
To get the root categories use $parentId = Mage::app()->getStore()->getRootCategoryId()
.
For the sub categories use $parentId = 'the category id for which you are trying to retrieve the child categories.'
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f75446%2fmagento-for-each-loop-limit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can get a list of categories based on the parent id like this:
$parentId = 'Your parent id here';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $parentId)
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->setCurPage(1)->setPageSize(6);//limit to 6 categories
To get the root categories use $parentId = Mage::app()->getStore()->getRootCategoryId()
.
For the sub categories use $parentId = 'the category id for which you are trying to retrieve the child categories.'
add a comment |
You can get a list of categories based on the parent id like this:
$parentId = 'Your parent id here';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $parentId)
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->setCurPage(1)->setPageSize(6);//limit to 6 categories
To get the root categories use $parentId = Mage::app()->getStore()->getRootCategoryId()
.
For the sub categories use $parentId = 'the category id for which you are trying to retrieve the child categories.'
add a comment |
You can get a list of categories based on the parent id like this:
$parentId = 'Your parent id here';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $parentId)
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->setCurPage(1)->setPageSize(6);//limit to 6 categories
To get the root categories use $parentId = Mage::app()->getStore()->getRootCategoryId()
.
For the sub categories use $parentId = 'the category id for which you are trying to retrieve the child categories.'
You can get a list of categories based on the parent id like this:
$parentId = 'Your parent id here';
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $parentId)
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->setCurPage(1)->setPageSize(6);//limit to 6 categories
To get the root categories use $parentId = Mage::app()->getStore()->getRootCategoryId()
.
For the sub categories use $parentId = 'the category id for which you are trying to retrieve the child categories.'
answered Jul 23 '15 at 12:08
Marius♦Marius
167k28319686
167k28319686
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f75446%2fmagento-for-each-loop-limit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi, welcome on Magento SE. Use a category collection, it'll give you more control over the limit rather than resorting to use a counter and if's :)
– Julien Lachal
Jul 23 '15 at 11:57
Hi Im not too sure as to how to do this? I thought this would be the better way and just limiting them within the foreach loop
– Robert
Jul 23 '15 at 12:04
easier yet dirtier. here is a link for the manipulation of products to give you a rough idea of what you should do.
– Julien Lachal
Jul 23 '15 at 12:12