magento 1.7 - adding dynamic content to home page - magento

I would like to add dynamic content to front page of Magento site that looks like this...
I wrote a small "template program" called myPgm.phtml that looks like this:
<?php
$cats = Mage::getModel('catalog/category')->load(2)->getChildren();
$catIds = explode(',' , $cats);
?>
<div class='block block-list'>
<div class='block-title'><strong><span>Goto Category</span></strong></div>
<div class='block-content'>
<ul>
<?php foreach($catIds as $catId): ?>
<ul>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<li> <a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a></li>';
?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
I put this in:
app/design/frontend/default/mytheme/template/catalog/navigation/mypgm.phtml
Then in the front page CMS->Pages->Design, I added the following XML reference in side the "&gtreference name="header"&lt" section.
<block type="core/template" name="catalog.category" template="catalog/navigation/mypgm.phtml">
</block>
I put it next to an existing block that does appear on front page.
However my new block does not appear. What am I missing?
I did some additional testing. It works when I put it CMS->Pages->Front-Page->Content as
{{block type="core/template" name="catalog.category" template="catalog/navigation/mypgm.phtml"}}
I also works when I drop the block in this form:
<block type="catalog/navigation" name="catalog.category" template ="catalog/navigation/category.phtml"/>
... in content, left, and right "reference" sections, however not in header... maybe program has not fully boostrapped when header is created????

Try this on your CMS page:
{{block type="core/template" name="giveitaname" template="path/to/your.phtml"}}

Related

Locate and edit content in Magento 1 block

I am very new to Magento. I have an old Magento 1 site that someone else has built and I am trying to edit content that is on a particular page, called 'Trade'.
In the backend, I have found the page: CMS > PAGES > TRADE.
The 'CONTENT' tab has some of the pages content written in it, but not the part I want to edit.
The 'DESIGN' tab has the following code, which I believe is where the content I want to edit is located:
<reference name="content">
<block type="core/template" name="boards" template="cms/trade.phtml" />
</reference>
When I go to 'TRADE.PHTML' in my files, I have the following code:
<?php
$page = Mage::getSingleton('cms/page');
$advanced_fields = Mage::helper('core')->jsonDecode($page->getAdvancedFields());
$cms_fields = array();
foreach($advanced_fields as $field){
$name = $field['name'];
$content = $field['content'];
$cms_fields[$name] = $content;
}
$filter = new Mage_Widget_Model_Template_Filter();
?>
<div class="board">
<?php if(isset($cms_fields['board_1'])){ ?>
<div class="board_left board_inner">
<?php echo $filter->filter($cms_fields['board_1']); ?>
</div>
<?php } ?>
<?php if(isset($cms_fields['board_2'])){ ?>
<div class="board_right board_inner">
<?php echo $filter->filter($cms_fields['board_2']); ?>
</div>
<?php } ?>
</div>
I can not for the life of me figure out where to edit this little bit of content, and it's taking up way too much time.
A point in the right direction would be a great help, as I'm sure this is pretty simple and obvious to you Magento devs! Help a newbie out :)

how do I alter a link in the my account navigation column in magento?

im trying to alter the navigation links in the my account section of my magento site currently they look like this:
I turned on debug template paths so I can locate where it came from but it just sent me to navigation.phtml, which was just some php code the echos the links in a list form see below.
<div class="block block-account">
<div class="block-title">
<strong><span><?php echo $this->__('My Account'); ?></span></strong>
</div>
<div class="block-content">
<ul>
<?php $_links = $this->getLinks(); ?>
<?php $_index = 1; ?>
<?php $_count = count($_links); ?>
<?php foreach ($_links as $_link): ?>
<?php $_last = ($_index++ >= $_count); ?>
<?php if ($this->isActive($_link)): ?>
<li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
<?php else: ?>
<li<?php echo ($_last ? ' class="last"' : '') ?>><?php echo $_link->getLabel() ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
My goal is simple to rename "My Wishlist" to "My Sample Request" any ideas on how to achieve this ?
If renaming is only the issue than it is very simple.
You just edit the name in the "app/design/frontend/base/default/layout/wishlist.xml".
you will search for below code.
<customer_account>
<!-- Mage_Wishlist -->
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Wishlist</label></action>
</reference>
</customer_account>
change the label "My Wishlist" to "My Sample Request".
This will work.But its not the best way to achieve this.First Override the "wishlist.xml" to your theme and then only make a change.
Hope this will help.
you dont need to do this from xml file , just open the
`app/locale/en_US/Mage_XmlConnect.csv
and around line 601 you wil see a "My Wishlist","My Wishlist"
you can change from there. if you will change in xml file than in multilangual site it will same for all languages. So change from translate file.
thanks
$this->getLinks() is heart of that template. It retrieves all links as an array and then loop through it and display each item. So the array returned by that code is actually constituted by another method addLink(). It normally use in layout files. My guess is, you need to alter that name in layout file.
File : app\design\frontend\<package>\<theme>\layout\customer.xml
You can see many code like this
<action method="addLink" translate="label" module="customer">
<name>account</name>
<path>customer/account/</path>
<label>Account Dashboard</label>
</action>
Here label is the part that you need to change.
So check for this code in customer.xml file. Find the code that generate "Wisthlist" link. Then change the label part according to your need

Magento - display product reviews on product view page

I am having difficulty placing the product reviews on the main product view at a specific location. I can load them in the content area, but not at the specific location I require (within some of the view mark-up).
I have a local.xml with the following in it:
<catalog_product_view>
<reference name="content">
<block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>
</reference>
<catalog_product_view>
The above loads the reviews after all other content - as might be expected, due to content not being a templated block.
I have tried defining the blocks outside of the content reference, and placing this at the relevant point:
<?php echo $this->getChildHtml('reviews') ?>
For clarity, here is where I need the block to appear in view.phtml:
<div class="product-collateral">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
<?php echo $this->getChildHtml('reviews') ?>
</div>
Unfortunately, this doesn't output anything at all. I'm fairly new to Magento, and I'm at a loss how to achieve the above.
You can try leaving the code as in your example and include and use the attribute before, or after.
This allows you to position a block in regards to another block within that reference.
Ex: <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml" before="product.description"/>

How do I get the rating summary in new products section on my homepage?

On my homepage I have “New products” section. I created it with the following code:
<block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage2" template="catalog/product/new.phtml">
<action method="setColumnCount"><columns>3</columns></action>
<action method="setProductsCount"><count>3</count></action>
</block>
That works fine, but I want also show the rating summary (stars and amount of reviews) om my homepage:
<?php if($_product->getRatingSummary()): ?>
<div class="ratingsum">
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
</div>
The code above gives nothing back. It seems that there are no reviews, but I definitely know that there are reviews!
The problem seems the block type, for new products: catalog/product_new and for bestsellers bestsellers/list, is that possible?
I have also a “best sellers” section on my homepage. There is getting the rating summary no problem.
Also:
$_productCollection=$this->getLoadedProductCollection();
Doesn't work in my new.phtml. It returns no collection/products.
Below is the code to retrieve product rating summary.
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load('product_id');
if($summaryData->getRatingSummary()){
?>
<div class="rating-box" style="float:left;">
<div class="rating" style="width: <?php echo $summaryData->getRatingSummary().'%'; ?>"></div>
</div>
<?php
}
Just be sure to pass it the right product id number.

I want add custom column for sidebar all page in Magento

I want add my custom sidebar next right column all page.
Please check this link: http://www.wildbuilder.com/images/Untitled-1-Recovered.png
(I explain using image.)
There are featured products in the mini sidebar.
I don't want include the mini sidebar into right column. next to right column :)
I already made featured-products.phtml at /catalog/product/ folder.
And I created cms block, featured_products and I put in this code
{{block type="catalog/product_list" category_id="4" template="catalog/product/featured-products.phtml"}}
And I added code at page.xml like this.
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
<block type="cms/block" name="featured_products">
<action method="setBlockId"><block_id>featured_products</block_id></action>
</block>
</block>
Then I added code in 2columns-right.phtml at /template/page/ folde.
like this,
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col2-right-layout">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="main">
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
<?php //my slidebar ?>
<div style="float:right;width:92px;vertical-align:top;background-color:#000;margin:-766px 110px 0 0;">
<?php echo $this->getChildHtml('featured_products') ?>
</div>
But my sidebar is not showing.
How Can I Do???
Please let me know.
Thank you.
Also, try the following in 2-columns-right.phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(featured_products)->toHtml() ?>
No no no. Never edit the 2col-right, left or any other ./page/ template file for a modification such as this. You should also not be making changes in page.xml
What you need to do is understand layout handles on Magento. As your change relates specifically to catalogue, you should edit
catalog.xml
Then within that file, you can utilise the layout handle - which means, it appears, by default, everywhere.
<default>
<reference name="right">
<block type="catalog/product_list" template="catalog/product/featured-products.phtml" name="featuredprods" before="-">
<action method="setCategoryId"><category_id>4</category_id></action>
</block>
</reference>
</default>
There is no need for a phtml modification, or a CMS block or an edit of page.xml

Resources