In WordPress I need to fetch the Author image of author who created post. I tried to get the profile image in this way, but it didn't work.
Here is the code I have written to get other author_meta_details.
<div class="row">
<div class="avatar col-md-3">
<picture class="avatar-circle">
<?php if($avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?>
<img src="<?php echo $avatar; ?>" alt="">
<?php else: ?>
<img src="/wp-content/themes/lymited-child/images/avatar-image.png">
<?php endif; ?>
</picture>
</div>
<div class="author-details col-md-9">
<div class="author-name"><strong><?php echo get_the_author_meta('first_name'); ?></strong> - <?php echo get_the_author_meta('nickname'); ?>
</div>
<div class="author-summery"><?php echo get_the_author_meta('description'); ?>
</div>
</div>
</div>
Try this
<?php
$get_author_id = get_the_author_meta('ID');
$get_author_gravatar = get_avatar_url($get_author_id, array('size' => 450));
if(has_post_thumbnail()){
the_post_thumbnail();
} else {
echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';
}
?>
OR Remove this if the condition and try
echo get_avatar( get_the_author_meta('ID') );
get_avatar() returns <img> element so you don't need to wrap it to img again
Also you need to wrap $avatar = ... to parenthesis as = priority is lower than !==
try to replace this
<?php if ( $avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?>
<img src="<?php echo $avatar; ?>" alt="">
with this
<?php if ( ( $avatar = get_avatar(get_the_author_meta('ID')) ) !== FALSE): ?>
<?php echo $avatar; ?>
Related
I have problem with mysqli_query. When last user upload image, all user have last image.
This code that I have write:
<?php
$query = mysqli_query($soci->con, "SELECT soci.*, (SELECT full_path FROM soci_media WHERE id = soci.immagine_profilo) AS immagine_profilo_file FROM soci");
while($socio = mysqli_fetch_assoc($query)) {
?>
<div class="col-sm-12 col-md-6 col-lg-4 single_socio pb-3">
<?php if($soci->user_data['immagine_profilo_file'] == '') { ?>
<img src="<?php echo get_site_url(); ?>/wp-content/themes/test/images/user.png" alt="" class="default_image img-fluid" />
<?php } else { ?>
<img src="<?php echo get_site_url(); ?>/uploads<?php echo $soci->user_data['immagine_profilo_file']; ?>" alt="" class="default_image img-fluid" />
<?php } ?>
<h2><?php echo $socio['nome']; ?> <?php echo $socio['cognome']; ?></h2>
</div>
<?php
}
?>
Screenshot table database and result
Instead of using the select clause to do another query (it will not work). You should join the tables. I used a left join to avoid not having values if there is no profile image.
SELECT soci.*,soci_media.full_path AS immagine_profilo_file
FROM soci
LEFT JOIN soci_media ON soci.immagine_profilo = soci_media.id
You need to replace your query like this:
$query = mysqli_query($soci->con, "SELECT soci.*,soci_media.full_path AS immagine_profilo_file FROM soci LEFT JOIN soci_media ON soci.immagine_profilo = soci_media.id");
In addition you need to assign the current variables:
while($socio = mysqli_fetch_assoc($query)) {
?>
<div class="col-sm-12 col-md-6 col-lg-4 single_socio pb-3">
<?php if($socio['immagine_profilo_file'] == '') { ?>
<img src="<?php echo get_site_url(); ?>/wp-content/themes/test/images/user.png" alt="" class="default_image img-fluid" />
<?php } else { ?>
<img src="<?php echo get_site_url(); ?>/uploads<?php echo $socio['immagine_profilo_file']; ?>" alt="" class="default_image img-fluid" />
<?php } ?>
<h2><?php echo $socio['nome']; ?> <?php echo $socio['cognome']; ?></h2>
</div>
<?php
}
I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22
I have this most annoying problem; I'm trying to arrange three divs on a row, and then new row, and another three divs and so on, like this:
<div class="container">
<div class="row">
<div class="col-sm-1">1</div>
<div class="col-sm-1">2</div>
<div class="col-sm-1">3</div>
</div>
<div class="row">
<div class="col-sm-1">4</div>
<div class="col-sm-1">5</div>
<div class="col-sm-1">6</div>
</div>
</div>
As for this accepted answer,
There is one catch: 0 % 3 is equal to 0. This could result in
unexpected results if your counter starts at 0.
So how would i implement this into this code:
<div class="col-md-8">
<?php
foreach($this->movies->movie_data as $key => $movie){
$string = file_get_contents("http://example.com/?t=" . urlencode($movie->movie_titel). "&y=&plot=short&r=json");
$result = json_decode($string);
if($result->Response == 'True'){
?>
<div class="col-sm-4">
<?php if($result->Poster == 'N/A') : ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<?php else: ?>
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo $result->Poster; ?>" class="img-responsive img-thumbnail"></a>
<?php endif; ?>
<div><b><?php echo $result->Title; ?></b></div>
<div><i><?php // echo $result->Plot; ?></i></div>
</div>
<?php }else{ ?>
<div class="col-sm-4">
<a href="<?php echo Config::get('URL')?>ladybug/day/<?php echo $this->city ?>/<?php echo $movie->movie_id ?>">
<img src="<?php echo Config::get('URL')?>/images/na.png" class="img-responsive img-thumbnail"></a>
<div><b><?php echo $movie->movie_titel ?></b></div>
<div class="plot"><i><?php //echo 'N/A' ?></i></div>
</div>
<?php }}} ?
</div>
For some reason, divs is arranged like this:
My question: How do I arrange thumbnails on a new row, every third time?
Found the answer in the other Q... Didn't read, sorry about that.
<?php }
if (($key + 1) % 3 == 0) { ?>
</div>
<?php }
}} ?>
I am creating a online webstore. But i am stuck in calling out the selected value to be used on the next page.
My Product summary page code,
<?php
include 'productData.php';
if (isset($_GET['cat']) && isset($productArr[$_GET['cat']])) {
$selected = $productArr[$_GET['cat']];
}
foreach ($selected as $productName => $productDescriptionArr):
?>
<div>
<div>
<a class="thumbnail" href="productDetailPage.php?cat=<?= $selected; ?>&code=<?= $productName; ?>">
<img src="<?php echo "img/" . $productDescriptionArr['image'] ?>" class="img-rounded" width="250" height="220">
<div><h3><?php echo $productName; ?></h3></div>
</a>
</div>
</div>
<?php endforeach; ?>
</body>
</html>
My Product Detail Page,
<html>
<body>
<?php
include 'productData.php';
if (isset($_GET['cat']) && isset($productArr[$_GET['cat']])) {
$selected = $productArr[$_GET['cat']];
if (isset($_GET['code']) && isset($productName[$_GET['code']])){
$name = $productName[$_GET['code']];
}
}
foreach ($selected as $name => $productDescriptionArr):
foreach ($productDescriptionArr as $key => $value) :
?>
<div>
<div>
<img src="<?php echo "img/" . $productDescriptionArr['image'] ?>" class="img-rounded" width="250" height="220">
<div class="title"><h3><?php echo $name; ?></h3></div>
</a>
</div>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
</body>
</html>
in sort, select "PT", moves to page with all "PT" product, and end at the specific selected "PT" product in the product detail page.
I have edited your code for product detail page.. As you've not defined $productName variable anywhere in page. I've customized your code and hope it'll be good for you..
include 'productData.php';
<?php
if (isset($_GET['cat']) && isset($productArr[$_GET['cat']])) {
$productNames = $productArr[$_GET['cat']]; //Added $productNames here to asign your current product category
}
foreach($productNames as $name=>$details):
if (isset($_GET['code']) && $name==$_GET['code']){
//$name is product name.
//print_r($details);
// now you can use $details['images'], $details['dimension'], $details['price'] as you want...
?>
<div class="category">
<div class="col-md-3">
<a class="thumbnail">
<img src="<?php echo "img/" . $details['image'] ?>" class="img-rounded" width="250" height="220">
<div class="title"><h3><?php echo $name; ?></h3></div>
</a>
</div>
</div>
<?php } ?>
<?php endforeach; ?>
so i guess this is pretty easy for most of you, but i can't figure this out.
im trying to make the links dynamic eg: href="linkname(#1 or #2 etc)"
any ideas?
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(GENERATE CODE HERE)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>
Suppose below is what you need.
<?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
<?php foreach ($top_fundraisers as $index => $fundraiser): ?>
<a title="" class="fancybox" href="linkname(#<?php echo $index + 1; ?>)">
<div class="top-fundraiser">
<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
<img src="<?php
if($fundraiser['member_pic_medium']) {
print htmlentities($fundraiser['member_pic_medium']);
} else {
print $template_dir . '/images/portrait_placeholder.png';
}
?>"/>
</div>
</div>
</a>
<?php endforeach;?>
<?php endif; ?>