Hey there,
i would like to use the order of post thumbnails from a page to navigate from a single post to the next.
Is there a simple way to use the laygridder order as post order?
Post Navigation
Hey there,
i would like to use the order of post thumbnails from a page to navigate from a single post to the next.
Is there a simple way to use the laygridder order as post order?
Ah, interesting.
Well, you would need to go through the JSON of the page's gridder and check the order of the thumbnails.
Try this in your php:
// $id has to be the id of the page you are getting the gridder json from
$gridder_json = get_post_meta( $id, '_gridder_json', true );
// if you need the gridder json of a term do: $gridder_json = get_term_meta( $id, '_gridder_json', true );
// now turn the gridder json into an object:
$obj = json_decode($gridder_json);
// now print the json object into your error.log file. Read more about this here: https://codex.wordpress.org/Debugging_in_WordPress
// to print to your debug.log you need to add this to your wp-config:
// define( 'WP_DEBUG', true );
// define( 'WP_DEBUG_LOG', true );
error_log(print_r($obj, true));
Now in your debug.log you can look at the json structure and traverse through it to find out the order of your thumbnails.
The above can be tricky if you don't have the experience, but it is a great learning opportunity.
You could also use the post order of the post overview:
Use a plugin like "Post Order" https://wordpress.org/plugins/intuitive-custom-post-order/
And then for finding out the next post do a wp_query using orderby => menu_order
https://codex.wordpress.org/Class_Reference/WP_Query
like:
// get all posts of post type "post"
$args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order',
'post_type' => 'post'
);
$all_posts_query = new WP_Query( $args );
if($all_posts_query->have_posts()){
foreach ($all_posts_query->posts as $post){
// do something with $post->ID
}
}
thanks Armin, works like a charme!
Hey everyone! Happy new year. I'm looking at an intuitive way to navigate posts similar to that of laygridder theme. Does this code add this ability?
Example https://forever1995.com
Yes next and previous arrows would be great. The same as laythemes project navigation.
Dear @forever1995
we need to see if this is possible. The Gridder is designed to actually display elements and not to switch between pages.
Best!
Marius
Just wanted to share this with you. No clue if it's the easiest way, but works great in my case. @forever1995
if(get_laygrid()) :
$gridder_json = get_post_meta( 7, '_gridder_json', true );
$obj = json_decode($gridder_json,true);
$current_id = $post->ID;
$items = $obj['cont'];
$total = count($obj['cont']);
foreach ($items as $item) {
if ($item['postid'] == $current_id) {
$current_pos = array_search($item, $items);
if($current_pos > 0) {
$prev_id = $items[$current_pos - 1]['postid'];
echo '<a rel="prev" href="' .get_permalink($prev_id). '" title="'.get_the_title($prev_id). '">Previous</a>';
}
if ($total - 1 > $current_pos) {
$next_id = $items[$current_pos + 1]['postid'];
echo '<a rel="next" href="' .get_permalink($next_id). '" title="'.get_the_title($next_id). '">Next</a>';
}
}
}
This just decodes the gridder_json and gets the position of the current item. Than it gets the ID's of prev and next Items.
Works for me. Have a great day!