Wordpress query post get Image unless blank - image

Hi I am creating a wordpress custom page theme, I have included the code. Is there a way to dynamically add the list items. In the code I grab each image related to its post with screenshot1 screenshot2 so on... This all currently works. My problem is at the current moment if I upload 2 screen shots 3 list items will show up and the third will just be blank. So how could I dynamically add them based on the number of images in the post?
query_posts('cat=3'); /*--Query to grab Projects categorie--*/
while (have_posts()) : the_post(); /* --- loop through the posts in that categorie */
<ul>
<?php
$screen1 = get_post_meta($post->ID, 'screenshot1', true);
$screen2 = get_post_meta($post->ID, 'screenshot2', true);
$screen3 = get_post_meta($post->ID, 'screenshot3', true);
echo "<li>" . wp_get_attachment_image($screen1, 'large') . "</li>";
echo "<li>" . wp_get_attachment_image($screen2, 'large') . "</li>";
echo "<li>" . wp_get_attachment_image($screen3, 'large') . "</li>";
?>
</ul>

Loop through the possible meta values and only output it if it's not empty.
Something like:
<ul>
<?php
$i = 1;
while ($screen = get_post_meta($post->ID, 'screenshot'.$i , true)) {
echo "<li>" . wp_get_attachment_image($screen, 'large') . "</li>"
$i++;
}
?>
</ul>

Related

add blog picture to user profile page in joomla contact page

I want to add the article's pictures before the articles titles in the contact (user profile page ) like so:
Also, I have created an ovveride into a template html/com_contact/contact
and I have added this code but it gives a warning:
"Notice: Undefined property: stdClass::$images"
and no image.
Code:
/ Create a shortcut for params.
$images = json_decode($this->item->images);
$introImage = $images->image_intro;
?>
<?php if ($this->params->get('show_articles')) : ?>
<div class="contact-articles">
<ul class="nav nav-tabs nav-stacked">
<?php foreach ($this->item->articles as $article) : ?>
<li>
<?php echo JHtml::_('link',
JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article-
>catid, $article->language)), htmlspecialchars($article->title, ENT_COMPAT,
'UTF-8')); ?>
<?php echo $introImage; ?>
</li>
How can I get this fixed?
i have fixed it by using this cod ;
// Create a shortcut for params.
$article_id = $article->id; // get article id
//aticle_id = JFactory::getApplication()->input->get('id'); // get article
id
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('images'))
->from($db->quoteName('#__content'))
->where('id = '. $db->Quote($article_id));
$db->setQuery($query);
$result = $db->loadResult();
$intro_image = json_decode($result)->image_intro;
//var_dump($intro_image);
//echo $intro_image;
echo "<img src=\"".$intro_image."\" alt=\"icon\" >";

Magento order grid

Hi I need to display Order Details grid in my Magento FRONT END page. I tried different ways, but nothing worked fine.
Also how to find <?php echo $this->getChildHtml('customer.account.dashboard.extra') ?> block.
Any idea please.
Here is the quick way,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app()->getStore();
echo '<pre>';
$orders = Mage::getModel('sales/order')->getCollection()
//->addFieldToFilter('status', 'complete')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('status')
->addAttributeToSelect('increment_id')
;
//echo $orders->getSelect();
//exit;
foreach ($orders as $order) {
$email = $order->getCustomerEmail();
echo $order->getIncrementId() . ": '" . $order->getStatus() . "', " . $email . "\n";
}
It fetches all order details. Please comment here if you have any doubt.

build category tree for categories and sub categories

i am trying to built category tree for the categories and sub categories in custom admin module, if possible to override the default category tree present in edit tab of product.
Below is the code which i am working, it is able to build category tree but it lack the checkbox ability. any sugestion would be appreciated
<?php
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function get_categories($categories) {
$array= '<ul>';
foreach($categories as $category) {
$cat = Mage::getModel('catalog/category')->load($category->getId());
$count = $cat->getProductCount();
$array .= '<li>'.
'<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
$category->getName() . "(".$count.")</a>\n";
if($category->hasChildren()) {
$children = Mage::getModel('catalog/category')->getCategories($category->getId());
$array .= get_categories($children);
}
$array .= '</li>';
}
return $array . '</ul>';
}
echo get_categories($categories); ?>
Please clarify your question as it's bad idea to override core functionality because same function is used by different modules instead you can check functionality of these
app/design/adminhtml/default/default/template/catalog/product/edit/categories.ph‌​tml app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
and then reflect these to your template files

Magento: get desription and image of child category

I'm using this code to display the child categories of a specific category in Magento:
$parentCategoryId = 3;
foreach Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $childCategory) {
echo $childCategory->getName() . '<br />';
echo $childCategory->getUrl() . '<br />';
}
That works quiet fine. But now I like to display description and category image of these child categories. I've tried it with the descriptions and added this line:
echo $childCategory->getDescription() . '<br />';
But the output is empty. Does anybody has an idea what I can do to display the description and later the category image?
Thank you for your help.
Please try this one, its working fine at my end
<?php
$parentCategoryId = 10;
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
$catArray = explode(',', $categories);
foreach($catArray as $child){
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
we will not get category description attribute from this function getChildrenCategories(). A better explanation about this function can be found here on Stackoverflow answer

How to make Categories with sub categories not linkable

Should be a simple question. But i've got a category list in Magento that has sub categories. And i want to make my categories with subs under then act as a title, instead of a clickable link to that category. So for instance:
Link 1
Link 2
Link 3 (this should be a title)
---Link 1
---Link 2
Link4
I'm getting my categories likes so.
<?php foreach ($helper->getStoreCategories() as $_category): ?>
<li> <?php echo $_category->getName() ?>
<?php foreach (Mage::getModel('catalog/category')->load($_category->getId())->getChildrenCategories() as $childCategory):?>
<?php echo '<li class="subCats">'.$childCategory->getName() .'</li>'; ?>
<?php endforeach;?>
</li>
<?php endforeach ?>
Any help would be greatly appreciated.
thanks
OK this is a bit of a hacky solution, but it worked for me. Firstly create a local copy of:
app > code > core > Mage > Catalog > Block > Navigation.php
Or if you know how to configure modules, extend the class and do it the proper way.
Look for the function called _renderCategoryMenuItemHtml.
Somewhere on the page create yourself an array of all the category names you want to exclude:
$categoryArray = array("Duplicate NCR", "Triplicate NCR", "Quadruplicate NCR");
Now just surround the tags with a standard if statement by replacing this:
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' title="'.$this->htmlEscape($category->getName()).'">';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';</code>
With this:
if(!in_array($this->htmlEscape($category->getName()), $categoryArray)) {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' title="'.$this->htmlEscape($category->getName()).'">';
}
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
if(!in_array($this->htmlEscape($category->getName()), $categoryArray)) {
$html[] = '</a>';
}
As I said, making a module of this would be the much better option, but in terms of a quick fix this will work perfectly.

Resources