I created a CSS menu, to use on a PHP site, but now I realised that for example:
From the Home tab (URL localhost/site), all the item links are correct if you hover over them, but now i navigate to "Stock" for example, who's URL is localhost/site/stock... it opens correctly. So from Stock i want to navigate to Sales (localhost/site/sales), the URL of sales become localhost/site/stock/sales and not just localhost/site/sales.
I added this menu only recently, the previous one was working fine, so for a test, i replaced the css menu with the previous one, but to no avail. the problem still persist, so I assume that something else must have changed the behaviour of the links...
I can probably fix this by added " ../ " in front of the menu's URL, but on the other hand. not all items are just one step back.
Your help would be greatly appreciated.
Try using absolute URLs.
When your link is on a page located at localhost/site/stock:
Link <!-- goes to localhost/site/stock/sales -->
But if you prepend a forward slash, the destination will be absolute, relative to your document root:
Link <!-- goes to localhost/site/sales -->
Assuming of course that your document root is localhost/site
More likely your links will have to look something like:
Link
You're correct in saying you need to add slashes. My suggestion would be to provide absolute links from / to your page:
/site
/site/sales
/site/sales/sale24
/site/stock
/site/stock/secondstockpage
/site/stock/thirdpage
I have changed the menu as you suggested, but now, it works as follow:
if i for example set my menu link to direct to: /site/sales/sold.php
so the menu.php file link would look like this:
<li>Sales</li>
<ul>
<li>Sold Items</li>
</ul>
it would sometime direct to /site/sales/sold.php and the next moment, it repeats the menu's directory like: /site/sales/sales/sold.php
so i removed the sales directory, as its directing there by itself, worked for a little while and now it directs to /site/sold.php which does not exist so it ends up with a 404.
should i specify a siteroute somewhere else?
this is very weird to me. first time i encounter something like this!
Hope my examples make sense!
Related
I have an issue with wordpress' permalink. So, there is a blog, there is a note/notes. when i click the link (with href=php the_permalink()) note is not shown but main page loads (not blog's page).
How can i fix it?
http://www.xn--d1aa4fb.xn--p1ai/blog/
I have another version of this site and it works properly:
http://dyadya.o98110rn.bget.ru/blog/
The problem is with the CSS path in the inner pages.
You do not use the complete URL to call assets, like this:
http://......com/assets/css/your.css
You use the folder navigation, like this:
./assets/css/your.css
In your inner pages, the css file will not be found.
To solve this, add this tag inside your <head></head>
<base href="https://yoursite.com/"/>
With this, in yout inner pages, the pathi will not use the pages URL, will use the BASE HREF to look for the assets.
I hope it helps!
I've created a page with an article. On top of that there's a title. If people try to click this title I want them to be redirected to the same page.
Like this: https://gyazo.com/74350b4fe91c670c4101449ee1c928a4 If I click on the article it just refreshes the page.
I can't do this manually for every article because I'm using a script.
The code I've written looks like this:
echo ' <h1 class="entry-title">'.$row['postTitle'].'</h1>';
As you can see I wrote
<a href="/">
and that's will not redirect me / refresh the page i'm viewing.
This is how it looks for me: https://gyazo.com/8a15ae274d8a7240b07100395460568d
as you can see it does not redirect me to the same page when i click the title.
How can I do this?
To make your custom PHP blog post template be able to display a title link that points back to the page, one way is to make use of your $row[.... variable.
Provided that,
your URLS will look like your screenshots, such as http://localhost/viewpost.php?id=8 when running locally and for example http://www.yourwebsite.com/viewpost.php?id=8 when online
you know how to refer to the post's id that is used in the ...viewpost.php?id=8, for example $row['postID']
you don't yet have any variable or means to refer to your current domain http://localhost when local or http://www.yourwebsite.com when online
Then, I recommend a two-part approach:
Somewhere at the top of your code, or perhaps in an include you might use for such code-reuse purposes, define for example $host:
$host='http://' . $_SERVER['SERVER_NAME'];
Then, for your actual title link::
echo ' <h1 class="entry-title">' . $row['postTitle'] . '</h1>';
Explanation
Separated HTML from the concatenation dots . with spaces, to be easier to read, as well as to support any helper programs such as fmt that you might use for wrapping long lines, so they have spaces to use for wrapping lines.
Uses PHP's predefined $_SERVER variable's SERVER_NAME , which, combined with the http://, the $host will be http://localhost when local and http://www.yourwebsite.com when online.
Define $host as a variable once at the top of the page, because it is clearer that way and likely you will have a use for it elsewhere on the page, so this helps avoid having to repeat yourself writing 'http://'.$_SERVER['SERVER_NAME'] everywhere else you may need to start forming the absolute URL
$host is then combined with the pattern for the rest of the URL, to assemble the absolute URL
Absolute URL is helpful so that if a user saves your article to their computer, then later clicks the title link on their locally saved article, the user can still correctly reach the original online page
As the article author, setting a link this way also means it can serve as a permalink, which helps with search engine optimization (SEO)
Please use # in href attribute! that will redirect you on the same page.
Problem solved. I used
echo '<h1>'.$row['postTitle'].'</h1>';
Thank you everyone.
I'm looking to dynamically change the navigation of a static html site. I'd like to detect which page I'm on and adjusts the navigation accordingly, since certain pages are in folders and causing the navigation to break when linking back to previous pages. If I need to rebuild my navigation I'm okay with that. Just not sure how to deal with navigating nested folders in php.
I have a site with a navigation structure like so
index.php
sample-page.php
Resources(folder) > resource-1.php, resource-2.php, resource-3.php
Contact(folder) > contact-1.php, contact-2.php
I can go from index.php to Resources/resources-1.php fine but if I click resources-2.php I go to Resources/Resources/resources-1.php.
The same thing happens if I'm on Resources/resources-1.php to index.php I go to Resources/index.php instead of the root.
Not sure how to change this. I've broken up the nav so it's
being inserted by <?php include ("navigation.php"); ?>
<?php set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); ?>
Thank you!
p.s. Sorry for the poor formatting, long time lurker and first time poster. Haven't quite figured out it out just yet.
Be sure to include a forward slash to avoid the unwanted relative paths. Assuming / is your base:
Index
Sample Page
Resources 1
Resources 2
Resources 3
Contact 1
Contact 2
Give that a go, I hope it helps!
I have written my own blog let’s say at example.com.
I’ m trying to use footnotes for my posts.
So I have a post at the address:
http://www.example.com/blog/2012/04/post-slug
I use this code for the footnotes (produced by markdown-extra):
<p>That's some text with a footnote.<sup id="fnref:1">1</sup></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
<p>And that's the footnote. ↩</p>
</li>
</ol>
</div>
This code is saved in the database as the post’s body.
The problem is that when I point to the browser to the post and click the links they point to the home page of my site like this:
http://www.example.com/#fnref:1
and
http://www.example.com/#fn:1
Instead of the correct:
http://www.example.com/blog/2012/04/post-slug#fnref:1
And
http://www.example.com/blog/2012/04/post-slug#fn:1
respectively.
That is they don’t take in mind the part of the URL
/blog/2012/04/post-slug
They "think" they are in the home page for some reason.
In Codeigniter I have chosen not to include index.php in the URL. And of course I have some routing definition in the routes.php file.
I cant’ figure out why this problem occurs. Maybe it has to do with routing.
I have tried all the available options in the config.php file:
$config['uri_protocol'] = 'AUTO';
(PATH_INFO etc) but didn’t help.
Can anyone help?
Thanks in advance.
CI always behaves as it's in the root this because that's where its index.php file is located and all the controllers/methods are called from there.
To solve your case, I'd suggest you add a path to your href attribute, or use base, like Zenbait said.
I'm having problems with the paths to my first wordpress theme. Post images and stuff not related to css is located in wordpress_folder/blog-images/ and in index.php when I link to images I use this path: blog-images/img.jpg
The problem is now that when I want to link to the same image from another file (not index.php) in this case single.php wich displays one blog post, the correct path is now ../../../blog-images/img.jpg
This is causing problems in the includes like sidebar etc. sidebar.php works fine when called from index.php but the images path is changed if sidebar.php is called from single.php.
Does anyone know what's going on?
If you are creating these links from within php scripts, I would suggest using the site_url() function to get the URL for your wordpress install and then appending your images path to the end of that. If you are editing static theme files like css, then you should use /wordpress_folder/blog_images/img.jpg.
Something like <img src="<?php echo site_url() ?>/blog_images/img.jpg" /> should be sufficient from theme files.
The reason that paths are chaning is because if you are in wordpress_folder then the path blog_images/img.jpg resolves to wordpress_folder/blog_images/img.jpg but if you are on a post that has the url yoursite.com/wordpress_folder/2011/09/category/my_great_post then the path would resolve to wordpress_folder/2011/09/category/blog_images/img.jpg which is obviously incorrect.
For this reason you should try to use the absolute path or full URL so that no matter what file/folder/url you are linking from, the path will always be correct.
The main downside you may run into is that if you were to change the name of your wordpress folder, or remove it altogether, then you may need to make a lot of edits to reflect that. But in any case, you should put the / in front of your path so that it can be referenced the same from everywhere.
Also check out the site_url() reference page, it lists some other helpful functions at the bottom that may be useful to you.
I thought this was a little unclear from drew's answer, so I am adding a little bit more in a separate answer. His advice is sound and I agree with him.
If you prepend a url with a / then it will navigate based on your site url. Without the slash it uses relative navigation.
So here are some examples for www.mydomain.com
//always shows the image located at http://www.mydomain.com/myfolder/pic.png
//no matter what the url is
<img src="/myfolder/pic.png" />
//shows the image located relative to the current path
//if current url is http://www.mydomain.com/posts/ then the image will come from
//http://www.mydomain.com/posts/myfolder/pic.png
<img src="myfolder/pic.png" />
If you are creating links dynamically from php side then you will want to use site_url().
If you are creating links to your theme directory folder then you will want to use bloginfo('template_directory')