Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Using LayThumbnail class for next/prev project within project footer

Using LayThumbnail class for next/prev project within project footer

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 26 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monospace
    wrote on last edited by
    #1

    Hi there,

    I was wondering if anyone has experience with using LayThumbnail class to display next/prev project thumbnails automatically at the end of a project using the globally defined (via Customizing ▸ Project Thumbnails) thumbnail settings.

    I want to create a shortcode for next and one for prev, placed in the project footer.

    Thanks!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      monospace
      wrote on last edited by monospace
      #2

      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');
      
      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by
        #3

        hey you only need this workaround cause at the moment $tags$ doesn't work in footers?

        1 Reply Last reply
        0
        • arminunruhA Offline
          arminunruhA Offline
          arminunruh
          Global Moderator
          wrote on last edited by
          #4

          if you want a next / prev link, you can also just have a text link that you can put in your footer as described here:

          https://laytheme.com/documentation/navigation-between-projects.html#next-project-link

          you can even use the projects titles in these links:

          Any text inside this "Next Project Link" can contain the text: $nextprojecttitle$. This will be replaced with the next project title.

          Any text inside the "Previous Project Link" can contain the text: $previousprojecttitle$. This will be replaced with the previous project title.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          💿 Email me here: 💿
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. 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:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          Z
          zlay
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search