Support » Fixing WordPress » two anchors in each post

  • Resolved agnesvarda

    (@agnesvarda)


    DEAR ALL,

    I’m creating a blog wich will have very long posts. At the bottom of each post i have two anchors:

    POST TOP / TOP

    1. post top (is supposed to take to the post title)
    2. top (takes me to the very top of the page)

    I was able to create the top of the page anchor. I am unable to create the “POST TOP” functionality.

    I believe I have to place a php script next to the_title (to generate an unique name/ number or id) and other script next to my link ‘post top’ to call it.

    please help!?

    thanks so much

Viewing 6 replies - 1 through 6 (of 6 total)
  • It doesn’t have to be an id that is unique to the site – just unique on that page. So if this is a single post page, you could just edit single.php and change:

    <h2><?php the_title(); ?></h2>

    to:

    <h2 id="post-top"><?php the_title(); ?></h2>

    Note: Your template markup may vary, so the above is just a generic example.

    Thread Starter agnesvarda

    (@agnesvarda)

    esmi, thanks very much for your answer.

    The problem is that it is not a single post page. So it does not matter where I am, when i click on the “POST-TOP” link it takes me to the very first post of the page, but i would like to go to the top of the current post i’ve clicked. How would I do that?

    thank you.

    In that case, try:

    <h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>

    But you’ll then need to generate the correct url in your “back to top of post” links. Where you outputting this link in the Loop?

    Thread Starter agnesvarda

    (@agnesvarda)

    thanks esmi! Now I have something like this on my index.php

    <h2 class="contentheader" id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>
    <div class="content">
    <div class="permalink"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Permanent Link</a></div>
    <?php the_content('Read more &raquo;'); ?>
    
    <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    <div id="postinfotext">
    Posted by: Admin <br />
    Date: <?php the_time('d.m.y') ?><br />
    Category: <?php the_category(', ') ?><br />
    Top:<a href="<???????????????????> POST TOP</a> / <a href="#page" class="top"> PAGE</a>

    I have added the code you gave on the first line, now I please need to place the second part on the last line (??????????????????), correct? thanks!

    Try:

    Top:<a href="#post-<?php the_ID(); ?>">POST TOP</a> / <a href="#page" class="top"> PAGE</a>

    Thread Starter agnesvarda

    (@agnesvarda)

    it did work!

    thaks so much : )

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘two anchors in each post’ is closed to new replies.