SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <?php the_permalink() ?> Help Needed...

    I am essentially losing my mind.

    I'm working on a PHP website where every other PHP tag I'm using is working properly except for:

    PHP Code:
    <?php the_permalink() ?>
    I'm receiving a fatal error that this command doesn't exist, now here's the kicker, I have several other websites on the same server with the same php.ini files and it works just fine on them. So, the first thing that comes to mind is well perhaps it's conflicting with something? Not likely, my code is clean, valid and on this particular website, the code is far simpler than other websites I've done anyways.

    Now;
    PHP Code:
    <?php the_permalink() ?>
    is the best and easiest way to collect the page URL, correct? It hasn't been deprecated or anything has it?

    Thanks

  2. #2
    Non-Member DelvarWorld's Avatar
    Join Date
    Jul 2004
    Location
    Baloney
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Always search the manual before asking for other's time :P

    http://pl2.php.net/manual-lookup.php...malink&lang=en

    the_permalink is not a default PHP function and was most likely added by other code included on the page.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the_permalink() is a Wordpress function rather than a native PHP one.

    If you want the current URL, use $_SERVER["REQUEST_URI"]

  4. #4
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaaaaaaah, that makes so much sense now, thank you so much corbyboy.

  5. #5
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must be missing something because here's how I'm wrapping it:

    PHP Code:
    <?php $_SERVER["REQUEST_URI"?>
    and it isn't working, how exactly should I display the code?

    Thanks

  6. #6
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So apparently there is no easy way to accomplish dynamically displaying the current page URL using PHP, pretty astounding actually, but here is what I had to do:

    Since currently PHP doesn't have a built in function you have to define one yourself:

    PHP Code:
    <?php function currenturl(){ 
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" ""
    $protocol strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
    return 
    $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];}
    function 
    strleft($s1$s2){return substr($s10strpos($s1$s2));} ?>
    and then to actually implement the function, use this:

    PHP Code:
    <?php echo currenturl(); ?>
    There may be a much simpler way, but this is the best that I could find.

    Thanks, Bryan

  7. #7
    Non-Member DelvarWorld's Avatar
    Join Date
    Jul 2004
    Location
    Baloney
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php echo $_SERVER["REQUEST_URI"] ?>
    edit: Well, if you want the domian, you do need server_name, although sometimes it's just easy to set it as a global variable and use that.

  8. #8
    SitePoint Zealot calmestghost's Avatar
    Join Date
    Dec 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, what I was looking for is the URL, as in the entire URL no matter what it is or how long including the prefix, domain, sub-folders, page and finally the extension, not simply just the page name. Perhaps it would have made more sense if I described it as the browser URL for the current page.

    I hope the code I pasted helps someone. Thanks, Bryan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •