Support » Fixing WordPress » Excerpts links to full blog page with the name attribute

  • Resolved Etabeeta


    Hello. First of all I apologize for the perhaps nondescriptive title, but I don’t really know how to frase myself (making googling for an answer hard). I will try to explain.

    What I am trying to do is create a website where a few excerpts from the latest blog posts are displayed in the sidebar, with a ”Read more” link.

    When you press the link you will be taken not to that particular posts single page, where it is displayed in full, alone, but rather to a page where all posts are displayed, scrolled down to the particular position using the link name attribute (horrible name for googling).

    I’m talking about <a name="bookmark" to create a bookmark, and then using websiteurl#bookmark to make the window scroll to the correct position.

    So basically what I want to do is first of all make all the posts when displayed on the blog page have a name attribute, and second to make the Read more-link link to that, and not to the post itself.

    I’m at a loss at how to approach this, I have decent knowledge of CSS, PHP and HTML but the inner workings of the wordpress code is beyond me.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator bcworkz


    There’s probably an easier way, but you could always directly query the database for the last, say 5, posts and display whatever portion of the content you want in the sidebar.

    The main thing I wish to convey is that every post on an index page has an <article> tag with an id="post-#" attribute to which you can target your skip links in the sidebar. (# = actual post number).

    For example, if you were to display the excerpt of post 238 in the sidebar, the read more link would be something like:
    <a href="">read more...</a>
    You don’t need to anchor skip link destinations any more with <a name="bookmark">, in fact, it is frowned upon. You can skip link to the id or name of any html tag.

    I’m sorry but I can’t find what your talking about. I see no article tags and when I try testing I can’t get it to work.

    This is the url for my blog page:
    (using MAMP)

    and in the source each blog post has this form:

    <h2><a href="http://localhost:8888/theme/?p=1" title="Permalink to Hello world!" rel="bookmark">Hello world!</a></h2>
    <h3>Publicerat 5 mars, 2012</h3>
    <p>Lorem ipsum</p>
    <p><a class="post-edit-link" href="http://localhost:8888/theme/wp-admin/post.php?post=1&action=edit" title="Redigera inlägg">Edit</a></p>

    So I try using this as my URL
    But it doesn’t work. Am I completely confused or something? Thanks for any help.

    Moderator bcworkz


    My apologies, I’m the one confused, it must be theme dependent. I assumed since <article> tags did not appear on my template, it was standard output of the loop. Apparently my theme injects it via a hook to ‘the_output’ filter.

    You could do something similar, enclose the output with a <div id='post-###> block for which you can target your skip links to.

    You mean edit the loop to enclose all posts with that? What would be the command to get the post number?

    I’m thinking I should do something like this in the loop:

    <div id="<?php THE_POST_ID_NUMBER_FOR_LINKING(); ?>">
    			<h2><?php the_title(); ?></h2>
    			<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    			 <?php twentyten_posted_on(); ?>

    … … …

    And where would I then change it so that the excerpt-link links to this instead of to the single post?

    Moderator bcworkz


    In the loop, the global $post is available, the post ID is accessed with $post->ID .

    If your div id ended up being "post-60", the ‘excerpt’ link to get to it would be, or actually just seems to work also. (Assuming WP is installed in your site’s public html root)

    If your code is for the main loop of your index page, and not the sidebar loop of latest posts, then yeah, something like that, except don’t forget to close with a </div> .

    I would think you also would want to display the_content(); there, but it’s your call, not mine.

    Thanks for all the help. I have now solved it exactly like I wanted it to.

    In the loop my post display starts with this:
    <div id="<?php the_ID(); ?>">

    And my excerpt read more function now looks like this:

    function twentyten_continue_reading_link() {
    	return '<a href="' . get_permalink( get_option('page_for_posts' ) ) . '#' . get_the_ID() . '">' . __( '[Läs mer]', 'twentyten' ) . '</a>';

    And everything is working just as it should. Great!



    Forum Moderator

    @rahul928: It is extremely rude to interrupt another poster’s ongoing thread with a question of your own. Please stick to your own topic – which, I might add, you only posted an hour ago.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Excerpts links to full blog page with the name attribute’ is closed to new replies.