Site logo

Archived topic

Custom Taxonomy Archive page

13 replies · Started by David on October 4, 2018

Viewing posts 1–14 of 14

I am trying to get my custom taxonomy pages to reflect the same settings I am applying to my standard archive page (https://learn04.digitaldiplomats.com/category/news-and-info/). But it does not.

Is this achievable without coding? If coding is need, what files will need to be created to get the loop integrated in the custom taxonomy/post type pages?

Thanks

Hi David,

We'll need to add a couple filters to achieve this.

Just to confirm, which settings should we be targeting? I'm seeing masonry, but is there anything else?

Hi Tom,

For some reason, your reply wasn't appearing on my mobile.

I'm using an Excerpt with a Word Count of 20. Displaying Read More as a Button. All so Displaying Tags.

For Featured Images, I have those set to Display, with padding. Title is below the image and centered.

Columns set to Display with 3 Columns. And Masonry.

Thanks.

Word count and read more button should happen by default. Doesn't look like any of those posts are long enough for them to apply.

The featured image settings should apply as well.

Columns and masonry:

add_filter( 'generate_blog_columns', 'tu_tax_columns' );
function tu_tax_columns( $columns ) {
    if ( is_tax( 'sait_division' ) ) {
        return true;
    }

    return $columns;
}

add_filter( 'generate_blog_masonry', 'tu_tax_masonry' );
function tu_tax_masonry( $masonry ) {
    if ( is_tax( 'sait_division' ) ) {
        return 'true';
    }

    return $masonry;
}

Tags and categories:

add_action( 'generate_after_entry_title', 'tu_tax_meta' );
function tu_tax_meta() {
    if ( is_tax( 'sait_division' ) ) : ?>
        <div class="entry-meta">
            <?php generate_posted_on(); ?>
        </div><!-- .entry-meta -->
    <?php endif;
}

Let me know if this gets us close :)

Hi Tom,

Quick reply, Thanks!

Now for the dumb question...where do I put the code? In the function.php or use elements-hook?

I'm a design/implementer...I'm been using and recommending GeneratePress for several years, but I never had to add code to it until now.

Thanks, Leo.

Perfect. I'll try one of those tool in the morning. I actually read that page weeks ago, added the plugins in. Now I can actually use them.

Again, many thanks to you and Tom.

No problem!

Let us know :)

Good morning,

I was able to use the code for columns and masonry. It worked for a single taxonomy, but code snippet came back with the following error code when I tried to add another version with a different taxonomy...

The code snippet you are trying to save produced a fatal error on line 8:

Cannot redeclare tu_tax_columns() (previously declared in /homepages/14/d119673623/htdocs/learn/learn04/wp-content/plugins/code-snippets/php/snippet-ops.php(353) : eval()'d code:2)
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

I have a total of four taxonomies and two post types: Course Topic, Resource Topic, Resource Type, SAIT-Divison, Course Type and Knowledge Resource Type.

As for the tags and categories, the code did not work.

Thanks

Ah, you can add multiple taxonomies like this:

add_filter( 'generate_blog_columns', 'tu_tax_columns' );
function tu_tax_columns( $columns ) {
    if ( is_tax( array( 'sait_division', 'another_one', 'one_more' ) ) ) {
        return true;
    }

    return $columns;
}

add_filter( 'generate_blog_masonry', 'tu_tax_masonry' );
function tu_tax_masonry( $masonry ) {
    if ( is_tax( array( 'sait_division', 'another_one', 'one_more' ) ) ) {
        return 'true';
    }

    return $masonry;
}

So just the two functions with the multiple taxonomies on the same line.

As for the tags and categories - do your posts within these taxonomies have the core tags and categories enabled? Or are you using different taxonomies within them?

The tags are core. I don’t need to display categories.

So instead of that tags/category function, try this:

add_action( 'generate_after_entry_title', 'tu_tax_meta' );
function tu_tax_meta() {
    if ( is_tax( array( 'sait_division', 'another_one', 'one_more' ) ) ) : ?>
        <div class="entry-meta">
            <?php
                $tags_list = get_the_tag_list( '', ', ' );
                if ( $tags_list ) {
                    echo $tags_list;
                }
            ?>
        </div><!-- .entry-meta -->
    <?php endif;
}

get_the_tag_list() is a core WP functions, so it should work.

Hi Tom,

The first code work again. Thank you so very much.

The tags code didn't, so I decided to make a new taxonomy for subject tags. You've helped me to get where I needed to go.

I can't thank you guys enough.

David

Glad I could help! :)

This archived topic is closed to new replies.