• Resolved brianhorace

    (@brianhorace)


    basically i use the salient theme and within that theme you can display your blog page using cards, within those cards it has a featured image, title, excerpt and the category for each post. I would also like to display my custom taxonomy for “resource type” which identifies the post as a blog, a whitepaper or an event.

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Salient theme support is going to be your best bet for how to potentially change or add to the output for that. Possible that you could do a child theme, but they may also have settings to help with this, or some sort of documentation.

    Thread Starter brianhorace

    (@brianhorace)

    They were not of any help. I know where the code should go, I’m just having issues with the correct way to write the php.

    Thread Starter brianhorace

    (@brianhorace)

    displaying it directly after this category output would be ideal:

    // Featured image.
    get_template_part( ‘includes/partials/blog/styles/masonry-material/post-image’ );

    // Output categories.
    get_template_part( ‘includes/partials/blog/styles/masonry-material/post-categories’ );

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Without knowing anything else for what they have going in their templates, chances are you’re going to want to duplicate includes/partials/blog/styles/masonry-material/post-categories.php and rename it to something else, say “post-MY-CUSTOM-NAME.php” Then add in get_template_part( ‘includes/partials/blog/styles/masonry-material/post-MY-CUSTOM-NAME’ ); below that spot above. Choose something besides “MY-CUSTOM-NAME” literally ??

    Then inside that file you’ll need to tweak which taxonomies it queries for and everything.

    Thread Starter brianhorace

    (@brianhorace)

    didnt quite work unfortunately, I believe there is an incorrect name but just not sure what it is:

    /**
    * Post categories partial
    *
    * Used when “Material” masonry style is selected.
    *
    * @version 10.5
    */

    // Exit if accessed directly
    if ( ! defined( ‘ABSPATH’ ) ) {
    exit;
    }

    global $post;

    echo ‘<span class=”meta-category”>’;

    $resource_types = get_ancestors();

    if ( ! empty( $resource_types ) ) {
    $output = null;
    foreach ( $resource_types as $resource_type ) {
    $output .= ‘slug ) . ‘” href=”‘ . esc_url( get_ancestors_link( $resource_type->term_id ) ) . ‘”>’ . esc_html( $resource_type->name ) . ‘‘;
    }
    echo trim( $output ); // WPCS: XSS ok.
    }

    echo ‘</span>’;`

    Thread Starter brianhorace

    (@brianhorace)

    …also do you guys do any custom programming?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I would recommend making use of https://developer.www.ads-software.com/reference/functions/get_the_terms/ since it’ll fetch the terms for the specified taxonomy, for the provided post.

    Also a pastebin.com link may help preserve formatting and whatnot above, as parts have become links, etc.

    Thread Starter brianhorace

    (@brianhorace)

    I tried using this in a separate file but it returned nothing, and while the php seems correct it’s posting nothing on the front end – any tips? just to reiterate I created a custom taxonomy called “resource type” I want it to show up on my blog cards:

    `<?php
    /**
    * Post categories partial
    *
    * Used when “Material” masonry style is selected.
    *
    * @version 10.5
    */

    // Exit if accessed directly
    if ( ! defined( ‘ABSPATH’ ) ) {
    exit;
    }

    global $post;

    echo ‘<span class=”meta-category”>’;

    $terms = get_the_terms( $post_id, $taxonomy );

    if ( is_wp_error( $terms ) ) {
    return $terms;
    }

    if ( empty( $terms ) ) {
    return false;
    }

    $links = array();

    foreach ( $terms as $term ) {
    $link = get_term_link( $term, $taxonomy );
    if ( is_wp_error( $link ) ) {
    return $link;
    }
    $links[] = ‘<a href=”‘ . esc_url( $link ) . ‘” rel=”tag”>’ . $term->name . ‘</a>’;
    }`

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Are you loading the file at all ? That the only guess I have here, without being able to see what the theme is doing as a whole, and what ways there are to integrate and tap into the spots in question.

    For example from your comment at https://www.ads-software.com/support/topic/displaying-a-custom-taxonomy-on-the-front-end/#post-14076185

    did you add below those two something like this below. I’m going to assume you named the file post-resource type.php, but rename that part to whatever you named your file.

    get_template_part( ‘includes/partials/blog/styles/masonry-material/post-resource type.php’ );
    
    Thread Starter brianhorace

    (@brianhorace)

    i called it includes/partials/blog/styles/masonry-material/post-taxonomies.php

    and added it just below like this:

    <?php
            
              // Featured image.
              get_template_part( 'includes/partials/blog/styles/masonry-material/post-image' );
    
              // Output categories.
              get_template_part( 'includes/partials/blog/styles/masonry-material/post-categories' );
            
    		  // Output categories.
              get_template_part( 'includes/partials/blog/styles/masonry-material/post-taxonomies' );
            
            ?>
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Gotcha, that’s good, and i assume you put it in the same directory as the others.

    Looking closer at your last code paste, you’re returning an array of links, but you’re not doing anything with them.

    Perhaps instead of:

    $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
    

    try

    $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
    echo implode( ', ', $links );
    

    This will combine all the links into a comma-separated list of links and echo it out into place.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘displaying a custom taxonomy on the front end’ is closed to new replies.