Opened 20 years ago
Closed 18 years ago
#1271 closed defect (bug) (fixed)
the_permalink() broken outside the loop
Reported by: | Skeltoac | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 1.5 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
The output of the_permalink() on a Page with a loopless template (such as my links page http://www.skeltoac.com/links/) will be something like "http://www.skeltoac.com/2004/04/21//". It should either output the correct URI or nothing at all.
Change History (6)
#3
@
20 years ago
You really should be using a loop if you want to use functions like the_permalink(), even if there is only one post.
Alternatively, you can directly pass the ID to the get_permalink() function.
#4
@
20 years ago
It didn't occur to me that I would need a loop in a Page that had no 'post' content. I ran across this bad URI output while writing a plugin; I'm sure others use Page templates without loops, too, so I have to put a workaround in my plugin code. It would just be nice if the_permalink() was more reliable, i.e. didn't spit out invalid URIs.
A simpler version, not so forgiving or assuming:
if ($post) $idpost = $post;
else return false;