Controlling Magenot sort collectio by attribute - php

I am using the FishPig module to display WordPress on my Magento site. I have selected some associated blog posts from a CMS Page and they display as I need to.
However I am using the postion boxes but this doesn't seem to have any effect.
I have tried adding ->addAttributeToSort('position') to the getPostCollection() but this causes the page to break.
Full code as it is now.
<?php if (($posts = $this->getPostCollection()) !== false): ?>
<?php if (count($posts) > 0): ?>
<div class="box-collateral box-description" style="padding:5px 20px;">
<!--<?php if ($title = $this->getTitle()): ?>
<h2 style="margin-bottom:15px;">Blog <span style="color: #68d088;">Posts</span></h2>
<?php endif; ?>-->
<div class="std">
<ul>
<?php foreach($posts as $post): ?>
<li class="related-blogs">
<h2><?php echo $this->escapeHtml($post->getPostTitle()) ?></h2>
<div class="content">
<?php
$pos = strpos($post['post_content'], ' ', 300);
echo substr($post['post_content'],0,$pos );
?>
</div>
<a style="color:#68d088; font-weight:bold;" href="<?php echo $post->getPermalink() ?>">Read More...</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
<?php endif; ?>

Related

ACF loop within category loop - Wordpress

I cannot get my posts to display on a category page.
It finds if the posts are within and category and displays content fine.. But the loop I am using does not bring in the posts.. Any help would be great.
<?php if (is_category(array(4, 5, 6))) { ?>
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="case-study-box">
<a href="<?php the_permalink(); ?>">
<div class="post-img ripple-me" style="background-image: url(<?php the_field('thumbnail_image'); ?>)">
</div>
</a>
<div class="post-intro">
<span><?php the_category(' '); ?></span>
<?php the_title('<h4>', '</h4>'); ?>
Read more
</div>
</div>
<!--Close .case-study-box -->
<?php endwhile; else: ?>
<?php endif; ?>
<?php } else { ?>

How to show k2 items in k2 content module in 3 columns?

Joomla k2 component is power Joomla content system. k2 has a module that's called k2 content module and you can override the layout template of it.
I had this code for my k2 content module, this template file shows k2 items in 2 columns with even and odd classes and extra fields in it.
<?php
// no direct access
defined('_JEXEC') or die;
// includes placehold
$yt_temp = JFactory::getApplication()->getTemplate();
include (JPATH_BASE . '/templates/'.$yt_temp.'/includes/placehold.php');
?>
<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2ItemsBlock<?php
if($params->get('moduleclass_sfx')) echo ' '.$params-
>get('moduleclass_sfx'); ?>">
<?php if($params->get('itemPreText')): ?>
<p class="modulePretext"><?php echo $params->get('itemPreText'); ?></p>
<?php endif; ?>
<?php if(count($items)): ?>
<ul class="product">
<?php foreach ($items as $key=>$item): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1)
echo ' lastItem'; ?>">
<?php if($params->get('itemImage') || $params->get('itemIntroText')): ?>
<?php if($params->get('itemImage')): ?>
<div class="product-image">
<img src="<?php echo $item->image; ?>" alt="<?php echo
K2HelperUtilities::cleanHtml($item->title); ?>" />
</div>
<?php endif; ?>
<div class="main">
<?php if($params->get('itemTitle')): ?>
<p class="moduleItemTitle"><?php echo $item->title; ?></p>
<?php endif; ?>
<?php if($params->get('itemIntroText')): ?>
<div class="introtext">
<?php echo $item->introtext; ?>
</div>
<?php endif; ?>
<!-- end main-->
<?php if($params->get('itemExtraFields') && count($item->extra_fields)): ?
>
<div class="moduleItemExtraFields-energi">
<ul>
<?php foreach ($item->extra_fields as $extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="type<?php echo ucfirst($extraField->type); ?>
group2">
<?php if($extraField->type == 'header'): ?>
<h4 class="moduleItemExtraFieldsHeader"><?php echo
$extraField->name; ?></h4>
<?php else: ?>
<span class="moduleItemExtraFieldsLabel"><?php echo
$extraField->name; ?></span>
<span class="moduleItemExtraFieldsValue"><?php echo
$extraField->value; ?></span>
<?php endif; ?>
<div class="clr"></div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clr"></div>
</li>
<?php endforeach; ?>
<li class="clearList"></li>
</ul>
<?php endif; ?>
</div>
I would like to show my articles in 3 columns with extra fields.
How to do this? If it's possible, help me to do it.
Thanks for your attention.

magento do not display title and logo when manufacturer attribute is set to empty

I am working with the following codes for Magento inside product page view.phtml.
<div class="manufacturer">
<?php if ($_product->getAttributeText('manufacturer') == "Bellazza" || "Della" || "Pet Zone" || "Spyder Auto" ):?>
<div class="dealer">
<p>Authorized Dealer:</p>
</div>
<div class="logoImg">
<?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
</div>
<?php elseif ?>
<?php endif;?>
</div>
So I create div.manufacturer to display associated brand logo image started by the title "Authorized Dealer". It works. But not all products have a brand so when I set the manufacturer attribute to empty ( refer to the image below ) I don't need the title "Authorized Dealer" anymore. What is the best practice to approach the elseif. Thank you
manufacturer/manufacturer.phtml
<?php
$maufacturers = Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('status',Array('eq'=>1));
$_columnCount=4;
$i=0;
?>
<div class="manufacturer-list">
<?php foreach($maufacturers as $manufacturer): ?>
<?php if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName())): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul>
<?php endif; ?>
<li>
<a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
<?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setListPageFlag(1)->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
</a>
<div class="manufacturer-name">
<?php echo Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName()) ?>
</div>
</li>
<?php if ($i%$_columnCount==0 && $i!=count($maufacturers)): ?>
</ul>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</div>
product_manufacturer
<?php
$product=$this->getProduct();
if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($product->getData('manufacturer'))):
$manufacturers=Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('menufecturer_name',$product->getData('manufacturer'));
foreach($manufacturers as $manufacturer){
$status=$manufacturer->getStatus();
if($status==1){
?>
<div class="manufacturer-img-box">
<a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
<?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
</a>
</div>
<?php }
}
endif;
?>
You need refactoring the code
<div class="manufacturer">
<div class="logoImg">
<?php echo $this->getLayout()->createBlock('manufacturer/manufacturer')->setProduct($_product)->setTemplate('manufacturer/product_manufacturer.phtml')->toHtml();?>
</div>
</div>
and check variable
<?php if(!is_null($manufacturer->getMenufecturerName())): ?>
<div class="manufacturer-name">
<?php
echo Mage::getModel('eav/entity_attribute_source_table')
->setAttribute(Mage::getModel('eav/entity_attribute')
->load(Mage::getModel('eav/entity_attribute')
->getIdByCode('catalog_product',"manufacturer")))
->getOptionText($manufacturer->getMenufecturerName())
?>
</div>
<?php endif; ?>
And you need refactoring your code. Because I loock much excess code in your template. You need get data in you block and in phtml you need render this data by API blocks. getImageSrc(); getManufactures() and more over methods for get processed information.

Make clickable the whole block with <a> element

I want that the whole block be possible to click when hover the cursor over, to click on a link to go the link.
Example:
How this now:
The code of the component is:
<li<?php echo strlen($item->custom_tags) ? ' class="'.$item->custom_tags.'"' : ''; ?> data-mosaic-item>
<div class="sprocket-mosaic-item" data-mosaic-content>
<?php echo $item->custom_ordering_items; ?>
<div class="sprocket-padding">
<?php if ($item->getPrimaryImage()) :?>
<div class="sprocket-mosaic-image-container">
<?php if ($item->getPrimaryLink()) : ?><a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>"><?php endif; ?>
<img src="<?php echo $item->getPrimaryImage()->getSource(); ?>" alt="" class="sprocket-mosaic-image" />
<?php if ($item->getPrimaryLink()) : ?>
<span class="sprocket-mosaic-hover"></span>
<span class="sprocket-mosaic-hovercontent"><span>+</span><?php rc_e('READ_MORE'); ?></span>
</a>
<?php endif; ?>
<?php if ($item->getPrimaryLink()) : ?>
<span><?php rc_e('READ_MORE'); ?></span>
<?php endif; ?>
<?php if (count($item->custom_tags_list)) : ?>
<ul class="sprocket-mosaic-tags">
<?php
foreach($item->custom_tags_list as $key => $name){
echo ' <li class="sprocket-tags-'.$key.'">'.$name.'</li>';
}
?>
</ul>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="sprocket-mosaic-head">
<?php if ($item->getTitle()): ?>
<h2 class="sprocket-mosaic-title">
<?php if ($item->getPrimaryLink()): ?><a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>"><?php endif; ?>
<?php echo $item->getTitle();?>
<?php if ($item->getPrimaryLink()): ?></a><?php endif; ?>
</h2>
<?php endif; ?>
<?php if ($parameters->get('mosaic_article_details')): ?>
<div class="sprocket-mosaic-infos">
<span class="author"><?php //echo $item->getAuthor(); ?></span>
<!--
<i class="icon-time"></i>
<span class="mosaic-date">
<?php //echo $item->getDate();?>
</span> -->
<?php if($item->getDate()): ?>
<!-- Date created -->
<span class="mosaic-date">
<i class="icon-time"></i>
<?php echo JHTML::_('date', $item->getDate(), JText::_('d M Y')); ?>
</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="sprocket-mosaic-text">
<?php echo $item->getText(); ?>
</div>
</div>
</div>
So i want the entire block of red border to be possible to click
My english is not the best, so I hope that I got you right:
you want one div-container to be clickable?
if that is what you want, why don't you wrap the div container by your link
Code Example:
<a href="...">
<div>
//Additional Code in here
</div>
</a>
Here's a fiddle with two ways - FIDDLE.
The upper one uses jQuery .on('click' and it points to a styled div.
The lower one changes an anchor tag to block, adds a picture and text, then on click redirects.
I'm sure there are other ways.
HTML
<div class='wholeblock'>
<img src='http://i.imgur.com/DgYUsKY.jpg?1' />
<div>Minions are fun</div>
<div>Minions are happy</div>
<div>There are many Minions</div>
</div>
<a href='www.stackoverflow.com' class='wholeblock'>
<img src='http://i.imgur.com/DgYUsKY.jpg?1' />
<div>Minions are fun</div>
<div>Minions are happy</div>
<div>There are many Minions</div>
</a>

Magento category link to 404 error

this is my first Magento project and I've run into such a big issue.
The Magento version I'm using is 1.7.0.2
I managed to create a custom left bar navigation bar using the following code in my "app/design/frontend/default/default/template/catalog/navigation/category.phtml"
<?php
$cats = Mage::getModel('catalog/category')->load(1)->getChildren();
$catIds = explode(',',$cats);
?>
<div id="LeftCategory">
<h2>Wicked Categories</h2>
<hr style="color:white; height:1px; margin:5px;" />
<ul>
<?php foreach($catIds as $catId): ?>
<li class="Li-Top-Category">
<?php
$category = Mage::getModel('catalog/category')->load($catId);
?>
<a href="<?php echo $category->getUrl()?>">
<?php echo $category->getName()?>
</a>
<?php
$subCats = Mage::getModel('catalog/category')->load($category->getId())->getChildren();
$subCatIds = explode(',',$subCats);
?>
<?php if(count($subCatIds) > 1):?>
<ul>
<?php foreach($subCatIds as $subCat) :?>
<li class="Li-Sub-Category">
<?php
$subCategory = Mage::getModel('catalog/category')->load($subCat);
?>
<a href="<?php echo $subCategory->getUrl()?>">
<?php echo $subCategory->getName()?>
</a>
<?php
?>
</li>
<?php endforeach;?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
It does the work to generate the category navigation. But the issue is, the URL each link points to doesn't work. All links are invalid that lead to the 404 Error Page.
You can see it here: http://wicked-shop.dev.thejinstudio.com/shop/catalog/category/view/s/accessories/id/15/
I've done so much search and nothing really solved this issue.
I appreciate your help in advance.
Use the catalog/category helper to get the proper URL from a category model
$_catalogCatgoryHelper = Mage::helper('catalog/category');
Then with that helper pass your category to the getCategoryUrl() function
$_catalogCatgoryHelper->getCategoryUrl($category);
So give this a try. I've put my suggestions into your code:
<?php
$_catalogCatgoryHelper = Mage::helper('catalog/category');
$cats = Mage::getModel('catalog/category')->load(1)->getChildren();
$catIds = explode(',',$cats);
?>
<div id="LeftCategory">
<h2>Wicked Categories</h2>
<hr style="color:white; height:1px; margin:5px;" />
<ul>
<?php foreach($catIds as $catId): ?>
<li class="Li-Top-Category">
<?php
$category = Mage::getModel('catalog/category')->load($catId);
?>
<a href="<?php echo $_catalogCatgoryHelper->getCategoryUrl($category) ?>">
<?php echo $category->getName()?>
</a>
<?php
$subCats = Mage::getModel('catalog/category')->load($category->getId())->getChildren();
$subCatIds = explode(',',$subCats);
?>
<?php if(count($subCatIds) > 1):?>
<ul>
<?php foreach($subCatIds as $subCat) :?>
<li class="Li-Sub-Category">
<?php
$subCategory = Mage::getModel('catalog/category')->load($subCat);
?>
<a href="<?php echo $_catalogCatgoryHelper->getCategoryUrl($subCategory)?>">
<?php echo $subCategory->getName()?>
</a>
<?php
?>
</li>
<?php endforeach;?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
You might be better off with this code which I used in the past (but actually ended up rewriting so that it iteratively displays categories regardless of how deep they go, looking into how to do this would certainly be a good exercise for you). It is a bit cleaner, but you'll need to modify it slightly to your needs:
<?php $helper = $this->helper('catalog/category') ?>
<div class="block block-categorynavigation">
<div class="block-title">
<strong><span><?php echo $this->__('Category') ?></span></strong>
</div>
<div class="block-content">
<?php $categories = $this->getStoreCategories() ?>
<?php if (count($categories) > 0): ?>
<ul id="leftnav-tree" class="level0">
<?php foreach($categories as $category): ?>
<li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
<span><?php echo $this->escapeHtml($category->getName()) ?></span>
<?php $subcategories = $category->getChildren() ?>
<?php if (count($subcategories) > 0): ?>
<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
<?php foreach($subcategories as $subcategory): ?>
<li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?>
<?php $subsubcategories = $subcategory->getChildren() ?>
<?php if (count($subcategories) > 0): ?>
<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level2">
<?php foreach($subsubcategories as $subsubcategory): ?>
<li class="level2<?php if ($this->isCategoryActive($subsubcategory)): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($subsubcategory->getName(), '- ')) ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
edit: Original code only showed subcatgories for the currently viewed category

Categories