WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excerpts links to full blog page with the name attribute (9 posts)

  1. Etabeeta
    Member
    Posted 2 years ago #

    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.

  2. bcworkz
    Member
    Posted 2 years ago #

    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.

  3. Etabeeta
    Member
    Posted 2 years ago #

    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:
    http://localhost:8888/theme/?page_id=60
    (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
    http://localhost:8888/theme/?page_id=60#post-1
    But it doesn't work. Am I completely confused or something? Thanks for any help.

  4. bcworkz
    Member
    Posted 2 years ago #

    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.

  5. Etabeeta
    Member
    Posted 2 years ago #

    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?

  6. bcworkz
    Member
    Posted 2 years ago #

    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.

  7. Etabeeta
    Member
    Posted 1 year ago #

    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!

  8. rahul928
    Member
    Posted 1 year ago #

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    @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.

Topic Closed

This topic has been closed to new replies.

About this Topic