Guide

Attachments List

Displays a list of attachments for the parent post of the current attachment. This block is intended to be used on attachment pages only.

Block Metadata

PropertyValue
Nameprc-block/attachments-list
TitleAttachments List
Categorytext
Version0.2.0
API3
Textdomainattachments-list
ExampleYes (sample heading / hideHeading — inserter preview)

Attributes

AttributeTypeDefaultDescription
headingBackgroundColorstring"ui-black"Preset color slug for the heading background.
headingTextColorstring"ui-white"Preset color slug for the heading text.
hoverBackgroundColorstringPreset color slug for list item hover background.
hoverTextColorstringPreset color slug for list item hover text.
customHoverBackgroundColorstringCustom hex color for hover background.
customHoverTextColorstringCustom hex color for hover text.
activeBackgroundColorstringPreset color slug for the active (current) item background.
activeTextColorstringPreset color slug for the active item text.
customActiveBackgroundColorstringCustom hex color for active item background.
customActiveTextColorstringCustom hex color for active item text.
backgroundColorstring"ui-white"Preset color slug for the overall background.
headingstring"Attachments"The heading text displayed above the list.
hideHeadingbooleanfalseWhether to hide the heading.
styleobject{ spacing: { blockGap: "var:preset|spacing|20" } }Block style object with default block gap.
parentIdnumberOverride the parent post ID to fetch attachments from. If not set, uses the current post's parent.

Supports

FeatureEnabledNotes
AnchorYes
HTML editingNo
Color: backgroundYes
Color: textYes
Spacing: marginYes
Spacing: paddingYes
Spacing: blockGapYes
Typography: fontSizeYes
Typography: fontFamilyNo (default control enabled)

Context

This block uses the following context from parent blocks:

ContextDescription
postIdThe current post ID (used to determine the parent post).
postTypeThe current post type.

Usage Instructions

  1. This block is designed for use in attachment page templates only.
  2. Insert the Attachments List block into your attachment template.
  3. The block automatically queries and displays all sibling attachments (images attached to the same parent post).
  4. The current attachment is highlighted with the active state styles.
  5. The parent post itself is included as the first item in the list.
  6. Use the color controls to customize heading, hover, and active state colors.
  7. Optionally override the parentId attribute to fetch attachments from a specific post.

Block Markup Example

<ul
	class="wp-block-prc-block-attachments-list wp-block-prc-block-attachments-list__list"
	style="--hover-background-color: #f5f5f5; --hover-text-color: #000; --active-background-color: #e0e0e0; --active-text-color: #000; --block-gap: 0.5em;"
>
	<li
		class="wp-block-prc-block-attachments-list__list-item flex-align-center"
	>
		<a href="/parent-post-url/">Parent Post Title</a>
	</li>
	<li
		class="wp-block-prc-block-attachments-list__list-item flex-align-center is-active"
	>
		<a href="/attachment-url/">Current Attachment Title</a>
	</li>
	<li
		class="wp-block-prc-block-attachments-list__list-item flex-align-center"
	>
		<a href="/another-attachment/">Another Attachment Title</a>
	</li>
</ul>

PHP Rendering

The render_block_callback in class-attachments-list.php is server-side rendered:

  1. Determines the parent post ID from the parentId attribute or falls back to wp_get_post_parent_id().
  2. Calls get_attachments() which:
    • First collects all Chart Builder synced chart references from the parent post content.
    • Then queries all image attachments for the parent post (up to 50).
    • Filters out: art direction images, images with menu_order > 0, single-word titles, PDFs, and Getty-copyrighted images.
    • Results are cached for 1 hour.
  3. Renders the list with the parent post as the first item, followed by all attachments.
  4. The currently viewed attachment gets an is-active class.
  5. Injects CSS custom properties for hover/active colors via WP_HTML_Tag_Processor.

Frontend Interactivity

This block does not have a view script. All interactivity is handled via CSS hover/active states.

Styles

List items respond to CSS custom properties for hover and active states:

  • --hover-background-color / --hover-text-color: Applied on :hover.
  • --active-background-color / --active-text-color: Applied when .is-active.
  • --block-gap: Controls spacing between list items.

The list uses a vertical flex layout with no default list styling.

Was this helpful?