Php Include not working correctly [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Right basically, I have a php include statement in my html document. The include is working as such, it is pulling in the file and displaying it. The include file is basically my navbar, with links. What is happening is that all the other content within the index file is being turned into a hyper link, all pointing to the last item within the ul/li.
Here is my include statement:
php include ("/var/www/elements/navbar.html"); ?>
Here is my navbar.html file:
<ul>
<li><a href="http://www.upndown.co/home">Home</li>
<li><a href="http://www.upndown.co/about">About</li>
<li><a href="http://www.upndown.co/blog">Blog</li>
<li><a href="http://www.upndown.co/hardware">Hardware</li>
<li><a href="http://www.upndown.co/contact">Contact</li>
</ul>

You are missing closing tags on your links
add </a>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Hardware</li>
<li>Contact</li>
</ul>

Related

Set active link on page using includes

I have written some code that will highlight a link in the header based on: class="active". The class is connected to some CSS code to style it.
I am currently adding the class="active" the specified link for each page. However, since I want to move my header into it's own file and include it on each page, I will lose the ability to set the class for each page. I could of course add a variable that will allow me to sort of do the same thing.
What I wish to know is if there is a better and secure way to automatically set the class="active" to the page that I am on. I have seen some posts that suggest using: ($_SERVER['PHP_SELF'] but I have read that it could cause some security issues.
Lastly the main problem that I have is that I need to set two links to
class="active" if I am viewing a page that is in the portfolio list item. For instance, if games.html is currently viewed, both the games and the portfolio page should have the code: class="active".
(All of my .html files are read as .php)
Here is the html code I have so far:
<ul>
<li>Home</li>
<li><a class="active" href="portfolio.html">Portfolio</a>
<ul>
<li><a class="active" href="games.html">Games</a></li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>
Any help will be appreciated!
PHP_SELF is safe when you only use it to compare values and don't directly use it in your html:
The portfolio menu can be made active by nested all related pages in a folder called portfolio and checking if the path starts with that folder.
<?php
$currentPage = $_SERVER['PHP_SELF'];
$portfolioFolder = 'portfolio/';
$isPortfolioFolder = substr($currentPage, 0, strlen($portfolioFolder)) == $portfolioFolder);
?>
<ul>
<li>Home</li>
<li><a class="<?= $isPortfolioPage ? 'active' : '' ?>" href="portfolio.html">Portfolio</a>
<ul>
<li>Games</li>
<li>2D Art</li>
<li>3D Models</li>
<li>Particles</li>
<li>Shaders</li>
<li>Environments</li>
<li>Programming</li>
<li>Substance Designer</li>
<li>Music</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>Store</li>
</ul>

Mystery Markup Generated on Wordpress Footer

I'm having a strange problem with a Wordpress site I built recently, wherein when users visit one of the website's pages via search engine (typically Google), a bit of strange markup is generated inside the footer element. That markup is an unordered list of dates linking to non-existent archive pages, and an unordered list of categories linking to non-existent category pages.
The strange thing here is that there is no code in the theme that would generate this markup, and even more peculiarly, the categories in the unordered list don't exist in the site's database. My first thought was that this could be the result of a possible malware infection, but since the links don't direct the user offsite, that seems unlikely. It would also be strange for the malware to generate problems only when the site is accessed via search engine.
I've been scouring the Internet looking for an example of this occurring, but have yet to find anything, and though I've been working in WP dev for over a year now, this is my first time encountering such a problem. So, my question is this: have any of you encountered something like this before, and if so, do you have any ideas on what could be the problem source, and/or do you have recommendations about how to go about debugging the issue?
NOTE: I have already hidden the markup using CSS for a user-facing solution, so I'm looking for an answer to help me address the problem more sustainably; i.e., finding a way to eliminate the markup in question.
Thanks!!
<ul>
<li><a href='http:/2015/10/'>October 2015</a></li>
<li><a href='http:/2015/09/'>September 2015</a></li>
<li><a href='http:/2015/07/'>July 2015</a></li>
<li><a href='http:/2015/06/'>June 2015</a></li>
</ul>
<ul>
<li class="categories">Categories<ul>
<li class="cat-item cat-item-14"><a href="/category/articlesorder/" >articles,order</a>
</li>
<li class="cat-item cat-item-13"><a href="/category/articlesus/" >articles,us</a>
</li>
<li class="cat-item cat-item-11"><a href="/category/businesswriting/" >business,writing</a>
</li>
<li class="cat-item cat-item-16"><a href="/category/englishorder/" >english,order</a>
</li>
<li class="cat-item cat-item-17"><a href="/category/serviceterm/" >service,term</a>
</li>
<li class="cat-item cat-item-12"><a href="/category/shoolbuy/" >shool,buy</a>
</li>
<li class="cat-item cat-item-18"><a href="/category/studybusiness/" >study,business</a>
</li>
<li class="cat-item cat-item-15"><a href="/category/studypapers/" >study,papers</a>
</li>
</ul></li>
</ul>
Try to change the theme and see if it is the source of this and then disable every plugin and enable one after one to see which of them generates the code.
If this just happens when someones comes from a search engine it is called cloaking.
Please check also the code in your .htaccess and all core files.
You can use Wordfence to scan the files for changes https://de.wordpress.org/plugins/wordfence/

How can I replace html elements with php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a website in which I use just html, but I'd like to add one location where I would edit things like the nav and the footer. Then it would be instantly updated across the whole site.
So, for example, I'd like to put:
<nav>
<div class="nav-wrapper">
Logo
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>Sass</li>
<li>Components</li>
<li>JavaScript</li>
</ul>
</div>
</nav>
Into
<?php echo $nav;?>
Any help would be greatly appreciated! =)
Add the html that you want to show into a file. For eg:
add this to menu.html
<nav>
<div class="nav-wrapper">
Logo
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>Sass</li>
<li>Components</li>
<li>JavaScript</li>
</ul>
</div>
</nav>
Now include this page in other HTML pages wherever you want to call it like below
<?php
include 'menu.html';
?>
I like Lal's answer. I would change include 'menu.html'; with include_once 'menu.php'; The idea is that you will can add some php variables if you need them on some point.....

PHP text outside of li [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am building a wordpress theme and for some reason my list of pages are showing outside the li when I view the source
<ul class="tabs">
<?php
while ( $queryObject->have_posts()) : $queryObject->the_post();
echo sprintf('<li>%s</li>', the_title());
endwhile;
?>
</ul>
And when I review the source in the inspector in chrome
<ul class="tabs">
Deans’ Corner<li></li>
Education Plan<li></li>
Counselors’ Corner<li></li>
</ul>
I got to be missing something simple
Take a look at the docs for the_title():
https://codex.wordpress.org/Function_Reference/the_title
Displays or returns the title of the current post.
[...]
$echo
(Boolean) (optional) Display the title (TRUE) or return it for use in PHP (FALSE).
Default: TRUE
the_title() takes an optional parameter $echo which decides whether it should return or echo the title of the page. Since you did not fill it and it defaults to the echo option, your code does not work.
If the_title() echoes, you won't be able to use it directly with sprintf().
Therefore, you can do just use HTML...
<li><?= the_title(); ?></li>
The below example is unnecessary because of the_title()'s optional parameters as pointed out in Timosta's answer.
Or you can use output buffering if you need to use the_title() as a function argument:
ob_start()
the_title();
$title = ob_get_clean();
echo sprintf('<li>%s</li>', $title);
The problem is that by default the_title() echos the title instead of returning it. You can actually specify what to echo before and after the title so there is no need for using sprintf().
This should work:
<ul class="tabs">
<?php
while ( $queryObject->have_posts()) : $queryObject->the_post();
the_title('<li>', '</li>');
endwhile;
?>
</ul>
Check the WordPress Codex:
http://codex.wordpress.org/Function_Reference/the_title

Adding class="active" to parent when child is the current item selected [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is what's happening in my boostrap menu. When I click any item in the dropdown the child is selected (class="active") but the parent is not. So, if the dropdown is closed you can't see in the menu the selected page.
<ul class="nav navbar-nav navbar-right">
<li class="my-class">Home</li>
<ul role="menu" class=" dropdown-menu">
<li class="active">Brokerage</li>
<li class="my-other-class">Consulting</li>
</ul>
</li>
<li class="my-class">Contact Us</li>
</ul>
I'm trying to do it with this but it's not working:
$('li').click(function() {
$(this).parents().addClass('.active');
});
Any help? Thanks.
You shouldn't put the . in the class name you pass to addClass. Also, parents() selects all its ancestors. If you just want the direct parent, use parent() (without 's').
$(this).parent().addClass('active');
You have some mistakes in your jQuery:
$('li').click(function() {
$(this).parent().addClass('active');
});
1.) It is parent() in your case, not parents().
2.) addClass('active')is correct, not addClass('.active').
Bootply Example

Categories