Excerpts links to full blog page with the name attribute

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.

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="example.com/index.html#post-238">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.

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.

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 example.com/index.php#post-60, or actually just example.com/#post-60 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.