Here’s a useful code snippet in PHP for WordPress to get a link to the newest (latest, freshest… you get the idea) post in WordPress.
Code starts here:
$latest = get_posts(array('numberposts' => 1));
$url = get_permalink($latest->ID);
echo "<a href='" . $url . "'>Click here and read our latest post!</a>";
Yeah, that’s it. Have a great day!
First off, I didn’t not write this code. I might have modified it but I’m not sure since I’ve had it around for quite some time.
If you’re the creator, thanks! It’s been handy. And comment and I’ll add a “credit-link” in this post. 😉
The code to get the value, text or string or whatever you choose to call it is so easy to use, short and it’s handy in many different kind of applications.
If you’re writing a Scraper in VB.net, this is a perfect Function that surely will be useful for you.
Lets say you have a string with the following content:
"Erik Johan Jonas Johanna Martin David"
And you want to pick out the name between Johanna and David:
Dim FindIt As String = GetBetween(Haystack, "Johanna", "David")
So, I used Dim in the same line to set up a string to store the text we’re picking out and then used the function called GetBetween to extract the text.
There will be spaces that you might want to use Trim on since I didn’t include the space as a prefix and suffix when using the GetBetween function.
The code is in the full post. Follow the link!
Continue reading VB.net: Get a String between 2 words(any text) inside a larger string – Supereasy!