Hello inspirationally,
I think you will not need the foreach loop if you just want to drop into a particular header.
Can you try something like
<?php $headers = get_uploaded_header_images();
at the top of the page, then when you call a header just use
echo $headers[0]['url'];
or echo $headers[1]['url'];
When you are inside the foreach, $header will only have one occurrence of the header with the array holding the meta information for that particular header. Keeping in the headerS array will allow you to pick from any.
Of course you may have to do some error checking to make sure you do have the number header you are calling.
Let me know if that works at all.
Drew
Hey Drew,
thanks very much.
unfortunately, this throws the same error:
Notice: Undefined offset: 0 (or 1).
I also tried
$headers = get_uploaded_header_images();
$i="0";
while ($i < 1000) {
echo $headers[$i]['url'];
$i++;
}
just to catch all possible numbers of this relatively new installation.
They all throw the same error, as if you simply can’t call them with numbers.
Kind regards, Martina.
Does indeed seem strange,
Have you tried printing the $headers array, to see how it is made up?
<pre>
<?php print_r ($headers); ?>
</pre>
Hey Drew,
I’m no php-professional (obviously), so I did not know this handy php function, which is of a big help, thank you!
This tells me
Array ( [header-11.jpg] => Array ( [attachment_id] => 104 [url] => http://example.org/wp-content/uploads/2015/09/header-11.jpg [thumbnail_url] => http://example.org/wp-content/uploads/2015/09/header-11.jpg [alt_text] => [width] => 2362 [height] => 1550 )
and so on.
And with
echo $headers[“header-11.jpg”][‘url’];
I can indeed echo the URL to that image. Just that it varies depending on the image name, so that it does not make any sense to write that.
Now I continued thinking about that and came to this solution (stopping the foreach loop after two steps):
$headers = get_uploaded_header_images();
$i=0;
foreach($headers as $key => $header) {
$header=$header['url'];
$i++;
if($i==2) break;
}
echo $header;
for the second header.
I also wrote a little function for the functions.php, and it works with just additional_header_image(2); in the template files.
/************* ADDITIONALL HEADER IMAGE *************/
function additional_header_image($n=2) {
$headers = get_uploaded_header_images();
$i=0;
foreach($headers as $key => $header) {
$header=$header['url'];
$i++;
if($i==$n) break;
}
echo $header;
}
Thank you, Drew, for your great help giving me the right direction.
Martina.