Moving the category toolbar out of product/list
Catalog/product_list
and catalog/product_list_toolbar
are so wired trough with each other that you're stuck with using them together. If you only want to display toolbar, though, you'll need to create an (almost) empty product_list template.
Say you want toolbar displayed in the breadcrumbs block, but this should work with any block really.
Put the following update somewhere in your layout/local.xml
(you may need one for catalog_category_default, too):
<catalog_category_layered>
<reference name="breadcrumbs">
<block type="catalog/product_list" name="toolbar_only" template="catalog/product/list/toolbar_only.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar_only" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar_only</name></action>
</block>
</reference>
</catalog_category_layered>
Create a one-liner product list template in template/catalog/product/list/toolbar_only.phtml
:
<?php echo $this->getToolbarHtml() ?>
You can then insert the new block where ever you want in your breadcrumbs template:
template/page/html/breadcrumbs.phtml
:
<?php echo $this->getChildHtml('toolbar_only'); ?>
After trying to move the toolbar block through layout XML and template hacks I decided it was a lot easier to move it via javascript. I think this way gives you more control without any risk of breaking functionality.
jQuery(document).ready(function($) {
$(".breadcrumbs").after($(".category-products > .toolbar"));
});
Note this method only moves the first toolbar and not the bottom one using the specific selector .category-products > .toolbar
Some more reasoning as to why this method is best:
- The product list and toolbar are heavily intertwined, referencing each other in their blocks so it makes sense to keep them together in terms of code - they go hand in hand
- Less code and less changes to block logic means less probability for bugs to pop up
- Using javascript you can easily move it anywhere on the page
- Using layout XML you can only include the javascript on pages with a product list
- Moving via javascript is extendable and future-proofed - if the logic behind the product list or toolbar blocks changes in the new releases of Magento this method will still work.
LuFFy's code is not far off
To copy the block to other parts of your site, you can get the main layout object, and then just get the content block by name
$layout = Mage::app()->getLayout();
$content = $layout->getBlock('content');
$categoryProducts = $content->getChild('category.products');
$productList = $categoryProducts->getChild('product_list');
$toolbar = $productList->getToolbarBlock();
$toolbar->setCollection($productList->getLoadedProductCollection());
echo $toolbar->toHtml();