Data-binding and php error - php

Hi this is what I'm trying to do.
What I'm trying to do is if the data-bind id() is equal to 1 or 2 hide it , but show all the others.
<?php if($authUser->Plan=='3'){ ?>
<div class="image-item" data-bind="visible: id() == 1,2, css:{hide}" data-bind="css:{active: ($parent.theme()==id())}">
<?php } ?>
Thank you.

<?php if($authUser->Plan=='3'){ ?>
<div class="image-item" data-bind="visible: ('simple'==id()) || ('amelia'==id()), css:{active: ($parent.theme()==id())}">
<?php } ?>

Related

Hide ACF fields when one of them are empty

i use the following code with custom fields:
But the problem is; when did not put any content in one of custom field it need be hide.
the class style of the other effect it, and that is something I don’t want to show.
<div class = "class2">
<? php the_sub_field ('filed2'); ?>
</div>
<div class = "class1">
<? php the_sub_field ('filed1'); ?>
</div>
I want hide one of both custom filed when on of them is empty.
How can i hide it?
<?php if (get_sub_field ('filed2') || get_sub_field('filed1'));{ ?>
<div class = "class2">
<? php the_sub_field ('filed2'); ?>
</div>
<div class = "class1">
<? php the_sub_field ('filed1'); ?>
</div>
<?php } ?>
You would want to wrap it in an if statement.
You can also do (if you need the conditional logic on a per-field basis):
<?php if (get_sub_field ('filed2'));{ ?>
<div class = "class2">
<? php the_sub_field ('filed2'); ?>
</div>
<?php }; if (get_sub_field ('filed1'));{ ?>
<div class = "class1">
<? php the_sub_field ('filed1'); ?>
</div>
<?php }; ?>

How to hide a <Div> using PHP

Hi I have used some code but I want it so when the name is NULL it is hidden, if this is possible please help.
Here is the code
<p id="top"><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>Welcome To the homepage of The Journalist's</p>
I want it to be when name is NULL, for
"<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]"
to be hidden.
Thank you.
update...
This is what i have so far
This is what i have so far.
<?php
if ($SESSION['name']= NULL) {
?>
<div><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]</div>
<?php
}
?>
I have fixed it , thank you for everyone that has commented. for anyone else with this problem. here is my solution.
<?php
if ($_SESSION['name']!= NULL) {
?>
<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>
<?php
}
?>
Update from your posted code:
For one, you are using $SESSION instead of $_SESSION. Second, you are setting $SESSION['name'] using a single equal sign, so the if condition would always fail because it is evaluating if (NULL). You need to use == or ===. Read up on comparison operators.
<?php
if (condition) {
?>
<div></div>
<?php
}
?>

Hide Div title if there's no content

I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.
I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.
Here is the code:
<div class="customfields">
<h2 class="widgettitle">My Title</h2>
<?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
I would very much appreciate your help!
Thanks a ton,
T.
So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<div class="customfields">
<?php if(!empty($taxonomy)) : ?>
<h2 class="widgettitle">My Title</h2>
<?php echo $taxonomy; ?>
<?php endif; ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.

How do I return TRUE or FALSE from MySQL within PHP function?

I am experimenting with PHP. This is my func.php
function returnBlankStylist(){
$sql=mysql_query("SELECT * FROM `".$dbn."`.`stylist` WHERE `stylist`.`customer_id`='1'");
if (mysql_affected_rows()==0) {
return false;
} else {
return true;
}
}
This is my page.tpl
<?php if (returnBlankStylist==false){?>
<div class="center graybox"> Please enjoy this discount since this you have never filled out a query before</div>
<? }?>
If the customer Id 1 exists it shows the message, and if the customer Id 1 does not exist it shows the message?
Page.tpl
<?php if (returnBlankStylist() == false) : ?>
<div class="center graybox">
Please enjoy this discount since this you have never filled out a query before
</div>
<? endif; ?>
or
<?php if (!returnBlankStylist()) : ?>
<div class="center graybox">
Please enjoy this discount since this you have never filled out a query before
</div>
<? endif; ?>
or
<?php if (returnBlankStylist() == false) { ?>
<div class="center graybox">
Please enjoy this discount since this you have never filled out a query before
</div>
<? } ?>
you have missed parenthises ..
if(returnBlankStylist()==false){
//your code...
}
hope it will work for you
Please replace your code if (mysql_affected_rows()==0) to if (mysql_num_rows()==0);
and try this:
<?php if (!returnBlankStylist()){?>
<div class="center graybox"> Please enjoy this discount since this you have never filled out a query before</div>
<? }?>

How to remove anchor from active navigation page using PHP?

I am sure this is a fairly simple question to answer, but I am new to PHP, so I was hoping someone could help me solve this problem.
I have a dynamic navigation menu that works really well, but I want to remove the link from the current page in the menu.
Here is my code:
<div id="navigation_menu">
<?
foreach($pagedata->menu as $menuitem){
$class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';
?>
<div id="<?=$menuitem->uri?>" class="<?=$class?>">
<img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
<h1><?=$menuitem->title?></h1>
<h2><?=$menuitem->description?></h2>
<img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
</div>
<?
}
?>
</div>
Any help would be greatly appreciated. Thanks!
UPDATED CODE: (this is what works for me now)
<div id="navigation_menu">
<?
foreach($pagedata->menu as $menuitem){
$class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';
?>
<div id="<?=$menuitem->uri?>" class="<?=$class?>">
<img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
<h1>
<?php if ($menuitem->uri == $requesteduri):?>
<?=$menuitem->title;?>
<?php else: ?>
<?=$menuitem->title?>
<?php endif;?>
</h1>
<h2><?=$menuitem->description?></h2>
<img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
</div>
<?
}
?>
</div>
I don't know what your loop is outputting, but you want to match your page name with the menuitem->uri. So you'd get your page name like.. (Put this outside the loop)
<?php echo base_name($_SERVER['REQUEST_URI']); ?>
find out what your loop is outputting (Put this in the loop):
<?php echo $menuitem->uri; ?>
Then you'd create an if statement to compare the current menuitem in the loop and the page request, this is just an example:
<h1>
<?php if (base_name($_SERVER['REQUEST_URI']) == $menuitem->uri):?>
<?=$menuitem->title?>
<?php else: ?>
<?=$menuitem->title;?>
<?php endif;?>
</h1>
Put a conditional around the anchor text to see if $menuitem->uri is equal to the current page URL, accessible from `$_SERVER['REQUEST_URI'] before outputting the anchor tags.

Categories