WordPress.org

Ready to get started?Download WordPress

Forums

linking urls without domain full address (40 posts)

  1. emaarkhan
    Member
    Posted 1 year ago #

    Hi,
    I have some hard coded links in footer. which i want to link to pages. But don't know the url on which i will upload the site.so how can i reach out to that page in anchor tag.so it opens up same page despite whatever the url is?

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Don't hardcode the links. Use something like:

    <?php $my_link =  home_url( '/' ) . get_permalink( $id );>
    <a href="<?php echo $my_link;?>"></a>

    where $id is the id of your chosen page.

  3. emaarkhan
    Member
    Posted 1 year ago #

    is there a easy way to manage footer links like policy and linking them.?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Yes - use the kind of approach I outlined above.

  5. emaarkhan
    Member
    Posted 1 year ago #

    I have a question. what if my permalink is post name instead of id? i tried this

    <?php $my_link =  home_url( '/' ) . get_permalink(51); ?>
        <?php //var_dump($my_link);exit; ?>
        <a href="<?php echo $my_link;?>">	<p>Privacy policy</p></a>

    and the url i got was
    The requested URL /abc/http://localhost:8888/abc/ was not found on this server.
    obviously there r two problems here.
    1. its appending to a wrong url
    2. it doesn't have that page id appended to the page.
    what am i missing?

    Edit : i removed the home_url('/') and it worked fine. i am right?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    what if my permalink is post name instead of id?

    Doesn't matter, That's why you're using get_permalink().

    its appending to a wrong url

    Sorry - try just <?php $my_link = get_permalink(51); ?>And your link markup is malformed. It should be:

    <p><a href="<?php echo $my_link;?>">Privacy policy</a></p>

  7. emaarkhan
    Member
    Posted 1 year ago #

    Yes. figured that out and thanks. but when i click on main nav. and if i rollover the privacy policy. it says the same link as i am on the current page.its like the url is still taking it be same as the page i m on.shld there be any reset?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    You need to add this code outside of the the Loop.

  9. emaarkhan
    Member
    Posted 1 year ago #

    its in footer.how do i know where loop ends. :/ i thought it was in index.php

  10. emaarkhan
    Member
    Posted 1 year ago #

    I have a image in home.php and i gave it link like you told.its showing and clickable but get_permalinks has the page name but it comes to index.is it coz of inside loop too? how can i break out of it in home.php and footer.php

  11. esmi
    Forum Moderator
    Posted 1 year ago #

    Do you understand the anatomy of the Loop?

  12. emaarkhan
    Member
    Posted 1 year ago #

    like loop shows u every post,pages,names,dates etc.?

  13. esmi
    Forum Moderator
    Posted 1 year ago #

    More specifically, you need to be able to recognise where the Loop starts and ends - especially in a situation like this. For example, the main Loop would not extend to the footer of the page in the vast majority of themes, so I suspect there might be a problem in your theme. Have a read of The_Loop.

  14. emaarkhan
    Member
    Posted 1 year ago #

    yes i have looked at that. My theme is a child theme and the loop is inside the loop.php, whereas i do have home.php which have my custom div and the footer has my own code.

  15. esmi
    Forum Moderator
    Posted 1 year ago #

    What's the parent theme? Do you have a custom copy of loop.php in your child theme?

  16. emaarkhan
    Member
    Posted 1 year ago #

    Twentyten. yes i have the loop.php in my child theme folder.

  17. esmi
    Forum Moderator
    Posted 1 year ago #

    Drop a copy of the file into the WordPress pastebin and post the pastebin url here.

  18. emaarkhan
    Member
    Posted 1 year ago #

    the custom loop file?

  19. esmi
    Forum Moderator
    Posted 1 year ago #

    Yes please.

  20. emaarkhan
    Member
    Posted 1 year ago #

    The wordpress pastebin always shows me page not found but here
    I don't think i have changed anything in loop.php as i m still learning but still heres the link

  21. esmi
    Forum Moderator
    Posted 1 year ago #

    That code looks fine. The Loop ends with <?php endwhile; // End the loop. Whew. ?>. What's in your child's footer.php file?

  22. emaarkhan
    Member
    Posted 1 year ago #

    here is footer

    [No bumping. If it's that urgent, consider hiring someone.]

  23. esmi
    Forum Moderator
    Posted 1 year ago #

    Paste does not exist or has expired.

  24. emaarkhan
    Member
    Posted 1 year ago #

    here
    I am having issues with a img which i wrapped around anchor and gave it permalink too. i think its all one problem.
    p.s - i know i m not good. what am i missing?

  25. esmi
    Forum Moderator
    Posted 1 year ago #

    <?php $my_link = get_permalink('neatfold-privacy-policy'); ?>

    You need to use the page/post id - not slug. And please stop bumping. These forums are manned by unpaid volunteers who help when, and as, they can.

  26. emaarkhan
    Member
    Posted 1 year ago #

    And please stop bumping. These forums are manned by unpaid volunteers who help when, and as, they can.

    sorry! :( i remember you said above i can use the name too.because the reason is that i am going to change the permalinks to post name.so if i give post/page id.it would get lost.no?

  27. esmi
    Forum Moderator
    Posted 1 year ago #

    No - I only ever said to use the page/post id.

  28. emaarkhan
    Member
    Posted 1 year ago #

    it worked! yay..but other links i give them post/page id, its not working.its on home but after get_template_part( 'loop', 'index' ); so it means its out of loop.right?

  29. esmi
    Forum Moderator
    Posted 1 year ago #

    In theory, yes.

  30. emaarkhan
    Member
    Posted 1 year ago #

    but why isn't it working :/ i only know var_dump way to debug and i did for get_permanlink(5); and came out as bool(false) meaning nothing is return.

    <?php $buy = get_permalink(5); ?>
                <?php var_dump($buy); exit;?>
                <a href="<?php  echo $buy; ?>"><img src="<?php bloginfo('stylesheet_directory') ?>/images/buy.png" /></a>

Topic Closed

This topic has been closed to new replies.

About this Topic