• Okay, so I am currently working on a custom plugin (my first ever attempt) for my own site. However, I’ve come upon an issue that has me stumped.

    I want to take the featured image from a custom post type, and make it the background of a div, and when that div is clicked on, I want the image to show up in a lightbox (I’m currently using Lightbox2).

    I want this all to be in a loop, so that I can have this happening for all of the posts in my custom post type.

    Thank you in advanced.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You essentially want a custom single post template for your CPT. Templates are best managed through a child theme, templates through plugins are much more tricky. If the template’s name takes the form single-{post-type}.php and is located in the current theme’s folder, it will be used automatically for any single CPT view.

    On this template, wrap the div containing the featured image with an anchor or link <a> tag that contains the usual data-lightbox attribute along with the href pointing to the proper size image.

    Setting the div’s background image property is best done with a style attribute within the div tag itself. This way template PHP can fill in the proper attribute values in each case by using functions like get_the_post_thumbnail_url().

Viewing 1 replies (of 1 total)

The topic ‘Custom post type Featured image Loop Lightbox’ is closed to new replies.