Hide and show divs using PHP - php

So I have this code that requires to be a member. Now the question is what code do I add to hide two different divs called "socialsignup" and "formwrap". Another question is can you have multiple <?php code here ?>s in different places on the same page? Much appreciated with any help.
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>

You can wrap multiple time of PHP tags in a page.
That's answer for your fisrt and second question.
You can check like this
<?php if($val=='socialsignup') {?>
html for the social sign up
<?php } else if ($val=='formwrap') {?>
html for formwrap
<?php }else{?>
remaining conditions
<?php } ?>

Related

Content visibility based on multiple url values with strstr?

Using a Wordpress plugin to sort custom post types based on custom taxonomies. Results are returned on the post type's archive page. Sorting is working great but hit a snag trying to display header content for items with multiple taxonomies:
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating")) { ?>
<h3>These poses are invigorating:</h3>
<?php } ?>
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating/position/seated")) { ?>
<h3>These poses are invigorating and seated:</h3>
<p>For positions of this nature please take care of your sacrum.</p>
<?php } ?>
<?php if(strstr($_SERVER['REQUEST_URI'], "position/seated")) { ?>
<h3>These poses are seated:</h3>
<?php } ?>
"level/invigorating/position/seated" returns three h3's because all if's return true.
My PHP skills are awful and trying to understand the manual is like staring into the night sky.
How can this be written so only one value can be returned per page?
Perhaps this screenshot helps.
Using Beautiful Taxonomy Filters.
I believe what you are trying to do is this...
<?php if(strstr($_SERVER['REQUEST_URI'], "level/invigorating/position/seated")) { ?>
<h3>These poses are invigorating and seated:</h3>
<p>For positions of this nature please take care of your sacrum.</p>
<?php } elseif(strstr($_SERVER['REQUEST_URI'], "level/invigorating")) { ?>
<h3>These poses are invigorating:</h3>
<?php } elseif(strstr($_SERVER['REQUEST_URI'], "position/seated")) { ?>
<h3>These poses are seated:</h3>
<?php } ?>

Remove a href from php

On my website the following php code displaying a list of items but i would like to remove the hyperlink from each list item.
Could someone please help me with this?
<?php
foreach($features_item as $fet_item){
echo '<li>'.$fet_item->name.'</li>';
}
?>
This will do it:
<?php
foreach($features_item as $fet_item){
echo '<li>'.$fet_item->name.'</li>';
}
?>

Wordpress PHP multiple else statements

I am making a wordpress theme and i want to have some of the page templates with an extended header div tag so i can add extra things in.
This is the code i have:
<?php if (!is_page_template('page-homepage.php')) { echo "</div>"; } ?>
I want it so i can have alternatives to the page-homepage.php so for example page-team.php as i want that individual page template to not close the div yet either, i tried writing this but it just does every page:
<?php if (!is_page_template('page-homepage.php' or 'page-team.php')) { echo "</div>"; } ?>
Any ideas? My php skills are not very advanced!
thanks :D
You are making a logical operation on two strings ('page-homepage.php' or 'page-team.php') which evaluates to true, so the statement becomes:
<?php if (!is_page_template(true)) { echo "</div>"; } ?>
Try this instead:
<?php if (!is_page_template('page-homepage.php') && !is_page_template('page-team.php')) { echo "</div>"; } ?>

Stacking PHP code?

I've done a project that now needs to be changed in order to display one div if a variable is in an array and a different div if it isn't in the array.
Normally I'd just do
<?php $quartermonths = array("February","May","August","November");
if (in_array($month,$quartermonths))
{echo "quarter code in here";}
else
{echo "nonquarter code in here";}
?>
and be on my merry way, however the code I've got already contains a load of html and php code already, which doesn't like encapsulated within another PHP block (as far as I'm aware?)
e.g.
<?php $quartermonths = array("February","May","August","November");
if (in_array($month,$quartermonths))
{echo "Quarter HTML CODE
<?php quarter phpcode ?>";}
else
{echo "Non-Quarter HTML CODE
<?php non-quarter phpcode ?>";}
?>
So my question is, what is the best way to tackle this? Is it simply to do a javascript hide div A when the variable is met and hide divB when the variable isn't met, or is there a better solution?
Thanks
<?php
if (in_array($month,$quartermonths))
{ ?>
Quarter HTML CODE
<?php quarter phpcode ?>
<?php } ?>
split your html code from php code like this.
It sounds like you just want to concatenate the value of quarter phpcode. Let's say it's a single function, quarter_phpcode(). You can just do this:
{ echo "Quarter HTML CODE" . quarter_phpcode(); }

how to make create and make use of two headers. which can be accessed based on the page

I am newbi to wordpress. I have created a website in wordpress which has totally 6 pages.
here 5 pages use the same header, but only one page has different header. So i how can how to create new header.
header.php(is used by all 5 pages): In this case is used "get_header();" in page.php to call the header.
home.php(to be used by home page). here is ther any possible way to access these new header
Please check the link
if link is www.test.com/home.php
then use
<?php if($_SERVER['REQUEST_URI'] == 'home.php') { ?>
<h1>Header for the Homepage</h1>
<?php } else { ?>
<h1>Header for other pages</h1>
<?php } ?>
There's different ways to do this. The easiest would be to use is_home() in header.php to check if the currently loaded page is the homepage. You could change the header.php to something like:
<?php if(is_home()) { ?>
<h1>Header for the Homepage</h1>
<?php } else { ?>
<h1>Header for other pages</h1>
<?php } ?>

Categories