Dynamic Render – Somehow need an index count
-
Hi there,
I LOVE your plugin. It’s the perfect addition to the most useful WP plugin ever created.
I’m just delving into Dynamic Render for the first time today. An issue I’m having is that I need to somehow get an index count of each layout on the page, and here’s why (I’m open to suggestions of better ways to accomplish this): Some of the blocks of content, like carousels, or blocks with modals, require unique targets. So if one of my content editors were to add, say, 2 carousels on a page, each one would need to have a unique (in Bootstrap, for example) ID and data-bs-target. The way I’d been handling this up until now was to have the following at the start:
<?php while(have_rows('choose_layout_items')) { the_row(); $layout = get_row_layout(); if(!isset($layout_counts[$layout])) { $layout_counts[$layout] = 0; } $layout_counts[$layout]++; ?>
And then putting this in the classes for each layout:
layout-<?php echo get_row_index(); ?>
This allows me to have custom styles for individual blocks that also reference that row index number. Example:
data-bs-target="Carousel<?php echo get_row_index(); ?>"
I do know it’s not great form to put <style></style> elements inside the main content area, but with the need for having styles that reference specific layout numbers, it’s what I’ve wound up doing. I’m not sure what another solution might be though. I’m definitely open to suggestions. But I am also hoping there’s a way to get that layout count, while using Dynamic Render.
- The topic ‘Dynamic Render – Somehow need an index count’ is closed to new replies.