• 157gs

    (@157gs)


    This is so odd. I have my post wrapped in an _a_ tag instead of a _div_ so the entire post becomes a link ( instead of just the title ). For some reason if my post has a link in it – the get_content function somehow butchers the closing tags for all of the _a_ tags and breaks everything completely.

    Here is the loop: (please don’t flame me for the inline styling – it’s only temporary)

    <?php while (have_posts()) : the_post(); ?>
    <a href="#" style="display:block;">
         <?php the_content() ?>
         <h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>
    </a>
    <?php endwhile; ?>

    The resulting render has the _a_ tag wrapping the entire post – just like it should. But for some reason it also renders that same _a_ tag AGAIN inside the post. !?

    The post that it is trying to render has markup in it (divs,_a_ links). Does that break the_content function, should I use something else render the post!?

Viewing 5 replies - 1 through 5 (of 5 total)
  • jonimueller

    (@jonimueller)

    What are you trying to do differently? The code should look like this:

    <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

    Thread Starter 157gs

    (@157gs)

    What I’m trying to do differently is wrap the post in a _a_ tag. So, if I was to take your code example and move that _a_ tag outside the h3 – that would be what I’m attempting to do.

    jonimueller

    (@jonimueller)

    And the purpose would be? I’m not trying to be snarky or facetious here, I just want to understand why you want the whole thing to be a clickable link. It works fine the way it is, so there really isn’t an “issue” with it.

    jonimueller

    (@jonimueller)

    Maybe just try this inside your loop code:

    <a href="<?php the_permalink() ?>" rel="bookmark"><h3 class="storytitle"><?php the_title(); ?></h3>
    [insert php the_content or php the_excerpt code here]</a>

    But the problem I have with this is that it’s not semantic markup but .. it’s not my web site so .. go for it.

    jonimueller

    (@jonimueller)

    And also, if you have it this way and if you make the anchor tag display: block I don’t know what that will do to the rest of the post formatting and since I don’t know what formatting you plan for it (e.g., meta division, feedback division, paragraph tags, etc.) just be forewarned that you may have some more tweaking to do. Provided that code works. It should, I just relocated the existing anchor tags and entry ID code. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Wrapping a post in a tag instead of div – causes strange behaviour’ is closed to new replies.