Site logo

Archived topic

Replicate Archive Page for CPT?

2 replies · Started by Mike on June 7, 2020

Viewing posts 1–3 of 3

Hi,

Apologies if this is a dumb question - I've searched high and low and can't quite nail this.

I have created a CPT "resources" which has "resource_categories" (like normal categories) and "resource_tags" (like normal tags).

I want the archive page to look exactly the same as the normal generatepress archive page i.e.:

Title
date author

Excerpt

Foldericon list of categories (but resource_categories)
tagicon list of tags (but resource_tags)

1) How can I present the normal GP way of showing categories and tags?
2) How can I show the date and author just as GP does?

If this is beyond the bounds of a reasonable question please say so, but any pointers would be great...

In the URLs I've shared - "review" is a normal archive and "resources" is the CPT archive I want to look the same.

thank you
Mike

Solved it - just needed to look harder!

Here's the solution - if you have any suggestions though please shout, as next I need to implement for for categories and tags, and then multiple CPTs and their category and tag equivalents.


add_action( 'after_setup_theme','cantuum_remove_entry_meta' );
function cantuum_remove_entry_meta() {
	remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
	remove_action( 'generate_after_entry_title', 'generate_post_meta' );
}

add_action( 'generate_after_entry_title', 'cantuum_cpt_post_meta' );
function cantuum_cpt_post_meta()
{
	if ( 'post' == get_post_type() || 'resources' == get_post_type() ) : ?>
		<div class="entry-meta">
			<?php generate_posted_on(); ?>
		</div><!-- .entry-meta -->
	<?php
endif;
}

add_action('generate_after_entry_content', 'cantuum_cpt_footer_meta');
function cantuum_cpt_footer_meta()
{
    if ('post' == get_post_type() || 'resources' == get_post_type()):
        $resource_cats = get_the_term_list(get_the_ID() , 'resource_categories', $before = '', ', ');
        $resource_tags = get_the_term_list(get_the_ID() , 'resource_tags', $before = '', ', ');
?>
        <footer class="entry-meta">
            <?php generate_entry_meta(); ?>
            <?php if (!empty($resource_cats)): ?>
                <span class="resource-cat-links">
					
					<span class="gp-icon icon-categories"><svg viewBox="0 0 512 512" aria-hidden="true" role="img" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em">
						<path d="M0 112c0-26.51 21.49-48 48-48h110.014a48 48 0 0 1 43.592 27.907l12.349 26.791A16 16 0 0 0 228.486 128H464c26.51 0 48 21.49 48 48v224c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V112z" fill-rule="nonzero"/>
					</svg></span><span class="screen-reader-text">Categories </span>
										
					<?php echo $resource_cats; ?></span>
            <?php
        endif; ?>

			<div></div>			
			
			
            <?php if (!empty($resource_tags)): ?>
                <span class="resource-tags-links">
					
			<span class="gp-icon icon-tags"><svg viewBox="0 0 512 512" aria-hidden="true" role="img" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em">
						<path d="M20 39.5c-8.836 0-16 7.163-16 16v176c0 4.243 1.686 8.313 4.687 11.314l224 224c6.248 6.248 16.378 6.248 22.626 0l176-176c6.244-6.244 6.25-16.364.013-22.615l-223.5-224A15.999 15.999 0 0 0 196.5 39.5H20zm56 96c0-13.255 10.745-24 24-24s24 10.745 24 24-10.745 24-24 24-24-10.745-24-24z"/>
						<path d="M259.515 43.015c4.686-4.687 12.284-4.687 16.97 0l228 228c4.686 4.686 4.686 12.284 0 16.97l-180 180c-4.686 4.687-12.284 4.687-16.97 0-4.686-4.686-4.686-12.284 0-16.97L479.029 279.5 259.515 59.985c-4.686-4.686-4.686-12.284 0-16.97z" fill-rule="nonzero"/>
					</svg></span><span class="screen-reader-text">Tags </span>
					
					<?php echo $resource_tags; ?></span>
            <?php
        endif; ?>

           <?php // if ( is_single() ) generate_content_nav( 'nav-below' );
         ?>
        </footer><!-- .entry-meta -->
    <?php
    endif;
}

Glad you've figured out :)

This archived topic is closed to new replies.