For everyone else, here is the code for the two shortcodes. Not the most elegant solution, but it does what it should do:
<?php function lay_previous_post_thumbnail_shortcode() { global $post; $prev_post = get_previous_post(false); // Remove category restriction if ($prev_post && $prev_post->ID === $post->ID) { $prev_post = null; // Reset if it's the same as the current post } if (!$prev_post) { // No previous post found, get the first post $first_post = get_posts(array( 'numberposts' => 1, 'order' => 'DESC', 'orderby' => 'date', 'post_status' => 'publish' )); if (empty($first_post)) { return 'No posts available.'; // Display message when no posts found } $prev_post = $first_post[0]; } $prev_post_id = $prev_post->ID; $thumbnail_id = get_post_thumbnail_id($prev_post_id); $thumbnail = wp_get_attachment_image_src($thumbnail_id, 'full'); $project_description = get_post_meta($prev_post_id, 'lay_project_description', true); $markup = '<a class="layprevproject thumb" style="" href="#layprevproject">'; $markup .= '<div class="thumb-rel">'; $padding_bottom = ($thumbnail[1] != 0) ? ($thumbnail[2]/$thumbnail[1]*100) : 0; $markup .= '<div class="ph" style="padding-bottom: ' . $padding_bottom . '%; ">'; $markup .= '<img src="' . esc_url($thumbnail[0]) . '" style="position: absolute;top: 0;left: 0;width: 100%;height: auto;" alt="Previous Post Thumbnail">'; $markup .= '</div>'; $markup .= '</div>'; $markup .= '<div class="lay-textformat-parent below-image"><span class="descr">'; $markup .= $project_description; $markup .= '</span></div>'; $markup .= '</a>'; return $markup; } add_shortcode('lay_previous_post_thumbnail', 'lay_previous_post_thumbnail_shortcode'); function lay_next_post_thumbnail_shortcode() { global $post; $next_post = get_next_post(false); // Remove category restriction if ($next_post && $next_post->ID === $post->ID) { $next_post = null; // Reset if it's the same as the current post } if (!$next_post) { // No next post found, get the last post $last_post = get_posts(array( 'numberposts' => 1, 'order' => 'ASC', 'orderby' => 'date', 'post_status' => 'publish' )); if (empty($last_post)) { return 'No posts available.'; // Display message when no posts found } $next_post = $last_post[0]; } $next_post_id = $next_post->ID; $thumbnail_id = get_post_thumbnail_id($next_post_id); $thumbnail = wp_get_attachment_image_src($thumbnail_id, 'full'); $project_description = get_post_meta($next_post_id, 'lay_project_description', true); $markup = '<a class="laynextproject thumb" style="" href="#laynextproject">'; $markup .= '<div class="thumb-rel">'; $padding_bottom = ($thumbnail[1] != 0) ? ($thumbnail[2]/$thumbnail[1]*100) : 0; $markup .= '<div class="ph" style="padding-bottom: ' . $padding_bottom . '%; ">'; $markup .= '<img src="' . esc_url($thumbnail[0]) . '" style="position: absolute;top: 0;left: 0;width: 100%;height: auto;" alt="Next Post Thumbnail">'; $markup .= '</div>'; $markup .= '</div>'; $markup .= '<div class="lay-textformat-parent below-image"><span class="descr">'; $markup .= $project_description; $markup .= '</span></div>'; $markup .= '</a>'; return $markup; } add_shortcode('lay_next_post_thumbnail', 'lay_next_post_thumbnail_shortcode');
M
monospace
@monospace
Topics
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it
Online Users
Forgot your key, lost your files, need a previous Lay Theme or Addon version?
Go to www.laykeymanager.com