wordpress pull 2 latest blog post
Posted by Taylor Bernard on September 16, 2015
i'm right on the brink of getting this.
theres couple ways to do this:
1. call an array/group of blog post, and tell how how many to pull ex- "=5" will populate 5 all together. this will work but we need them in 2 separate divs so that causes issues.
2. manually insert the post ID#.
so after they make a new post, they grab the post id# and put it into the php snippet and it populates that widget with the appropriate copy.
good, but a couple more steps for them to do, may be a good backup.
3. auto search and find latest post ID, populate 1 widget with it, then make another call to find latest ID # and use the get_next_post function to populate next in line without knowing either ID #'s.
got the first part of that function working. its correctly pulling latest post. and have 'something' pulling on second post, but its not the right post, or any post title at that.
heres my current hacked together code. first part above 'global' is working fine.
<?php
$last = wp_get_recent_posts( '1');
$last_id = $last['0']['ID'];
echo get_the_title($last_id);
global $last_id;
$post = get_next_post();
echo get_the_title($post);
?>
here are some resources..
https://codex.wordpress.org/Function_Reference/get_the_title
https://codex.wordpress.org/Function_Reference/get_next_post
http://stackoverflow.com/questions/6324421/getting-next-previous-post-id-using-current-post-id-in-wordpress
theres couple ways to do this:
1. call an array/group of blog post, and tell how how many to pull ex- "=5" will populate 5 all together. this will work but we need them in 2 separate divs so that causes issues.
2. manually insert the post ID#.
so after they make a new post, they grab the post id# and put it into the php snippet and it populates that widget with the appropriate copy.
good, but a couple more steps for them to do, may be a good backup.
3. auto search and find latest post ID, populate 1 widget with it, then make another call to find latest ID # and use the get_next_post function to populate next in line without knowing either ID #'s.
got the first part of that function working. its correctly pulling latest post. and have 'something' pulling on second post, but its not the right post, or any post title at that.
heres my current hacked together code. first part above 'global' is working fine.
<?php
$last = wp_get_recent_posts( '1');
$last_id = $last['0']['ID'];
echo get_the_title($last_id);
global $last_id;
$post = get_next_post();
echo get_the_title($post);
?>
here are some resources..
https://codex.wordpress.org/Function_Reference/get_the_title
https://codex.wordpress.org/Function_Reference/get_next_post
http://stackoverflow.com/questions/6324421/getting-next-previous-post-id-using-current-post-id-in-wordpress
Comments
Taylor Bernard on September 16, 2015:
http://client.fleeangrybear.com/webb/
Justin Bernard on September 17, 2015:
Taylor Bernard on September 17, 2015:
Taylor Bernard on September 17, 2015:
first title 'menus of change' is good to go.
need the 2nd one to do the same as the first, to get the id#, then use the get_next_post() command to make it current -1
Justin Bernard on September 17, 2015:
take a look at that sprite thing, i want to get that in play on realtree so can be wrapped on that