These are the custom fields composition:
1 Group Footer
1.1 Group Col2
1.1.1 bbcimg (this is the image ID)
1.1.2 bbc-rss (this is the RSS feed ID)
I have the following code displaying the bbc-rss:
<div class="col-md-3">
<?php
$footer = get_field('footer'); // 'footer' is your parent group
$col2 = $footer['col2']; // 'col2' is your child group
?>
<div class="widget_item widget_latest sm-m-top-50">
<h4 id="white" class="text-white">Latest News</h4>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/bbc_rss.png" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['bbc-rss'];?></p>
</div>
</div>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/reuters_rss.png" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['reuters-rss'];?></p>
</div>
</div>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/cnbc.jpg" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['cnbc-rss'];?></p>
</div>
</div>
</div><!-- End off widget item -->
</div><!-- End off col-md-3 -->
I have created the image field bbcimg with the following properties:
Field label: bbcimg
Field Name: bbcimg
Field Type: image
Instructions: -
Required: No
Return Format: Image Array
Preview Size: Medium(300x300)
Library: All
Minimum: Width 40px, Height px 40 File size - MB
Minimum: Width - px, Height px - File size - MB
Allowed file types: -
Conditional Logic: -
Wrapper Attributes: -
And the image is already uploaded in the custom field. See picture:
Question:
How to write the logic to display the picture on the website?
Thank you very much in advance!
been trying to use
First you need to find out what is getting returned inside the custom field.
Add a good old print_r to your code somewhere:
<?php print_r($col2['bbcimg']) ?>
That will print out an array of values like Array( 'url' => 'http....something.jpg', 'size'=>'full', ..etc)
Then you can identify which array value gives you the full URL to the image. Say in this case it would be a field called url, then you can use that value as follows:
<div id="gris" class="widget_latst_item_text">
<img src="<?php echo $col2['bbcimg']['url']; ?>" alt=""/>
<p><?php echo $col2['bbc-rss'];?></p>
</div>
Related
I'm making a custom WordPress theme with pinegrow editor and I'm using slick slider for my slides (not the WordPress plugin!). Here is the code of one item of my slider with custom dot thumb:
<div class="item" data-thumb="images/realmix/products/fresh-energy.png">
<div class="row productz">
<div class="col-md-7 col-lg-7 doesle col-sm-5 col-xs-12">
<img src="images/realmix/products/energy-panel.png">
</div>
</div>
</div>
and this is the php code i get from that code snippet from exporting the wordpress theme:
<div class="item" data-thumb="images/realmix/products/fresh-energy.png">
<div class="row productz">
<div class="col-md-7 col-lg-7 doesle col-sm-5 col-xs-12">
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/realmix/products/energy-panel.png">
</div>
</div>
</div>
now the problem is my slider dot images won't get loaded because pinegrow does not convert the data-thumb src into php.
Trying to add the php echo at the data-thumb like this:
data-thumb="<?php echo esc_url( get_template_directory_uri() ); ?>images/realmix/products/fresh-energy.png"
does not work when i upload to wordpress, still shows no images
How can i fix that by myself?
Not sure i'm following your correctly. I'll update if I am off track.
Maybe try using get_bloginfo('template_url') function instead?
data-thumb="<?=get_bloginfo('template_url)?>/images/realmix/products/fresh-energy.png"
This will go to the immediate child images folder in your current theme folder.
In relation to your comment on questions/64405779 linking to this question, for that script to work with your php, would be as follows...
<div class="slider">
<div class="item" data-thumb="<?=get_bloginfo('template_url')?>/images/realmix/products/fresh-energy.png">
<div class="row productz">
<div class="col-md-7 col-lg-7 doesle col-sm-5 col-xs-12">
<img src="<?=get_bloginfo('template_url')?>/images/realmix/products/energy-panel.png" alt="" />
</div>
</div>
</div>
<!-- next slides here -->
</div>
And the script would be...
// my slick slider options
const options = {
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
arrows: false,
adaptiveHeight: true,
autoplay: true
};
// my slick slider as const object
const mySlider = $('.slider').on('init', function(slick) {
// set this slider as const for use in set time out
const slider = this;
// slight delay so init completes render
setTimeout(function() {
// dot buttons
let dots = $('.slick-dots > LI > BUTTON', slider);
// each dot button function
$.each(dots, function(i,e) {
// slide id
let slide_id = $(this).attr('aria-controls');
// custom dot image
let dot_img = $('#'+slide_id).data('thumb');
$(this).html('<img src="' + dot_img + '" alt="" />');
});
}, 100);
}).slick(options);
and the css would be the same from questions/64405779
I'm pulling a list of news articles from the database and I'm putting them in a bootstrap card. My problem is when the news title is longer obviously the paragraph will be in a different position, look at the picture to better understand the problem
I have tried to set different margins and padding styles but I know it needs to be dynamic depending on the title size but what's the best possible way to do that? Here is my code.
<div class="item card ">
<img src="public/img/news/<?= $singleNews['news_image']; ?>" class="card-img-top" alt="blog">
<div class="card-body">
<a href="passion.html">
<h5 class="card-title ">
<?= $singleNews['news_title']; ?>
</h5>
</a>
<div class="card-paragraph ">
<p>
<?php
// $shortDetail = strlen($singleNews['news_short_detail']) > 70 ? substr($singleNews['news_short_detail'],0,70):$singleNews['news_short_detail'];
echo $singleNews['news_short_detail']; ?>
</p>
</div>
read more
</div>
</div>
There are two options
OPTION1: set min-height of title tag and align it to center via line-height or flex.
OPTION2: set specific height and then font-size to vw unit so that it adjust it self with overflow:hidden
I am new to WordPress and I wanted to create a dynamic "team-component" with ACF. For this I have created two fields for "headline" and "subline" + one "profiles" group with sub-groups "profile_1", "profile_2",...
Every sub-group has three different fields: "full_name", "job_titel", "image".
Now, with first sub-field "profile_1" everything is fine.
With second I am able to pull "full_name" and "job_titel" but not "image" from back-end.
If I type print_r("profiles"), all I can see is that within array "image" is not present for "profile_2" and it is for "profile_1", although I have previously uploaded through wp-admin.
<?php
$profiles = get_field('profiles_team_component');
if ($profiles): ?>
<!-- Profile 1 -->
<div class="profile-wrapper">
<div class="image-wrapper">
<div class="image" style="background-image: url(<?php echo $profiles['profile_1']['image']['sizes']['profile-pic'] ?>) "></div>
</div>
<h4 class="ourteam"><?php echo $profiles['profile_1']['full_name'] ?></h4>
<p class="ourteam"><?php echo $profiles['profile_1']['job_titel'] ?></p>
</div>
<!-- Profile 2 -->
<div class="profile-wrapper">
<div class="image-wrapper">
<div class="image" style="background-image: url(<?php echo $profiles['profile_2']['image']['sizes']['profile-pic'] ?>) "></div>
</div>
<h4 class="ourteam"><?php echo $profiles['profile_2']['full_name'] ?></h4>
<p class="ourteam"><?php echo $profiles['profile_2']['job_titel'] ?></p>
</div>
<?php endif; ?>
Thanks for your help!
If you want to generate dynamic 'team-component' from ACF, for that you would need to install ACF Repeater field so you can easily generate dynamically team-component and show each of the filed using PHP loops. For more details, you should follow below link: ACF
I have a php function to retrieve the three most recent entries to a table that holds news highlights. Here is my function:
function getHighlights(){
return $this->query("
SELECT *
FROM `highlights`
ORDER BY `inserted` DESC
LIMIT 3
");
}
These highlights are then placed on my homepage via a foreach loop. Here is my code:
<?php foreach($highlights as $a){ ?>
<div class="col-md-6 highlight">
<div class="highlightItem">
<img class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
<?php } ?>
I'd like for my homepage to ALWAYS be in this format:
News Highlight Format. However, the only reason it's in that format right now is because the images have predefined sizes that fit nicely together.
I want to be able to reference the most recent news highlight and set that image to always display as 300 x 210. I also want to reference the next two highlights and set them to always display as 300 x 100.
What's the best course of action for this?
<?php foreach($highlights as $index => $a){ ?>
if($index == 0){
<div class="col-md-6 highlight">
<div class="highlightItem">
<img width="300" height="210" class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
}else{
<div class="col-md-6 highlight">
<div class="highlightItem">
<img width="300" height="100" class="highlight-backdrop" src="<?=$a->backdrop;?>">
<p class="highlight-title"><?=$a->title;?></p>
</div>
</div>
}
<?php } ?>
try to use that code
I have double tables one for products and one for files, files table have multi images related to the one product.
I want to show only one image for each product not all of them.
I make this code but it's back with the for example 3 times with the first image!
#foreach($lastProducts as $key => $lastProduct)
#if($key == 1)
<div class="bl-thumb">
<img src="{{url('website/'.$lastProduct->path.$lastProduct->->file}}">
</div>
#endif
#endforeach
I need to show the first image at my page and other pages show the second and third image for the product.
And here's my view which want to show all images on it :
<div class="slim-scroll">
<div class="item active">
<img src="/website/images/{{$product->image_1}}" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/website/images/{{$product->image_2}}" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/website/images/{{$product->image_3}}" alt="" class="img-responsive" />
</div>
<div class="item">
<img src="/website/images/{{$product->image_4}}" alt="" class="img-responsive" />
</div>
</div>
It's showing me something like that without the foreach
If I understand correctly, you have multiple products and each product has multiple images. If on page 1 you want to display product 1 image 1, product 2 image 1, product 3 image 1...then on page 2 you want to display product 1 image 2, product 2 image 2, product 3 image 2 you could try something like this:
Page 1:
#foreach($products as $product)
<div class="bl-thumb">
<img src="{{url('website/' . $product->images->pull('1')->path . $product->images->pull('1')->file}}">
</div>
#endforeach
Page 2:
#foreach($products as $product)
<div class="bl-thumb">
<img src="{{url('website/' . $product->images->pull('2')->path . $product->images->pull('2')->file}}">
</div>
#endforeach
Really this logic should be in the controller though. You could use a get variable to define what page you are on and filter for the proper image before you render the page.