I am trying add an if statement to an anchor like so.
<div class="box-button">
<a href="
<?php $header_button = of_get_option('header_text'); ?>
<?php if($header_button){?>
<?php echo of_get_option('header_text'); ?>
<?php } else { ?>
#
<?php } ?>
" class="button">Connect Now</a>
</div>
I can click the button on the homepage and I will get linked to "#" so it is as if wordpress doesn't recognize as a theme option. Is my syntax the problem?
You know you can do the logic outside the html and then insert the result into the href
<?php
$header_button = of_get_option('header_text');
$link = (!empty($header_button)?$header_button:'#');
?>
<div class="box-button">
Connect Now
</div>
Related
I need to know How to pass variable between two web pages with PHP without using session , have a DIV link in which inside there is id i want to pass to another page when a link is clicked but i fail to do it. please help me:
firstpage.php ( where there is a link) :
......
<?php
$identity = $_POST['book_id'];
while($ResultsRow=mysql_fetch_array($res)) {
?>
<div class="col-md-2 offset-md-2">
<div class='thumbnail'>
<a href="shopping.php?<?php echo $identity?>" target="blank">
<input type="text" name="book_id" value="<?php echo
$ResultsRow['id'] ?>">
</div>
</div>
</a> <!-- end of link -->
..........
Secondpage.php (where i want to retrieve book id):
....
<p> <?php $myvarC = $_POST['identity'];
echo $myvarC;
?> </p>
....
I think you should try something like below:
firstpage.php
<a href="shopping.php?identity=<?php echo $identity?>" target="blank">
secondpage.php
<p> <?php $myvarC = $_GET['identity'];
echo $myvarC;
?> </p>
You can include it in the urlquery like
shopping.php?id=1234
and then read it on the other side.
You can do this by $_GET;
First Page
<a href="shopping.php?id=<?php echo $identity?>" target="blank">
Second Page
<?php $myvarC = $_GET['id'];
echo $myvarC;
?>
Create a correct url with parameters
<a href="shopping.php?id=<?php echo $identity?>" target="_blank">
And get that value using
<?php
$myVarC = $_GET['id'];
echo $myVarC
?>
First Page
<a href="shopping.php?identity=<?php echo $identity?>" target="blank">
Second Page
<p> <?php $myvarC = $_REQUEST['identity'];
echo $myvarC;
?> </p>
I'd like to know if it's possible to open a page (id=26) at a specific position: .
At the front page i'm using this code at the php file to make the title link to the page
<a href="<?php echo get_page_link(26); ?>">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
Yes, you can use DOM selectors such as #maincontent. You would need to assign an ID to a section on the page and then append it to the trigger URL.
For ex: http://yourdomain.com/index.html#maincontent would take you to that div on the page.
First, in the content of that page (id=26), you need to add an id attribute to some tag, like so:
<div id="myposition">
...
</div>
Next, append #myposition after the get_page_link(26) call:
<a href="<?php echo get_page_link(26); ?>#myposition">
<?php if(!empty( $clean_biz_home_service_title ) ){ ?>
<h2>
<?php echo esc_html( $clean_biz_home_service_title); ?>
</h2>
</a>
And you are done.
<div name="position">
content
</div>
link
example:
if you click the link below you will open this page at #new-answer position
link
I am a beginner and trying to use PHP statement inside <a> tag of HTML. I don't know whether it is possible or not and I tried to search it on Google, but I couldn't find any answer. Below is the code I am trying to execute.
Whenever I run this code, I do not get any error but the my browser does not display the value of $link1, $link2 and $link3 which I put inside the <a> tag of HTML.
I saved the document as index.php
<?php
$title = 'Shellitic';
$link1 = 'Home';
$link2 = 'Contact';
$link3 = 'About';
?>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1> Welcome to <?php echo $title; ?> </h1>
<p></br></p>
<p>To visit our home page, click on the <?php $link1; ?> button</p>
<p>To visit our contact page, click on the <?php $link2; ?> button</p>
<p>To visit our About page, click on the <?php $link3; ?> button</p>
</body>
You need to echo the values:-
<?php echo $link1; ?>
Some servers may accept this
<?= $link1; ?>
But it is typically safer to use
<?php echo $link1; ?>
Add echo command.
Like this:
<?php echo $link1; ?>
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.
I created a conditional statement for my custom theme in Concrete5. My codes goal is to toggle layout. If the current page has a child pages under it, it will display an additional sidebar (<div class="grid_3">) to list the subpages items. If there's no child page it would display a full layout (<div class="grid_13">).
Unfortunately I get a different result. there's something I probably had missed on my condition statement. Instead of just display one layout, It is rendering the two layout.
Below is what my code look like:
<? if($c->getNumChildren()) { ?>
<div class="grid_3">
<?php
$bt_sidenav = BlockType::getByHandle('autonav');
$bt_sidenav->controller->orderBy = 'display_asc';
$bt_sidenav->controller->displayPages = 'below';
$bt_sidenav->controller->displaySubPages = 'all';
$bt_sidenav->render('view');
?>
</div>
<div id="main-content-container" class="grid_10">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } else { ?>
<div id="main-content-container" class="grid_13">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } ?>
While your content generation portions of PHP use proper PHP tags (<?php … ?>), your if/else statements use short tags (<? … ?>) which are often disabled.
Use <?php instead.
try to do like this may this will solve the issue
<?php if($c->getNumChildren()!='') { ?>
...
<?php } else { ?>
...
<?php } ?>