houseofstrauss
Member
Posted 2 years ago #
I'm trying to implement the code here to pull an image from a tag. Taken from codex here
There seems to be a parse error on line 21, the last curly brace before the closing php. Can someone see what it wrong in the code here?
<?php
if ($all_the_tags);
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
if ($this_tag->name == "sometag" ) {
?>
<p>SOME HTML CODE <img src="someimage.jpg"></p>
<?php } else if ($this_tag->name == "someothertag" ) { ?>
<p>SOME OTHER HTML CODE <img src="someotherimage.jpg"></p>
<?php } else {
// it's neither, do nothing
?>
<!-- not tagged as one or the other -->
<?
}
}
}
?>
Try:
<?php
if ($all_the_tags) {
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
if ($this_tag->name == "sometag" ) {
?>
<p>SOME HTML CODE <img src="someimage.jpg"></p>
<?php}
elseif ($this_tag->name == "someothertag" ) { ?>
<p>SOME OTHER HTML CODE <img src="someotherimage.jpg"></p>
<?php }
else {
// it's neither, do nothing
?>
<!-- not tagged as one or the other -->
<?php
}
?>
houseofstrauss
Member
Posted 2 years ago #
Thank-you esmi for your help here. I am now getting a parse error on line 10 <?php}
Please note: this code is in the loop as required.
Thanks for any further help.
Try:
<?php
if ($all_the_tags) {
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
if ($this_tag->name == "sometag" ) { ?><p>SOME HTML CODE <img src="someimage.jpg"></p><?php}
elseif ($this_tag->name == "someothertag" ) { ?><p>SOME OTHER HTML CODE <img src="someotherimage.jpg"></p><?php }
}
}
else {
// it's neither, do nothing ?>
<!-- not tagged as one or the other -->
<?php
}
?>
houseofstrauss
Member
Posted 2 years ago #
Thanks esmi, that seems to have done the trick! I think elseif does not like to be separted to 2 words... else if