Wordpress Mobile Detect Plugin and if echo issues - php

I'm using WP Mobile Detect to see if site visitors are on a mobile device. The Plugin is installed and I'm good on that front.
Now, I'm trying to setup an if / else php statement to display a tel: link to mobile browsers and a non link phone number to everyone else. The code below breaks my theme.
<?php
if (function_exists('wpmd_is_phone')) {
echo "<li><a class="phone' href="tel:<?php echo ot_get_option('phonenumbercontent') ?>"><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></a></li>";
} else {
echo "<li><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></li>";
}
?>

Your code is not correct, for example (not properly concatenated)
echo "<li><span class="phone"><?php echo ot_get_option('phonenumbercontent') ?></span></li>";
You may try this
<?php
if (function_exists('wpmd_is_phone') && wpmd_is_phone()) {
echo "<li><a class='phone' href='tel:" . ot_get_option('phonenumbercontent') . "'><span class='phone'>" . ot_get_option('phonenumbercontent') ."'</span></a></li>";
} else {
echo "<li><span class='phone'>" . ot_get_option('phonenumbercontent') . "</span></li>";
}
?>
Also, the plugin doc says, you can use
[phone]Put content here that you only want displayed on Phones NOT Tablets or Desktops[/phone]
[notphone]Put content here that you only want displayed on Tablets OR Desktops NOT Phones[/notphone]

Related

Getting Value from clicked div's ID - php mysql issue

I am currently beginning in php mysqli connections and such, and I'm working on a real estate website design prototype.
As of now I've managed to create a search form which displays every single house available for purchase listed in the mysql database.
Now my task is that when the user clicks one of the homes it activates another .php form which shows a more detailed page.
I'm trying to figure out the proper way to do this.
I'm guessing when the user clicks the div he wants, the php form should get a unique value from said div to query the database for that specific property but I'm at a loss here.
This is the Code for the listed available homes:
<?php
echo "<div id='parent'>";
echo "<section class='responsive HomeBox filterDiv' id='";
echo $resultados['tipo']."";
echo "'>";
echo "<div class='HomeBoxImg'>";
echo "<img class='img-thumbnail img-responsive' alt='Forest'
src='img/propiedades/";
echo $resultados['nombre']."";
?>
/1.jpg' onerror="this.src='img/default.jpg'">
<?php
echo "</div>";
echo "<div class='HomeBoxInfo'>";
echo "<h1>";
echo $resultados['direccion']."";
echo "<h2>";
echo $resultados['estructura']."";
echo "- ";
echo $resultados['tipo']."";
echo "</h2>";
echo "</h1>";
echo "<hr style='width:100%;'>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/bed.png'' alt='Dormitorios'>";
echo "<h4>Dormitorios</h4>";
echo "<h5>";
echo $resultados['dormitorios']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/rooms.png'' alt='Ambientes'>";
echo "<h4>Ambientes</h4>";
echo "<h5>";
echo $resultados['ambientes']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/toilet.png'' alt='Baños'>";
echo "<h4>Baños</h4>";
echo "<h5>";
echo $resultados['baños']."";
echo "</h5>";
echo "</div>";
echo "<div class='homeboxdetailboxes'>";
echo "<img src='img/icons/price.png'' alt='Precio'>";
echo "<h4>Precio</h4>";
echo "<h5>";
echo $resultados['precio']."";
echo "</h5>";
echo "</div>";
echo "</div>";
echo "</section>";
echo "</div>";
?>
So what I'm missing would be the php form for displaying a whole new page based on an id or something provided by the user clicking on of these items.
You can use Javascript/JQuery here, like you can add following
echo '<div id="parent" class="number_<?php echo $resultados['nombre']; ?>">';
then to get specific elements id you can use:
var unique_id = document.getElementById('#parent').className.split('_')[1] //Javascript
var unique_id = $('#parent').attr('class').split('_')[1]; //Jquery
than you can use Ajax request or you can use javascript to change url of current page like:
window.location.href = 'https://www.some_url/'+unique_id;
or you can even wrap each estate item inside , and inside this form put hidden input element like:
<input type="hidden" name="unique_number" value="<?php echo $resultados['nombre']; ?>">
and hook on click event on Javascript or JQuery to submit the form.

Images wont show to guests, only admin

Im currently busy with working on a website but I got stuck.
The site is running on Processwire and working with the FeatherLight lightbox.
Now the strange thing is, I am only able to see the images when I'm logged in as admin. When I'm just a guest (incognito) the site won't show these images but shows the other pages.
You can find the website over here
I've looked at the page settings in the CMS, and the guest is able to view the pages, as it also does with the text pages.
But I can't figure out how to get the images back.
Here is the code
<div id="container">
<div class="grid-sizer"></div>
<?php if ($page->numChildren(true)) {
echo "<ul class='project'>";
foreach ($page->children as $childIndex => $child) {
if ($child->head_image) {
$image = $child->head_image;
echo "<li class='item'><a href='#' data-featherlight='#mylightbox" . $childIndex . "'><img id='mylightbox" . $childIndex . "' src='{$image->url}' class='image'></a></li>";
}
}
echo "</ul>";
}
?>
<style>
.featherlight-content:after {
content: "<?php echo nl2br($child->title); ?> <?php echo nl2br($child->image_description); ?> <?php echo $child->formaat; ?>";
}
</style>
Thanks in advance!

how to style a php form using css

i have made a form using php this is my code
<?php
echo "<div class='error_msg'>";
echo validation_errors();
echo "</div>";
echo form_open('user_authentication/new_user_registration');
echo form_label('Create Username : ');
echo"<br/>";
echo form_input('username');
echo "<div class='error_msg'>";
if (isset($message_display)) {
echo $message_display;
}
echo "</div>";
echo"<br/>";
echo form_label('Email : ');
echo"<br/>";
$data = array(
'type' => 'email',
'name' => 'email_value'
);
echo form_input($data);
echo"<br/>";
echo"<br/>";
echo form_label('Password : ');
echo"<br/>";
echo form_password('password');
echo"<br/>";
echo"<br/>";
echo form_submit('submit', 'Sign Up');
echo form_close();
?>
the form is supposed register new users
how can i style this form using css given that there is no html in the code.
The echo(); function you are using essentially prints HTML, this HTML can be styled by including a style sheet (Google CSS basics and you will quickly find out how to do this).
I would advise running this script and using the web inspector of your chosen browser to look at the HTML code you have created using your PHP code. Again, if your not familiar with the web inspector Google how to open it on your chosen browser.
Hope this clarifies things a bit :)

how to make selected links to become bold

I'm learning php following some tutorials
but the codes are not working as directed by the tutorials.
I want to make a selected page to become bold. these are the codes.
<?php
$subject_set = get_all_subjects();
while($subject = mysqli_fetch_array($subject_set)) {
echo "<li";
if ($subject["id"] == $sel_subj) {
echo "class=\"selected\"";
}
echo "><a href=\"content.php?subj=" . urlencode
($subject["id"]) . "\">{$subject["menu_name"]}</a></li>";
$page_set = get_all_pages_for_subject($subject["id"]);
echo "<ul class=\pages\">";
while($page = mysqli_fetch_array($page_set)) {
echo "<li><a href=\"content.php?page=" . urlencode
($page["id"]) . "\">{$page["menu_name"]}</a>
</li>";
}
echo "</ul>";
}
?>
In your HTML document you need this
<head>
<style>
li.selected{
font-weight: bold;
}
</style>
</head>
Currently you are setting the selected list item to have a class of "selected" but your not actually assigning the css class "selected" from the limited example you provided.
You can learn more here:
http://www.w3schools.com/cssref/pr_font_weight.asp

Dynamic link in IF/ELSE statement

I apologize for any misuse of terminology...I'm a noob...
I have a dynamically created page that contains a dynamic link. I added an IF/ELSE statement to display a different word based on the number of items in the variable $rowsphoto.
The different words display correctly, but the URL that is generated contains all of the PHP instead of generating the correct URL.
This is the original code, which works fine:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">Additional works in Portfolio:</div>
This is the code I have after adding the IF/ELSE statement:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">
<?php
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
?>
</div>
I ran the code through a couple syntax checks and they all came back with no errors. What am I doing wrong? Is this even possible?
You'd be better off using it correctly like this:
<?php if($portfolioid != 0): ?>
<div class="extrafield">
<?php if($rowsphoto <= 4): ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>
<?php else: ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>
<?php endif; ?>
</div>
<?php endif; ?>
You're mixing html and php very badly. You should be separating them to keep your code clean and concise.
Your issue with it displaying the php instead of the correct variables is because (as #scrowler said):
You can't use PHP tags inside PHP, you just need to escape the string
bounds and use the . concatenation operator instead of trying to open
new PHP tags, e.g. echo "String here" . $varname; as opposed to echo
"String here"
While Darren's answer is correct, alternatively you can just stay inside of php
<?php
if($portfolioid != 0) {
echo '<div class="extrafield">';
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
echo '</div>';
}
?>

Categories