How to properly embed a html conditional code in php - php

I have a situation and I am struggling to embed 2 conditional html code sequences inside of a PHP file. I was thinking, of using include PHP function to call two separate external html files (section1.html and section2.html) in header.php like this:
<!-- Start Header -->
...
<?php
/* a conditional PHP code is required in order to load
the section1.html if the menu1** is shown on the page (?)*/
include('section1.html');
/* also here, a conditional PHP code is required in order
to load the section2.html if the menu2** is shown on the
page (?)*/
include('section2.html');
?>
...
<!-- End Header -->
Another approach using in between PHP tags:
<!-- Start Header -->
...
<?php if(condition){ ?>
<!-- HTML code of section1 here -->
/* above, a PHP (condition) that could load section1 if
the menu1** is shown on the page, should be defined (?) */
<?php } ?>
<?php if(condition){ ?>
<!-- HTML code of section2 here -->
/* above a PHP (condition) that could load section2 if
the menu2** is shown on the page, should be defined (?) */
<?php } ?>
...
<!-- End Header -->
If this helps, I can expose the html code sections, but I think that at this point it's not so important.
**the conditional PHP code should be related to the above mentioned menu1 and menu2 made in wordpress/appearance/menus section.
LE:
HTML sections are,
section1:
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Portfolio
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
About
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
</div>
</nav>
and section2:
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Fiva
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
Caterham
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Mobile
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
</div>
</nav>
Any thoughts? Thank you,

Based on the menu1 and menu2 page links you included in your most recent comment, it looks like menu1 corresponds to your leaf pages and menu2 is your front page. If that's your intention then you could use the following conditional PHP.
<?php if (is_front_page()) : ?>
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Portfolio
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
About
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
</div>
</nav>
<?php else : ?>
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Fiva
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
Caterham
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Mobile
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
</div>
</nav>
<?php endif; ?>
If you want to include the code using external files you'd have to save them as .php files instead of .html. You can use the exact same code in those .php files, but it's important to use the .php extension when you save them. Here is what the files would look like:
menu1.php
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Fiva
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
Caterham
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Mobile
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
</div>
</nav>
menu2.php
<nav>
<ul>
...
</ul>
<div id='menuRight'>
<div>
Home
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
<div>
Portfolio
<img src='http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg'>
</img>
</div>
<div>
About
<img src='http://images5.fanpop.com/image/photos/31100000/random-space-space-31155586-598-398.jpg'>
</img>
</div>
</div>
</nav>
Then in your header.php file use this code:
<?php if (is_front_page()) : ?>
<?php include 'menu2.php'; ?>
<?php else : ?>
<?php include 'menu1.php'; ?>
<?php endif; ?>
It's important to make sure that the path to the menu1.php and menu2.php files are correct. My code above assumes that those two files are in the same directory as your header.php file.

Related

Inheriting files in specific div through php files

I've created a file called menu.php to be my universal nav/menu file. The way it was created using bootstrap though, I have a div called article at the bottom which serves as the main body of the app, since the sidebar in my menu is expandable/responsive.
I really want to have one global menu file. I'm currently including it in all of my content pages like so:
<?php include("menu.php")?>
This works but it breaks my formatting. What I'm trying to do is make all of my main pages such as index.php have the html formatted so that it will always sit inside the tag in my code below which shows card classes.
<header>
<div class="branding">
<div class="menu-button menu-toggle nav">
<i class="material-icons">menu</i>
</div>
<img src="" />
</div>
<div class="page-details">
</div>
<div class="settings">
<div class="menu-button profile">
<i class="far fa-user-circle fa-2x"></i>
</div>
<div class="menu-button menu-toggle aside">
<i class="material-icons">chat</i>
</div>
</div>
</header>
<div class="app">
<nav>
<div class="title-block">
<img src="" />
</div>
<ul>
<li><a href="#"><i class="material-icons">home</i>
<span>Home</span></a></li>
</ul>
</nav>
<!--This following article section is the main body of the page, that I want each additional page to take up-->
<article>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</article>
</div>
Example:
Menu.php is my global menu/nav file but it makes the page/app act as a wrapper for all the other pages (index.php, editor.php, etc.)
menu.php
<div class="app">
<nav>
Nav menu content
</nav>
<article>
This will be the main page article for index.php, editor.php,etc.
</article>
</div>
example with index.php (the start and end are just hypothetical to show the endpoints)
<body>
<?php include("menu.php");?>
<?php start('article') ?>
<!--Everything from here to the end() call would be inserted in the article tags on menu.php-->
<div class="app">
<div id="content">
<div>
<h1 style="text-align: center; color: #A9BD50; ">Content Management Editor</h1>
</div>
<form method="post">
<textarea id="mytextarea"></textarea>
</form>
<div>
<h1 style="text-align: center; color: #A9BD50; ">Preview</h1>
</div>
</div>
</div>
<?php end() ?>
</body>

copy content from other website to your based on div

<html>
<div class="product-tile ">
<div class="product-image">
<img src="1.jpg">
<img src="2.jpg">
</div>
<div class="brand">
<a href="example1.html" class="brand-link">
Example1
</a>
</div>
<div class="product-name">
Craquelé-Effect Leather Square-Toe Mules
</div>
</div>
<div class="product-tile ">
<div class="product-image">
<img src="11.jpg">
<img src="12.jpg">
</div>
<div class="brand">
<a href="example2.html" class="brand-link">
Example2
</a>
</div>
<div class="product-name">
Craquelé-Effect
</div>
</div>
</html>
My content is like this in HTML and want to copy it on my website.
My code is like how to get the title, images, brand and there price. I've used file_get_html in it but I'm getting issue in fetching the datalike brand and price.
require('simple_html_dom.php');
$html = file_get_html('new_arrival.html');
//$product = [];
foreach ($html->find('div.wrap-desc') as $pro) {
$proDetails = $pro->find('div.brand');
}
If you are using jQuery you can get the contents of a DOM element using .html():
$('html').html()
Alternatively in vanillaJS:
let x = document.getElementByTagName('html')
console.log(x.innerHTML)
https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML

Where can I find the file PHP is fetching text/table from?

I recently inherited a website with a horrible file structure. I need to update some content (text) but I can’t find where it is being defined. The database table does not have the information, so I'm guessing the text is being defined elsewhere. Is there a tool or "trick" in Chrome Dev Tools to find the content source? Your help is much appreciated!
***Snippet from PHP File:
<div id="product_wrapper" class="add-bottom30">
<div class="columns sixteen">
<div class="columns twelve add-bottom60 catalogue">
<!-- Pager -->
<?php include('sql-' . $_SESSION['lang'] . '/promos.php');?>
</div>
<div class="columns four side">
<h5 style="margin-bottom:25px;">FLYERS</h5>
<ul>
<li style="background-color:#0065a4;">
<?php echo flyer_jet_2016; (where the text I need to change lives) ?>
</li>
</ul>
</div>
<div class="clear"><!-- ClearFix --></div>
</div>
</div>
*** Snippet from source code ("View Source" in Chrome):
<div class="columns four side">
<h5 style="margin-bottom:25px;">FLYERS</h5>
<ul>
<li style="background-color:#0065a4;">
<span class="icon" data-icon="(" style="color:#fff;margin-bottom:15px;"></span><br>Tool Storage<br>Solutions 2016
</li>
</ul>
</div>
<div class="clear"><!-- ClearFix --></div>
</div>

Convert static navigation bar to dynamic

From the research I have done, I think it has to do something with the include() function linking to the nav.php file. What I am trying to accomplish is taking an older huge site with every element being static ones and converting it to have dynamic elements so that the updating is faster. The first step was the nav bar and I can't seem to get it to work.
The route to the nav bar is inputs/nav.php, and I'm trying to use include() to put the nav in:
<?php include("inputs/nav.php"); ?>
It works for the files at the same level as the inputs folder, but if a page is at any other level of files, it does not. Anyone got any ideas of what is going on and how to fix?
Thanks in advance!
<header>
<div id="mastHead">
<div id="fss_logo">
<a href="index.html">
<img src="images_folder/logos/35fss_logo4.png" alt="35 FSS" />
</a>
</div>
<!--End FSS logo-->
<div id="facility_title">
<div id="rotating-item-wrapper_main">
<a href="facebook_links.html" onClick="return popup(this, 'facebook')">
<img id="facebook_logo6" src="images_folder/logos/facebook_circle2.png" alt="Facebook Logo" class="rotating-item" />
</a>
<a href="http://ice.disa.mil/index.cfm?fa=site&site_id=7&dep=DoD" target="_blank">
<img id="ice_logo2" src="images_folder/logos/ice.png" alt="ICE Logo" class="rotating-item" />
</a>
</div>
<!-- END: Rotating images images -->
</div>
<!--End facility_title-->
</div>
<!--End Mast Head-->
<!--------------------------- NAV INCLUDE ----------------------------->
<?php include( "inputs/nav.php"); ?>
<!--------------------------- NAV INCLUDE ----------------------------->
<!-- /nav-wrap -->
</div>
</header>

Decoding base64 string?

I can't seem to decode this base64 string which is in the footer of a wordpress theme. I want to be able to add more to the footer.
Any help appreciated, thanks!
<?php eval(stripslashes(gzinflate(base64_decode("pVNRa9swEH7OYP/h1kG7PbiGwfaQuM7D1tCwsY42UAaBINsXWyD7hKTO87/vSXUct3PZYPKLdN/5vrvvk5Yp8JrNkkL+glwJay+2J7lCYdBsT9Ik5nj6+lVIGh+e7N9EEWBTQGuE1mgginpkhFsnjIMVkRsnBFpZMOc+IEx5IHuGfBigwxplqD/AkHCvJqIBUXIYtqIa/aQCKoN7DiRLXWnAvCIo0e1IO0nNu+1ZSDx7v4BlGvMPV3xMYsESKZnCCzyhVKt3Slq306JEy4WcdAo5dNFXm+g8nmz9H0w6VpiIHQV7FDoYs7q+3lzewOebyy/rzS18W3//6v2ZMZzJMk2sM9SU6WlOulvASJxCOORpfvZT9FCmqJTNnhhpxCBYEvdlkjgUzYynt7VQamA4OlA5p+dx3Lbt+d4gugprVKKje2fPc6pZfb5OnUKvAikyc3j76aP/Fg5/u6jAnIzwrs2hoQYXnB805/wV14M7MsUPg9bCxpe2LMbzkHcWsg7W9RVZhwVMdifrKqC+q/9o6g4zKx2Cp5JN6dt5Ggn3bFDwUbbB25eN//uLHb/HQwJbREUXNpWrPRFvlw8=")))); ?>
Replace eval with print and see what it says.
The full result is:
?> <div class="clearer"></div>
</div>
</div>
<!-- end wrapper -->
<!-- start Footer -->
<div id="footer">
<div id="footer2">
<div id="fl">
<ul>
<li class="home">Home</li>
<?php wp_list_pages('title_li='); ?>
</ul>
<div class="clearer"></div>
</div>
<div id="fr">
<!-- FOOTER CREDITS LINK -->
<big><strong>© <?php echo date('Y'); ?> <?php bloginfo('name'); ?></strong></big><br>
<small><strong>WordPress Themes by ImHosted Website Hosting<strong></small>
</div>
</div>
</div>
<!-- end Footer -->
</div>
</body>
</html>
<?

Categories