Image source path changing on different pages - php

I'm using Genesis and I have a functions.php that I have inserted images there using hooks to the footer.
I've used a widget to insert an image to the header.
The images are displayed correctly when viewed in the homepage, but when I switch a page, the images are not displayed.
Further investigation concludes that wordpress is seeking the file with a wrong path source.
That's the path source in the homepage - wp-content\themes\childTheme-Almog\images\linkedin.png
And wordpress is looking for it as it should.
However, on another page, called 'X', wordpress is looking for the same image as follows:
\wordpress\x\wp-content\themes\childTheme-Almog\images\linkedin.png
As you can tell, it adds to the path the page name as a folder, which it shouldn't do, because the image is not there.
Is there a way to make wordpress look for the image like it does on the homepage?
Here's how my images are implemented in my functions.php:
<div class="d_footer">
<ul id="list_left">
<li class="foot" id="ft_text1"><img src="wp-content\themes\childTheme-Almog\images\phone.png" alt="phone">
<span style="color: #969697">|</span><span style="margin-left:30px;"></span><img src="wp-content\themes\childTheme-Almog\images\envelope.png" alt="envelope"></li>
<li class="foot" id="ft_text2"></li>
</ul>
<ul class="foot" id="list_right">
<li id="ft_text3"><img src="\wp-content\themes\childTheme-Almog\images\linkedin.png" alt="linkedin" align="left">Almog's linkedin profile</li>
<li id="ft_text4"></li>
</ul>
</div>

You really should be using Wordpress' get_stylesheet_directory_uri variable to alleviate problems with paths like this.

Related

Adjusting link paths in a Navbar PHP file for subdirectories

I'm trying to create a portfolio website. This is my third attempt, and I've been attempting to use PHP files for the first time. In my previous websites, I would copy large swaths of HTML into each page so that they would be formatted the same. With this website, I'm instead just trying to link to a few PHP files that contain code shared by multiple pages, like the navigation bar for instance.
My issue is this. Say in my index file
mywebsite/index.php
I include this PHP file which contains HTML code for a navigation bar
<?php
echo <<<EOT
<!-- Navigation Bar -->
<div id="nav">
<a class="nav-link" id="index-link" href="">About</a>
<div class="nav-divider"></div>
<a class="nav-link" id="resume-link" href="resume">Resume</a>
<div class="nav-divider"></div>
<a class="nav-link" id="portfolio-link" href="portfolio">Portfolio</a>
<div class="nav-divider"></div>
<a class="nav-link" id="contact-link" href="contact">Contact Me</a>
</div>
EOT;
?>
However, the way the links work, if I wanted to include this same navigation bar in a sub-directory webpage
mywebsite/portfolio/index.php
All of the links would stop working.
I've tried doing absolute paths to the root, but then the webpage's url shows the absolute path as well, including things public_html in the url which looks bad.
I've tried doing paths like "mywebsite.com/..." and "mywebsite/..." but thats just shows up as "mywebsite.com/mywebsite/..." and doesn't actually work. If I try saying "public_html/..." public_html becomes included in the url.
I don't want to create a second PHP file just to have the same code with slightly different href paths. Is there a path I could use for both my main directory and subdirectories that doesn't show up weird in the url? If not, is there a way to use Javascript or Jquery to detect if a file is in a subdirectory, and add "../" to all links inside the included PHP files?
I can't seem to find an answer to this question, maybe I'm not using the right words in my searches? This feels like it would be a common issue.

Expression Engine 3 pagination with page_uri

I have looked for a while for a solution to this, but have been unsuccessful so far. Not sure if it's me, or if there's a problem with the pagination functionality.
What I'm trying to do
When on a page within a certain channel, I want to have 'prev' and 'next' buttons to click through to the next article in the channel. These links must use the page_uri set for each page.
What I've tried
I have a channel full of pages. In the template, I have added:
{exp:channel:entries channel="project" dynamic="no" orderby="date" sort="desc" limit="1" paginate="bottom"}
<div class="container-fluid project-section pagination-bar">
<div class="container">
<div class="col-md-12">
{paginate}
{pagination_links}
<ul>
{previous_page}
<li>Previous Page</li>
{/previous_page}
{next_page}
<li>Next Page</li>
{/next_page}
</ul>
{/pagination_links}
{/paginate}
</div>
</div>
</div>
{/exp:channel:entries}
This is adding the links to the bottom of the page, but when clicking on them the URLs are just loading the same URL you're currently on, then adding /P1 to the end.
I need it to use the page_uri added in the CMS so that it clicks through properly and doesn't affect SEO on the site.
Any help appreciated on this one, thanks
Pagination isn't really the way around this. You should look into Next/Previous Entry Linking. It'll give you a full link to the previous and next entry. Just make sure to keep it outside your channel entries loop.
For example you'd want something like:
{exp:channel:prev_entry channel="project"}
View previous project
{/exp:channel:prev_entry}
{exp:channel:next_entry channel="project"}
View next project
{/exp:channel:next_entry}
Assuming your projects all live in a section called projects you'd be linking between
/projects/example-project-1
/projects/example-project-2
/projects/example-project-3

The Wordpress way URL on static / dynamic pages

I would like to add a menu or footer like in Wordpress or any other CMS.
That really dont work with PHP includes because if a website file is in subdirectory there is a problem with the path.
As you know a normal static menu looks like
<nav>
<ul>
<li>About</li>
</ul>
</nav>
but CMS menu looks like
<nav>
<ul>
<li>About</li>
</ul>
</nav>
And that on all pages so no problems with the path
if you try it with static/dynamic pages you have to add the path or the url and that looks really ugly or not
<?php
define('WEB_ROOT', '../'); // relative path to /
?>
...
<nav>
<ul>
<li>Solution</li>
or
<li>Solution</li>
or
<li>Solution</li>
</ul>
</nav>
I think thats a bad idea and really ugly.
so how to solve that kind of problem maybe with adding a web root in php like above but looks not really good so do you have any other ideas?
And that Solution should also work for CSS and JS not only for static contents, so all styles are same and menus looks just like the other pages even if it is in the subdirectories
Generally in Wordpress I use the site url to generate full urls:
site_url('/about');
As for JS/CSS files, it depends where you are putting them. If the files are located in a specific theme use:
get_template_directory();
you can use it...in "a" tag href="", use this:
echo home_url('index.php/about');
or remove the index.php, just about [the name of the page.]
Done.

HTML - href adds a # to current URL

I'm creating a "web store". I've created a navbar using Bootstrap. I have 3 php files: index, category and article, all .php
<li class="dropdown">
Categories<span class="caret"/>
<ul class="dropdown-menu">
<li>Compu</li>
<li><a href="categorias.php?categoria=Mascotas" >Animals & Pets</a></li>
<li>Office</li>
<li>Music & Movies</li>
</ul>
</li>
The "Category" link works only as a dropdown, you click it and it shows the submenu.
Categorías<span class="caret"/>
This code is in all 3 files, but it only works on index and category. When I click it on the article.php file it only adds a "#" to the current URL.
localhost/store/article.php?id=1 -> localhost/store/article.php?id=1#
I'm using the id to show the selected article's info from a database. I use it too on the category.php file but the dropdown link works there. Everything else works fine, except that link.
Am I missing something?
PS. I'm only using HTML and PHP in my files.
Sounds like you forgot to import the necessary bootstrap dependents on the article page.
Necessary Dependents
CSS
bootstrap.min.css , or theme if you are using
JavaScript files
jQuery
bootstrap.min.js
Sounds like a JS issue.

modify wordpress wp_nav_menu url

How could I change the code generated by wp_nav_menu?
Right now it generates:
<ul class="rounded ">
<li class="arrow">Menus</li>
</ul>
I'd like it to look like this:
<ul class="rounded ">
<li class="arrow">Menus</li>
</ul>
i found this link, but could not get it working properly.
http://wordpress.org/support/topic/how-do-i-modify-wp_nav_menu-link-hrefs?replies=2
The link from support forum doesn't talk about the version number of the wordpress that he is using. I am currently on 3.2.1, it is having the menu options under Appearance section. You can check out this awesome post on menus. It gives you an option of modifying the href as well.
I hope you are on version > 3. If not possible to update then it has to be done using wp functions.

Categories