Jump to content

How to do a string replacement please


FalsAlarm

Recommended Posts

Hello everybody,

 

I have a variable that holds a text string that represents an <img> link and piece of text after it.

 

What I'd like to do is to fetch out the <img> link and surround the text with a <p> tag.

 

How would I got about doing such a thing?

 

 

Link to comment
Share on other sites

Okay, yeah, wasn't expecting that. Ahem. But the point is, you are working with a lot of HTML. And the right tool for the "working with a lot of HTML" job is DOMDocument.

 

But this WP stuff. Is it from your own site? Because the way to get the HTML output you want would be to do whatever it takes to WP to actually get that output from the start. Don't have to edit it after the fact because it's already correct.

Link to comment
Share on other sites

no, i don't really know what i'm doing right now in regards to editing the wordpress html. my code is below.

 

 

$fivesdrafts = $wpdb->get_results(
    "SELECT * FROM $wpdb->posts    WHERE id <= 60 && post_type='post' && post_title!='Auto Draft'"
);        

echo '<div class="row">';
foreach ( $fivesdrafts as $fivesdraft )
{
    echo '<div class="col-sm-3"">';
    //echo "<br>".print_r($fivesdraft);
    echo '<h2><a href='.$fivesdraft->post_name.'>'.$fivesdraft->post_title.'</h2>';
    //echo "<br><a href='.$fivesdraft->post_title.'>".$fivesdraft->post_title."</a>";
    echo "<br>".$fivesdraft->post_content;
    echo '</div>';
}
echo '</div>';
?>
 
for some odd reason as soon as i set that h2 tag to become a link, the entire contents of post_content became a link as well.
Link to comment
Share on other sites

but the real problem is that i have no way to put multiple posts on my homepage other than doing what I was doing with the wp_get_results function

I don't know WP but I'm pretty sure you're supposed to do it using a loop. "The Loop"? You get the posts you want to show, set up the loop, and inside display the posts like you normally would.

 

and my other problem is that $fivesdrafts->post_content contains an link along with an empty unmarked up text string that needs to be in a paragraph tag

So the post content itself has the problem? Are you doing this to fix the content because it's wrong, or because the content is right but in this particular case you want it to be different?

 

And sorry to ask but can you post that HTML again? I won't be stupid about it this time.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.