Main section appears weirdly on wordpress with elementor - php

i have been having some issues displaying pages properly on the website i'm working,
since an exemple is worth a thousand explanation go visit that web page and you'll see that the main section appears weirdly https://www.lannuaire.fr/0645325643/ .
I've made it dynamic by using this code and calling this function with a shortcode on the page,
the template that it loads is the whole blue section,
public function affiche_tel_non_trouve ()
{
$tel = get_query_var('tel');
$suffixe = $tel[1] ;
if (isset($suffixe) && $suffixe != '6' && $suffixe != '7') {
echo do_shortcode('[elementor-template id="2021"]');
} else if ($suffixe == '6' || $suffixe == '7') {
echo do_shortcode('[elementor-template id="2266"]');
}
}
I've been searching why I have this problem for too long I now am out of clue, I suspect that it is an optimization problem,
so now i seek help, to know why is that happening.
Thank you for your time
(Sorry for the approximate english)
i've also tried loading only the white section since it is the important part but it won't solve the problem, also this display problem doesn't appear using firefox and it is less visible on opera (i'm using chrome).

Related

Using isset on !$myvar['var']

I'm currently working through a large number of warnings I have logged after my server was updated to PHP 8.
One particular point that has me scratching my head is the following code block
if (!$option['type'] || $option['type'] == "select") {
$output .= '<b>'.$option['title'].':</b>';
}
I know that I can use isset($option['type']) like this
isset($option['type']) && $option['type'] == "select"
but confused how that would work for
!$option['type']
How can you be checking if isset, but also it being NOT. If it's NOT, then surely it isn't set anyway?
The test for "may not exist or may be falsey" is:
if (empty($option['type']))

PHP that displays different button depending on time not working consistently

This code was inherited from a previous version of our site http://iowacrisischat.org. It's supposed to show one button if it's between 12pm-2am central time, and another button if it's outside of those hours.
It's working on and off in Chrome, and displaying not only the wrong button but an OLD version of the button in IE and Firefox. I've tried deleting my cookies but it still displays an old version of the button that isn't even in the most recent file uploaded to the site.
So I guess a couple questions. 1) Is the time part of the code what's making Chrome inconsistent? Should it be 0-23 instead of 12 hours, does it need to have minutes? 2) Why would IE and Firefox be showing an old version of the code.
Thank you for any help!!
function crisischat()
{
date_default_timezone_set("America/Chicago");
$hour = date('G', time());
$duringHours = ($hour >= 12 || $hour < 2);
$isProblem = FALSE;
if ($duringHours) {
echo '<div id="chatbtn">.Chat Now.</div>';
} else if ($isProblem) {
echo 'We are experiencing technical difficulties. Please call our crisis line at 1-855-325-4296.';
} else {
echo '<div id="chatbtn">-Chat Now-';
}
}
crisischat();

PHP session changes unexpectedly in if statement and ignores echo command

I'm setting $_SESSION['showroom'] to 'active' when a particular page in Wordpress is displayed:
if(get_the_ID()==6470||get_the_ID()==252){
$_SESSION['showroom']='active';
}
I then set 2 arrays of pages to check against. If the next page displayed is NOT in one of these arrays, $_SESSION['showroom'] gets changed to 'inactive'.
$allowed_templates = array('template-A.php',
'template-B.php',
'template-C.php',
'template-E.php',
'template-G.php');
$allowed_ids = array(6470,252);
$template_name = get_page_template_slug();
$page_id = get_the_ID();
if(in_array($template_name,$allowed_templates)==false && in_array($page_id,$allowed_ids)==false){
$_SESSION['showroom']='inactive';
}
The if statement works most of the time, but sometimes my $_SESSION['showroom'] changes to inactive EVEN though one of the arrays is returning true! After several hours of testing I am unable to locate where the problem is. Echoing out the two parts of the if statement ALWAYS gives me 2 trues or 1 true + 1 false, but never 2 falses:
if(in_array($template_name,$allowed_templates)==false){echo 'TFALSE';}
if(in_array($template_name,$allowed_templates)){echo 'TTRUE';}
if(in_array($page_id,$allowed_ids)==false){echo 'IFALSE';}
if(in_array($page_id,$allowed_ids)){echo 'ITRUE';}
What am I missing here?
Thanks in advance for any help!
EDIT: Have continued testing and found the following anomaly:
if(in_array($template_name,$allowed_templates)==false && in_array($page_id,$allowed_ids)==false){
$_SESSION['showroom']='inactive';
echo 'SET TO INACTIVE';
}
The if statement changes $_SESSION['showroom'] to 'inactive' but DOES NOT echo out 'SET TO INACTIVE'!
There's something strange going on here!
Problem solved. My code was fine. Two missing images files were causing WordPress to crash my sessions. Took 10 hours to find out but happy I found it. Thanks to everyone for their help.
You can try the following;
if(!in_array($template_name,$allowed_templates) && !in_array($page_id,$allowed_ids)){
$_SESSION['showroom']='inactive';
}
Edit: lets try and break it down further... similar to your examples
if(!in_array($template_name,$allowed_templates){
echo "not in templates,";
}
if(!in_array($page_id,$allowed_ids)){
echo "not in ids,";
}
if(!in_array($template_name,$allowed_templates) && !in_array($page_id,$allowed_ids)){
echo "not in both\n";
}
then see if we get a result with not in templates,not in ids, but no trailing not in both
The problem is pure logical. Lets look at this statement:
if (in_array($template_name,$allowed_templates)==false && in_array($page_id,$allowed_ids)==false)
Which translates to "If the template is not valid AND page is not valid"
This means that both statements needs to be fulfilled in order to mark session as inactive. What if the template is fine, but the page is not valid? That definitely should be marked as inactive as well.
By changing the statement to read "If the template is not valid OR page is not valid", we cover up the invalid cases. Because either of them counts as an invalid state, and thus, only one of them needs to be false in order for everything to be false. (the OR-statement)
So code-wise it would be
if (in_array($template_name,$allowed_templates)==false || in_array($page_id,$allowed_ids)==false)
And you are set.
As and addition. I would structure the code as you noted works. Which is more logical. That is, mark it as inactive whenever it's should be treated as inactive, in all other cases mark it as 'active'. Or vice-versa.

PHP Search Filter on different pages

I'm trying to get my different search filters to pop up on different pages. I have an example here:
<?php
if(basename($_SERVER['REQUEST_URI']) == 'bedrijfsaanbod') {
include_once(VIEW_PATH . '/includes/filter.bedrijfsaanbod.php');
} else {
include_once(VIEW_PATH . '/includes/filter.makelaars.php');
}
?>
That is what I came up with so far. The problem however is that my URL changes as soon as the search gets conducted, which means it'll automatically show the /includes/filter.makelaars.php again. Any tips on how to tackle this problem?

How to know site open in mobile or PC browser?

I am developing site in php with responsive HTML. Now, I want to hide menu if user open that site in mobile browser (iOS and Android).
Then how i can verify in HTML or jQuery so i can hide menu. I tried to find but not get any proper solution.
Let me know if any one have.
Thanks
with CSS you can use #media-queries like the following:
#media screen and (max-width: 1199px) {
.your-navigation{
display:none;
}
}
or you use jQuery like the following:
if($(window).width()<=1199){
$(".your-navigation").hide();
}
but i would go with media queries, because its a more elegant and more easy to change way!
so actually you are not checking if its a mobile browser or desktop, but its totally okay, to check the width of the browser... i think, thats more what you want...
** edit **
after some thoughts i just wanna say, that it is possible to get the current browser by using javascript, but i wouldn't recommend that to you, because its not rubust and you will have a lot of pain with getting all browsers and so on... as i already said, go with the width! :)
(here is a link with an approach)
** edit 2 **
regarding your comment:
check this link out, it should be exactly what you want
here the code, thanks to feeela
/**
* Determine the mobile operating system.
* This function either returns 'iOS', 'Android' or 'unknown'
*
* #returns {String}
*/
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
{
return 'iOS';
}
else if( userAgent.match( /Android/i ) )
{
return 'Android';
}
else
{
return 'unknown';
}
}

Categories