WordPress.org

Ready to get started?Download WordPress

Forums

Add permalink inline following post; another the_content <p> problem (6 posts)

  1. electriccounterpoint
    Member
    Posted 6 years ago #

    This shouldn't be that tough, right? I've got a sidebar with an unordered list of "Asides" on my front page; these don't display with a headline, so I want to add a link to the single-post (permalink) page following each one. But, the_content wraps its output in paragraph tags, so using something like

    <li><?php the_content(); echo(' <a href="'); the_permalink(); echo('" rel="bookmark" title="Permanent Link to '); the_title(); echo('">#</a>')?></li>

    puts the link ("#") on a new line.

    Various solutions I've seen on the forum that haven't worked:

    • Modifying wpautop — I don't want to do this because I don't want to affect all posts; only those in the "Asides" category.
    • Pass the "read more" argument to the_content — won't work because this isn't a "read more" situation. These posts don't have <!--more--> links, and I just want a link to the post page at the end.
    • CSS "run-in" or ":after" — I want this to work across browsers, of course, and anyway this seems like a pretty crude workaroud
    • Manually adding a link to the end of each post — this would take forever, and is again not a very satisfying "fix." In the words of the ubiquitous infomercial announcer, "There's got to be a better way!"
  2. electriccounterpoint
    Member
    Posted 6 years ago #

    bump

  3. electriccounterpoint
    Member
    Posted 6 years ago #

    Maybe the rtrim function is the answer? Here's what I've been playing with:

    <ul>
      <?php
        $posts = get_posts("numberposts=6&category=20");
        foreach($posts as $post) : setup_postdata($post);
      ?>
      <li>
        <?php
          $thisaside = the_content();
          $trimmed = trim($thisaside, "</p>");
          echo "$trimmed <a href=\""; the_permalink(); echo('" rel="bookmark" title="Permanent Link to '); the_title(); echo('">#</a>')
        ?>
      </li>
      <?php endforeach; ?>
    </ul>

    (The second argument for trim() should be "</p>," but I can't get it to escape properly in this post.)

    This is my special Loop for asides. What I want it to do is to trim the closing </p> tag from the end of the_content. It's not doing that, though; actually it looks indistinguishable from the result of my original code:

    <ul>
      <?php
        $posts = get_posts("numberposts=6&category=20");
        foreach($posts as $post) : setup_postdata($post);
      ?>
      li>
      <?php the_content(); echo(' <a href="'); the_permalink(); echo('" rel="bookmark" title="Permanent Link to '); the_title(); echo('">#</a>')?>
      </li>
      <?php endforeach; ?>
    </ul>

    By the way, my site is http://danray.org/. You can see the problem on the front page — the "#"s that link to the permalinks in the right column are their own separate paragraphs.

  4. electriccounterpoint
    Member
    Posted 6 years ago #

    Alright, I hacked this together using the advice in this thread. It relies on get_the_content(), though, so it's still not great.

  5. aconover
    Member
    Posted 6 years ago #

    I was struggling with this myself, but was actually able to fix it by using the CSS rule "display: inline;" on the aside's <p> tag. Haven't tested this in IE, but I believe it should work crossplatform!

  6. gmsand
    Member
    Posted 6 years ago #

    If it were me, I'd use an image and apply it globally via your css. Something like this:

    #sidebar ul ul li a:link,
    #sidebar ul ol li a:link {
            background: transparent url('images/#.gif') no-repeat 0% 50%;
            background-position: absolute;
            display: inline;
    	color: #777;
            font-style: normal;
    	text-decoration: none;
            padding-left: 7px;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags