• Resolved grigorax

    (@grigorax)


    I want to insert content to explain what the Pod is all about. For example if my Pod is a gallery of my art, I want to have an image embodying what my art is all about, and an artist’s statement summarising all the artworks. HOWEVER this can be done only at the level of the individual artwork. This means I have to repeat the same content for EVERY artwork. This seems very cumbersome.

    Is there any way around this?

Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Either add a taxonomy or edit the theme template for the post type.

    Taxonomy

    Create a custom taxonomy, connect it to the art post type, then add the description and image fields as fields.

    If a description and image should apply to all artwork, edit the name and fields of the default “Uncategorized” term, which can be edited to any name.

    If there are several series with different banner images and descriptions, then taxonomy terms can then organize this, displaying one or many.

    For example, displaying taxonomy fields with a filter… Pods has similar functionality using magic tags in Auto Templates connected to the_content. The below filter added as a Code Snippet assumes a post type art has been connected to taxonomy art_category with fields image as a File field and description as a plain text field.

    <?php
    add_filter(
    'the_content',
    function( $content ) {
    if ( 'art' === get_post_type() && is_singular() ) {
    $pod = pods( get_post_type(), get_the_ID() );
    $content = $pod->template(
    null,
    '<p><img src="{@art_category.image}" /></p><p>Description: {@art_category.description}</p>'
    ) . $content;
    }
    return $content;
    }
    );

    The equivalent for a template connected to the_content with Auto Templates would be:

    <p><img src="{@art_category.image}" /></p>
    <p>Description: {@art_category.description}</p>

    …with the Auto Template set to add to the beginning of post_content.

    Edit the post type template

    The WordPress Template Hierarchy will use single-post-type-name.php as the template for a named post type. e.g., single-art.php. This can be duplicated from single.php with a description and image added in HTML.

    Add one description to all art without any fields or taxonomies.

    In generic PHP form, get_post_type() will return the current post type, allowing additional fields to be displayed on the_content filters or in any other context.

    For example:

    <?php
    add_filter(
    'the_content',
    function( $content ) {
    if ( 'art' === get_post_type() && is_singular() ) {
    // Displays for all art.
    $content = '<p><img src="https://picsum.photos/800/200/" /></p><p>This art is all inspired by Pablo Picasso.</p>' . $content;
    }
    return $content;
    }
    );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.