• 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?

Viewing 15 replies - 1 through 15 (of 39 total)
  • 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.

    Thread Starter emaarkhan

    (@emaarkhan)

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

    Yes – use the kind of approach I outlined above.

    Thread Starter emaarkhan

    (@emaarkhan)

    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?

    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>

    Thread Starter emaarkhan

    (@emaarkhan)

    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?

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

    Thread Starter emaarkhan

    (@emaarkhan)

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

    Thread Starter emaarkhan

    (@emaarkhan)

    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

    Do you understand the anatomy of the Loop?

    Thread Starter emaarkhan

    (@emaarkhan)

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

    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.

    Thread Starter emaarkhan

    (@emaarkhan)

    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.

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

    Thread Starter emaarkhan

    (@emaarkhan)

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

Viewing 15 replies - 1 through 15 (of 39 total)
  • The topic ‘linking urls without domain full address’ is closed to new replies.