substr not working with $item->getTitle - php

I'm making a website with Joomla and am using RokSprocket to display some news. Now, some Titles are too long, so I wanted to shorten it after a certain character number, but it's not working. Am a total php noob, my apologies.
Here's the whole code:
<li data-lists-item>
<h4 class="sprocket-lists-title ">
<?php if ($item->custom_can_have_link): ?><a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>"><?php endif; ?>
<?php if(strlen($item->getTitle)>10)
echo substr($item->getTitle,0,10) . ' ...';
else
echo $item->getTitle();?></a>
<div class="date"><?php echo date('d.M. Y', strtotime($item->getDate()));?></div>
</h4>
<span class="sprocket-lists-item" data-lists-content>
<span class="sprocket-padding">
<?php if ($item->getPrimaryImage()) :?>
<img src="<?php echo $item->getPrimaryImage()->getSource(); ?>" class="sprocket-lists-image" />
<?php endif; ?>
<?php echo $item->getText(); ?>
<?php if ($item->getPrimaryLink()) : ?>
<span><?php rc_e('READ_MORE'); ?></span>
<?php endif; ?>
</span>
</span>
</li>
I'm hoping it's something very obvious and I'm just being stupid. Thanks a bunch already!

$item->getTitle is probably a method not a property, so try:
$item->getTitle(); // <-- parenthesis
Change to:
<?php if(strlen($item->getTitle())>10)
echo substr($item->getTitle(),0,10) . ' ...';

Related

Wordpress - strange symbol appeared beside the post thumbnail

Sorry I feel it an idiot question, but I can't fix it, those characters "> appeared beside the post thumbnail, and I don't know what's wrong there!
<?php
$notification_id = $notification->ID;
$notification_time = strtotime($notification->post_date);
$type = get_post_meta($notification_id, 'dw_notification_type', true);
$custom_type = get_post_meta($notification_id, 'dw_notification_custom_type', true);
$image = get_post_meta($notification_id, 'dw_notification_image', true);
?>
<li id="dw-notif-<?php echo $notification_id;?>" class="<?php echo dwnotif_check_user_read(false, $notification_id)?'read':'unread'; ?> <?php echo $type?$type:''; ?> <?php echo $custom_type?$custom_type:''; ?>" data-time="<?php echo $notification_time;?>">
<a href="<?php echo get_permalink($notification->ID);?>">
<div class="notif-avatar">
<?php if(has_post_thumbnail($notification->ID)): ?>
<?php echo get_the_post_thumbnail($notification->ID, 'post-thumbnail'); ?>
<?php elseif($image): ?>
<img src="<?php echo $image; ?>">
<?php else: ?>
<img src="<?php echo dwnotif_default_image(); ?>">
<?php endif; ?>
</div>
<div><?php echo $notification->post_title; ?></div>
<date class="notif-time"><?php echo human_time_diff( $notification_time, current_time('timestamp') ) . __( ' ago', 'dw-notifications' ); ?></date>
</a>
</li>

Working with multiple breadcrumbs in a knowledge base

I am working with Heroic Knowledge Base, and I am having trouble getting only one breadcrumb to show up (their suggested CSS code is not working). Unfortunately, I am not a PHP expert, and I am not sure how to edit the code so that it only shows one of the lines that it is pulling (we don't care which one) I have added the PHP from their breadcrumbs file. Any assistance would be greatly appreciated.
<?php
/**
* Breadcrumbs template
*/
?>
<?php if(hkb_show_knowledgebase_breadcrumbs()): ?>
<!-- .hkb-breadcrumbs -->
<?php $breadcrumbs_paths = ht_kb_get_ancestors(); ?>
<?php foreach ($breadcrumbs_paths as $index => $paths): ?>
<ol class="hkb-breadcrumbs" itemscope
itemtype="http://schema.org/BreadcrumbList">
<?php $last_item_index = count($paths)-1; ?>
<?php foreach ($paths as $key => $component): ?>
<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">
<?php if($key==$last_item_index): ?>
<span itemprop="item">
<span itemprop="name"><?php echo
$component['label']; ?></span>
</span>
<?php else: ?>
<a itemprop="item" href="<?php echo $component['link']; ?>">
<span itemprop="name"><?php echo $component['label']; ?></span>
</a>
<?php endif; ?>
<meta itemprop="position" content="<?php echo $key+1; ?>" />
</li>
<?php endforeach; ?>
</ol>
<?php endforeach; ?>
I was able to solve this issue using the following code, however I would like to make it so that it is only effective when there is more than one.. the code below worked on articles with two breadcrumbs, but when there is only one it hid them all together.
ol.hkb-breadcrumbs {
display: table-column-group;
}

Magento, showing payment of a product conditions on the homepage

have a phtml file riding the payment of the value of a product, the function responsible for it automatically puts on every page of the product installment conditions, but does not appear the payment terms on the homepage where I coloto one "carousel "for featured products.
Someone would have a hint of what I do?
Note 1: I use a AllPago the module to set the conditions only that I can not use the stand for the value that do not have access.
Note 2: according to the source code that assembles the installments for me (file name in magento to find looks like this: allpago_installments / productviewtable.phtml
<?php foreach ($this->getInstallments() as $installment): ?>
<?php $result = count($this->getInstallments()); ?>
<?php if($installment->getValue()==$result):?>
<div class="product-view-parcel">
<?php echo $installment->getValue() . ' x ' . $installment->getInstallment() . ' ' . $installment->getMessage(); ?>
</div>
<?php endif;?>
<?php endforeach; ?>
Note 3: a part of the home page code where I try to call the price and conditions (heeding the price appears correctly only the payment terms that do not):
<div id="ripplesslider" class="ripplesslider" style="height: 470px!important;">
<?php foreach ($_productCollection_slider as $_product): ?>
<div id="slide" style="text-align: center !important;height: 470px!important;"
class="latest-slider-item slide slider<?php echo $_product->getId() ?>">
<a href="<?php echo $_product->getProductUrl() ?>"
title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<div style="height: 200px!important;">
<img onmouseover="mouseover(<?php echo $_product->getId() ?>)"
onmouseout="mouseout(<?php echo $_product->getId() ?>)"
style="width:<?php echo $t ?>px;
height:<?php echo $imageheight ?>px; "
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image'); ?>"
alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
</div>
</a>
<div class="desc-item">
<div class="carousel-name-product"> <?php echo $_product->getName() ?></div>
<div class="latest-price">
<?php if ($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php $this->getPriceHtml($_product, true) ?>
<?php echo '<span czlass="price">' . str_replace('R$','', $this->getPriceHtml($_product, true)) . '</span>'; ?>
</div>
</div>
</div>
<?php endforeach ?>
</div>
haha staff already got, I'll post here what I did to perhaps help others.
<div>
<?php echo '<span class="price">' . str_replace('R$','', $this->getPriceHtml($_product, true)) . '</span>'; ?>
<?php // object reference?>
<?php $reference = Mage::getStoreConfig('allpago/installments/active'); ?>
<?php//returns a new object. references ?>
<?php $installmentModel = Mage::getModel('installments/'.$reference); ?>
<?php //access the parameters to get the conditions have to function "getInstallmentHighest" to return the plots?>
<?php $installmentModel->setValue($_product->getFinalPrice()); ?>
<?php $installment = $installmentModel->getInstallmentHighest(); ?>
<span style="text-align: left;color: #A8A0A8;position: absolute;margin-top: -46px !important;margin-left: -78px !important;font-size: 12px;">
<?php echo $installment->getValue().' x '. $installment->getInstallment() . ' ' . $installment->getMessage(); ?>
</span>
</div>

Multilingual slideshow

I have this code for a slideshow in my Drupal 7, Nexus 7.x-1.3 theme.
My website is multilingual and I need to use a different image for every language, eg. I would like to change slide-image-1.jpg (en language) with other image-name for (gr language).
My code:
<?php if ($is_front): ?>
<?php if (theme_get_setting('slideshow_display','nexus')): ?>
<?php
$slide1_head = check_plain(theme_get_setting('slide1_head','nexus')); $slide1_desc = check_markup(theme_get_setting('slide1_desc','nexus'), 'full_html'); $slide1_url = check_plain(theme_get_setting('slide1_url','nexus'));
$slide2_head = check_plain(theme_get_setting('slide2_head','nexus')); $slide2_desc = check_markup(theme_get_setting('slide2_desc','nexus'), 'full_html'); $slide2_url = check_plain(theme_get_setting('slide2_url','nexus'));
$slide3_head = check_plain(theme_get_setting('slide3_head','nexus')); $slide3_desc = check_markup(theme_get_setting('slide3_desc','nexus'), 'full_html'); $slide3_url = check_plain(theme_get_setting('slide3_url','nexus'));
?>
<div id="slidebox" class="flexslider">
<ul class="slides">
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-1.jpg'; ?>"/>
<?php if($slide1_head || $slide1_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide1_head; ?></h2><?php print $slide1_desc; ?>
<a class="frmore" href="<?php print url($slide1_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-2.jpg'; ?>"/>
<?php if($slide2_head || $slide2_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide2_head; ?></h2><?php print $slide2_desc; ?>
<a class="frmore" href="<?php print url($slide2_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
<li>
<img src="<?php print base_path() . drupal_get_path('theme', 'nexus') . '/images/slide-image-3.jpg'; ?>"/>
<?php if($slide3_head || $slide3_desc) : ?>
<div class="flex-caption">
<h2><?php print $slide3_head; ?></h2><?php print $slide3_desc; ?>
<a class="frmore" href="<?php print url($slide3_url); ?>"> <?php print t('CONTACT US'); ?> </a>
</div>
<?php endif; ?>
</li>
</ul><!-- /slides -->
<div class="doverlay"></div>
</div>
<?php endif; ?>
<?php endif; ?>
Is there any solution for that? Thank you.
There is a Drupal connector from Smartling that may be of help. Here is a video showing how the connector works.
Many sites running on Smartling do language/country-specific image replacement, which is explained here.
Hope this helps,
Nataly
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<SCRIPT>
function english(){
$(#image).attr('src','http://link.to.your/english/image.png')
}
function greek(){
$(#image).attr('src','http://link.to.your/greek/image.png')
}
</SCRIPT>
<IMG id="image" src="http://link.to.your/greek/image.png">
Change to English<BR>
Change to Greek
Finally I fixed it in page.tpl with php code. One if/else on your page language to set you picture path.
Regards, HashKey

php foreach generating trash

I have here a quite complicated loop what I would like to modify while is not really working as I expected. The problem is: my if statements else condition is generating trash and I don't really know where the problem comes
<div id="container">
<?php include 'header.php';
foreach ($vars as $item):
if (is_array($item['productItems'])):?>
<div class="product_box">
<h4>
<?php echo $item['title']?>
</h4>
<?php foreach($item['productItems'] as $products):?>
<?php foreach($products as $key=>$product):?>
<div class="product">
<div class="image_holder">
<a href="<?php echo $product['image']['medium'];?>" class="preview">
<img src="<?php echo $product['image']['small'];?>"
alt="gallery thumbnail" title="" />
</a>
<?php foreach($product['trackingLinks'] as $key=>$trackinglink): ?>
<a href="<?php echo $trackinglink[0]['ppc']?>"> <span><?php echo $product['name'];?>
</span>
</a>
</div>
<h5>
<?php echo 'Preise: '. $product['price'].' '.$product['currency'];?>
</h5>
<span><?php echo 'Versand Kosten: '.$product['shippingCosts'].' EUR';?>
</span>
<p>
<?php echo (substr($product['descriptionLong'], 0,150 )).'...mehr';?>
</p>
<a class="shopping_button"
href="<?php echo $trackinglink[0]['ppc']?>">zum Shop</a>
</div>
<?php endforeach ?>
<?php endforeach ?>
<?php endforeach ?>
<div class="ajax_bar">
<select id="ajax_call" size="1" name="Weitere Produkte">
<option value='50'>Weitere Produkte</option>
<option value='100'>weitere 100</option>
<option value='150'>weitere 150</option>
</select>
</div>
</div>
<?php else: ?>
<div class="text_box">
<h2>
<?php echo $item['title'];?>
</h2>
<p>
<?php echo $item['text'];?>
</p>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php include 'footer.php';?>
</div>
I'm going to make a wild guess here and say that this is because you don't escape your output using htmlspecialchars or htmlentities.
If you're not sure what's inside the for-loop, use this nifty construct to debug on page:
echo '<pre>', htmlspecialchars(print_r($vars, true)), '</pre>';
It also helps to look at the page source instead; this usually gives vital clues as to why your page layout is so messed up.
Update
Okay got it! It's because of this:
<?php else: ?>
<div class="text_box">
<h2>
<?php echo $item['title'];?>
</h2>
<p>
<?php echo $item['text'];?>
</p>
The $item is a string here, and $item['title'] is understood by PHP as $item[0] which is the first character of $item :)

Categories