How can I add a link to the following line?
if ($image) echo $image->resize('w=272&h=170');
I have tried adding something like
if ($image) echo ''$image->resize('w=272&h=170')'';
if ($image) {
echo '' . $image->resize('w=272&h=170') . '';
}
Try the following (untested):
if ($image) echo '<img src="' . $image->resize('w=272&h=170') . '"/>';
The result from $image->resize() in wordpress renders the destination... A better solution would be the following:
if($image && ($imageResized = $image->resize('w=272&h=170'))) {
echo '' . $imageResized . '';
}
You can do this:
echo ($image ? ''. $image->resize('w=272&h=170'). '' : '');
Related
I need some help with solving duplicating problem. To deal:
I have 2 filed custom meta
It displays this way :
Only 2 image placed, but it duplicate <li>.
First and third <li> is only video, second and fourth works fine, looks like this :
foreach($slider_xml->childNodes as $slider){
$test_test = get_post_meta(9,'test_1', false);
foreach($test_test as $test_test){
echo '<li class="img-vid-slide">';
echo '<iframe src="https://www.youtube.com/embed/'. $test_test . '" frameborder="0" allowfullscreen></iframe>';
}
echo '<div class="img-slide" >';
if($link_type == 'Lightbox'){
$image_full_url = wp_get_attachment_image_src(find_xml_value($slider, 'image'), 'full');
echo '<a href="' . $image_full_url[0] . '" data-rel="prettyPhoto[flexgal]" title="" >';
}else if($link_type != 'No Link'){
echo '<a href="' . $link . '" >';
}
echo '<img class="'. $i .'" src="' . $image_url[0] . '" alt="' . $alt_text . '" />';
echo '</div>';
if( !empty($title) ){
echo '<div class="flex-caption gdl-slider-caption">';
echo '<div class="gdl-slider-title">' . $title . '</div>';
echo '<div class="slider-title-bar"></div>';
echo $caption;
echo '</div>'; // flex-caption
}
if($link_type != 'No Link'){
echo '</a>';
}
echo '</li>';
}
I find solution.
Filed custom fields: prntscr.com/7oqqvt
I named them like "name_1","name_2"..."name_4".
$i is equal of last nubmer in custom field.
Result on screen: prntscr.com/7oqsaw
$i = 1;
while ($i <= 3):
foreach( $slider_xml->childNodes as $slider ){
// ======= SAME AS FIRST ====== //
$test_test = get_post_meta(9,'test_'. $i .'', true);
echo '<iframe src="https://www.youtube.com/embed/'. $test_test . '" frameborder="0" allowfullscreen></iframe>';
echo '<div class="img-slide" >';
if($link_type == 'Lightbox'){
// ======= SAME AS FIRST ====== //
}
echo '</li>';
$i++;
}
endwhile;
Works fine for me, do what i searching for!
Thanks, Greg, for a little hint, but i go for "while" instead of "for"! Good luck
Don't use the a foreach inside a foreach loop. It a function problem.
Use the alternative "for" loop instead of the double foreach.
I'm trying to make a shortcode for displaying logged in user avatar from buddypress
// user avtar
function user_avatar() {
$user_avatar_url = bp_loggedin_user_avatar('type=full&html=false');
$user_image = '<img src="' . $user_avatar_url . '"/>';
return $user_image;
}
add_shortcode('avatar', 'user_avatar');
but when I try to insert shortcode [avatar], the HTML output looks like this:
http://localhost/.../images/bp_default_avatar.jpg <img src=""></img>
Somehow image url/src appears before 'img' tag?
Try using $userimage = "<img src='$user_avatar_url' />";
instead
Apparently it was the buddypress issue, I changed a few things and now it's working
// user avtar
function user_avatar() {
$userid = bp_loggedin_user_id();
$user_avatar_url = $avatarurl = bp_core_fetch_avatar( array( 'item_id' => $userid, 'html' => false ) );
$user_image = '<img src="' . $user_avatar_url . '"/>';
return $user_image;
}
add_shortcode('avatar', 'user_avatar');
try like these
<?php
function user_avatar()
{
$user_avatar_url = bp_loggedin_user_avatar( 'type=full&html=false' );
$user_image = '<img src="' . $user_avatar_url . '"/>';
return $user_image;
}
add_shortcode('avatar', 'user_avatar');
?>
My following code is based on
1.Get current URL
2.Go through array and check if in url value = to value in array
do this:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
Loader::model('page_list');
$nh = Loader::helper('navigation');
$pl = new PageList();
$pl->filterByAttribute('city', '%' . $city . '%', 'like');
$pl->filterByAttribute('category','%'.$category_is.'%','like');
$pl->sortByDisplayOrder();
$pagelist = $pl->get();
foreach ($pagelist as $p) {
echo '<li> ' .htmlspecialchars($p->getCollectionName()) . ' </li>';
?>
}
}
}
}
So It will show me only pages that have the same attribute with URL
Each of this page has image attribute that I want to show.
How can I pass this Image Attribute??
Check out the comments in the page list block's view template:
https://github.com/concrete5/concrete5/blob/master/web/concrete/blocks/page_list/view.php#L33
You can get image attributes by putting some code like this inside your foreach ($pagelist as $p) loop:
$img = $p->getAttribute('example_image_attribute_handle');
if ($img) {
//you could output the original image at its full size like so:
echo '<img src="' . $img->getRelativePath() . '" width="' . $img->getAttribute('width') . '" height="' . $img->getAttribute('height') . '" alt="" />';
//or you could reduce the size of the original and output that like so:
$thumb = Loader::helper('image')->getThumbnail($img, 200, 100, false); //<--200 is width, 100 is height, and false is for cropping (change to true if you want to crop the image instead of resize proportionally)
echo '<img src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" />';
}
Thx but I did it already just another way!
I didnt used
Loader::model('page_list');
Instead I used:
$blockType = BlockType::getByHandle('page_list');
And hardcoded the block!
$th = Loader::helper('text');
$ih = Loader::helper('image');
$page_current = Page::getCurrentPage();
$page_2 = $page_current->getCollectionHandle();
$img = $page->getAttribute('product'); $thumb =
$ih->getThumbnail($img, 240,150, false);
And after I changed a little bit my Code above:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
$city_att = $page->getAttribute('city', '%' . $city . '%', 'like');
$sub_cat_att = $page->getAttribute('category','%'.$category_is.'%','like'); ?>
<?php if($city == $city_att && $category_is == $sub_cat_att){ ?><li><img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<h3> <?php echo $title ?></h3>
<div class="product_description">
<?php echo $description ?>
</div>
Read More...
</li> <?php } ?> <?php
}
}
}
So everything it is working But still thx for respond! Apreciate
I have the following WordPress query:
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
echo '<div class="' . $tax_term->slug . '" style="display:none; background:url(' . $whatdoiputhere . ');">';
while ($my_query->have_posts()) : $my_query->the_post();
In the background URL, I need to include an image URL that is generated by the following code:
<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>
How would I include this IF function inside the background URL?
I tried this but as you can guess it didn't work:
background:url(' . if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); . ');
Would appreciate some help as to how I would do this.
<?php
if (function_exists('z_taxonomy_image_url')) $background_url = 'background:url(' . z_taxonomy_image_url() . ')';
echo '<div class="' . $tax_term->slug . '" style="display:none; ' . $background_url . '">';
?>
Ternary operator:
background:url(' . (function_exists('z_taxonomy_image_url') ? z_taxonomy_image_url() : '') . ');
I'd do something like this:
<?php
if (function_exists('z_taxonomy_image_url')) {
echo "background:url('" . z_taxonomy_image_url() . "');";
}
?>
If you wanted, you could set a default background image via an else clause, otherwise the background definition will just not exist in your CSS.
I am currently trying to add in alt img tags for an existing website running the interspire shopping cart platform, I have gotten pretty close I bleieve, but i cannot seem to get it right. Any help would be grealty appreciated.
// Is there a thumbnail image we can show?
$thumb = $GLOBALS['ISC_CLASS_PRODUCT']->GetThumb();
$alttext = $GLOBALS['ISC_CLASS_PRODUCT']->GetProductName();
if ($thumb == '' && GetConfig('DefaultProductImage') != '') {
if (GetConfig('DefaultProductImage') == 'template') {
$thumb = GetConfig('ShopPath').'/templates/'.GetConfig('template').'/images/ProductDefault.gif';
} else {
$thumb = GetConfig('ShopPath').'/'.GetConfig('DefaultProductImage');
}
$thumbImage = '<img src="'.$thumb.'" alt="->GetProductName" />';
} else if ($thumb != '') {
$thumbImage = '<img src="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'.$thumb.'" alt=""'.$alttext.'" />';
}
I have tried posting the code but it says new users cannot post image tags for some reason
It looks to me like you have two double quotes after you open the alt attribute, then the text, then another closing quote.
This line won't work
$thumbImage = '<img src="'.$thumb.'" alt="->GetProductName" />';
You probably want something like this
$thumbImage = '<img src="'.$thumb.'" alt="'.$GLOBALS['ISC_CLASS_PRODUCT']->GetProductName().'" />';
//or as you have already set $alttext:
$thumbImage = '<img src="'.$thumb.'" alt="' . $alttext . '" />';
ylebre meant: (scroll the code box to the right)
} else if($thumb != '') {
$thumbImage = '<img src="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'.$thumb.'" alt=""'.$alttext.'" />';
}
^
|
there is one extra " at the end!
} else if($thumb != '') {
$thumbImage = '<img src="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'.$thumb.'" alt="' . htmlspecialchars($alttext) . '" />';
}