Reputation: 29
<?php
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
'ptitle' => '',
), $atts )
);
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(!empty($ptitle)){
echo 'Whoops! Looks like went wrong here!';
}
else
{
if($postid == false)
{
echo '<span class="ptitle">$ptitle</span>';
}
else
{
echo '<span class="ptitle"><a href="site.com/$postid">$ptitle</a></span>';
}
}
I'm trying to have my code do the following
(This is where I need help)
2- That if another value is empty, it echo this <span class="ptitle">$ptitle</span>
3- If the other value ($postid) has something in it then it echoes <span class="ptitle"><a href="site.com/$postid">$ptitle</a></span>
However I just don't understand enough empty values and "false" to create this correctly
Upvotes: 0
Views: 175
Reputation: 5
I'm a noob but i think your'e missing the word echo before the strings you want to display and remove the ! sign
something like this:
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(empty($ptitle)){
echo "Whoops! Looks like went wrong here!"
}else{
if($postid == false) {
echo "<span class="ptitle">$ptitle</span>"
} else {
echo "<span class="ptitle"><a href=site.com/".$postid.">".$ptitle".</a></span>"
}
}
Upvotes: 0
Reputation: 74217
If you want it to display if something is "empty", you're using the wrong method with if(!empty($ptitle)){
you're telling it if it is NOT empty.
The !
is a negation character which translates as not
.
You need to use if(empty)
Plus, you also need to echo
while inside PHP.
Another thing, your $ptitle
will not echo while inside single quotes.
Use the following:
Sidenote: You may want to change if($postid == false)
to if($postid == true)
<?php
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
'ptitle' => '',
), $atts )
);
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(empty($ptitle)){
echo "Whoops! Looks like went wrong here!";
}else{
if($postid == false) {
echo "<span class=\"ptitle\">$ptitle</span>";
} else {
echo "<span class=\"ptitle\"><a href=\"site.com/$postid\">$ptitle</a></span>";
}
}
You can also try:
<?php
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
'ptitle' => '',
), $atts )
);
$postid = $atts['postid'];
$ptitle = $atts['ptitle'];
if(empty($ptitle)){
echo "Whoops! Looks like went wrong here!";
}
if(empty($postid)) {
echo "<span class=\"ptitle\">$ptitle</span>";
}
if(!empty($postid)) {
echo "<span class=\"ptitle\"><a href=\"site.com/$postid\">$ptitle</a></span>";
}
Upvotes: 2
Reputation: 920
see if this works for you
if(empty($ptitle)){
echo 'Whoops! Looks like went wrong here!';
} else if (empty($postid)) {
echo "<span class='ptitle'>$ptitle</span>";
} else {
echo "<span class='ptitle'><a href='site.com/$postid'>$ptitle</a></span>";
}
Upvotes: 0