FalsAlarm Posted April 19, 2018 Share Posted April 19, 2018 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 More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 I've been struggling which of the following functions that I should be using. https://www.w3schools.com/php/php_ref_string.asp Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2018 Share Posted April 19, 2018 String replacement is probably not the right tool for this job. What is the actual string (as in, post it) and how much do you know about it that will always be true? Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 the links are below. <div class="row">stuff</div> they are wordpress links. Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2018 Share Posted April 19, 2018 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 More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 I'v been struggling with how to get multiple posts per homepage. however, i'm using wp_qet_pages() and wp_query() as a workaround. I'd still like to know how to accomplish what I said earlier. Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 yes, it's my person bikini blog. Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2018 Share Posted April 19, 2018 If you want to know how to do it for academic reasons that's one thing, but the solution to the problem is fixing the template so it outputs the HTML you want. So you know where that template is? How to edit it? Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 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 More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 oh i see the problem now that the <a> isn't closed lol Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 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 Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 and my other problem is that $fivesdrafts->post_content contains an <img> link along with an empty unmarked up text string that needs to be in a paragraph tag Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2018 Share Posted April 19, 2018 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 functionI 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 tagSo 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 More sharing options...
FalsAlarm Posted April 19, 2018 Author Share Posted April 19, 2018 plz just help me out. I really need to fix it badly Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2018 Share Posted April 19, 2018 If you want me to wave a magic wand and make everything work then you're out of luck. I ask questions because I need to know the answer, not just because I like to be annoying. Link to comment Share on other sites More sharing options...
FalsAlarm Posted April 20, 2018 Author Share Posted April 20, 2018 Anyone help me out here. please and thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.