WordPress.org

Forums

named anchors on index.php with base href how to? (11 posts)

  1. lokjah
    Member
    Posted 10 years ago #

    i'm havin a heck of a time figuring out how to do this... I'm using a base href in the header of all my pages

    <base href="http://mysite.com/" />

    and I've got skip to nav (my nav is at the bottom) and skip to top links that look like so:

    <a href="wp/#navheadnews" tabindex="1" title="skip to navigation">skip2nav</a>

    where #navheadnews is bottom most div on the page and just above that div I have my skip to top link: (where #home is the body id)

    <a href="wp/#home" tabindex="2" title="up to top">up2top</a>

    but of course since I have these "hardcoded" once you click on a post, and then click either of the skip links it takes you to the hard coded link, and away from the post.

    the bottom "skip to top" link is also in an include file. but the top "skip to nav" link is hard coded into each index throughout the site.

  2. moshu
    Member
    Posted 10 years ago #

  3. lokjah
    Member
    Posted 10 years ago #

    wp is where my wordpress directory is, so if i take that out it resolves to the base href, which is the root index file of my .com, which is not a wp loop index.

    the difficult part is figuring out how to make the named anchors work with the base href, when viewing wp posts which are dynamic....

  4. jpettit
    Member
    Posted 10 years ago #

    maybe you could show us an example? do you want these links to move to anchors in a post page? you could perhaps use the_title tag (http://codex.wordpress.org/Template_Tags/the_title).

    php the_title('', '#home');

  5. lokjah
    Member
    Posted 10 years ago #

    the site is in dev and I cant show it right now. but what I need is in reference to the code that I have posted in the first post.

    If I click on a post then this is the URL it generates:

    http://mysite.com/wp/?p=13

    now If on that page I click the "skip2nav" link (see my code above)

    the generated URL will be:

    http://mysite.com/wp/#navheadnews

    instead of:

    http://mysite.com/wp/?p=13#navheadnews

    this is my problem......

  6. jpettit
    Member
    Posted 10 years ago #

    did you try using the_title?

    something like:
    <a href="<? php the_title('', '#home'); ?>" tabindex="2" title="up to top">up2top</a>

  7. jpettit
    Member
    Posted 10 years ago #

    actually, you can just reuse the existing code in the WP templates:

    <a href="<?php echo get_permalink() ?>#home">HOME</a>

  8. lokjah
    Member
    Posted 10 years ago #

    hmm i think you are on to something there, only I need to get to the very top of each page, which is why I was using a body id before...

    one other thing, I'll probably then have to use these as includes and include them on wp only pages as they wont work on a non wp php page will they?

    and then of course I need one for the skip to bottom as well

    Is there a php alternative to the base href that might work better for me, Ive used the base href for years and quite rely on it with my sites, but now that Im getting into more php I see it causes alot of path problems.

  9. moshu
    Member
    Posted 10 years ago #

    The other option is to drop the base url for you blog only and all that stuff with named anchors will work :)

  10. lokjah
    Member
    Posted 10 years ago #

    could i use something like this on the wordpress index.php in my theme folder?

    <?php
    /* Don't remove this line. */
    require($_SERVER['DOCUMENT_ROOT'] . '/wp/wp-blog-header.php');
    ?>

    and then would I have to get rid of the base href on that index? Im just talkin out loud here as I'm not well versed on the php side

  11. lokjah
    Member
    Posted 10 years ago #

    ok well i'm still bangin away at this, I just cant seem to break away from using the base href, there are alot of links and includes on my pages that refer to it, and if i take it out, it would be a ton of hard coding to do.. BUT Ive got some things to work yet I need some direction here if you would:

    first: as I posted above is there a way using php that I could use instead of the base href that would work on any php page (as the cool one jpettit posted is good for wp ones, but not for my non wp php pages)

    second: I did have problems with jpettits code on my skip to nav link, it wasnt picking up the post id in the link, but the up to top link was working fine, BUT I fixed the skip to nav by using this:

    <div id="skip2nav">
    <?php while (have_posts()) : the_post(); ?>
    <p><a href="<?php echo get_permalink() ?>#navhead">skip2nav</a></p>
    <?php endwhile; ?>
    </div><!-- close skip2nav -->

    now, today I was creating a paged post, and of course this code wasnt enough for it to recognize the page portion of the code:

    &page=2

    what I need the code to do is this:

    ?p=7&page=2#navhead

    what can I call that will cause wp to get the page and append it like the link above? is there like a get page link, that I could add after the get permalink?

Topic Closed

This topic has been closed to new replies.

About this Topic