Hi !
I am working on educational site where schools and colleges will be displayed along with blog posts.For this purpose I have created Schools and Colleges CPT.
Now I want to change structure of Archive pages for these cpts.I am thinking to use the Grid plugin for this task and i am pretty familiar with this plugin.
But unable to find template file or right way to complete this task…
Hi There,
- You have to setup a child theme first:
- After that create
archive-{post_type_slug}.php
(e.g: archive-schools.php) files in your child theme directory with the following code:
<?php
// =============================================================================
// VIEWS/INTEGRITY/WP-INDEX.PHP
// -----------------------------------------------------------------------------
// Index page output for Integrity.
// =============================================================================
get_header();
$stack = x_get_stack();
?>
<div class="x-container max width offset">
<div class="<?php x_main_content_class(); ?>" role="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php x_get_view( $stack, 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php x_get_view( 'global', '_content-none' ); ?>
<?php endif; ?>
<?php pagenavi(); ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Hope it helps
Hi !
Works great ! and achieved target which I wanted.
Again one more question !
How to assign custom sidebar for this ARCHIVE page…?
Hello @shriyash802,
To assign a custom sidebar to your custom post type archive, assuming that the child theme is set up, please add the following code in your child theme’s functions.php file
// =============================================================================
// Assign sidebar to custom post archives
// =============================================================================
add_filter( 'ups_sidebar', 'add_cpt_sidebar' );
function add_cpt_sidebar($sidebar){
if ( is_post_type_archive('my_custom_post_type') && ! empty( $query->query['post_type'] == 'my_custom_post_type' )) {
return 'ups-sidebar-my-sidebar';
}
return $sidebar;
}
// =============================================================================
Do not forget to forget to replace my_custom_post_type
in the code above. And just make sure that you replace ups-sidebar-my-sidebar
with the actual ID of your custom sidebar as shown below:
Regards.
Thanks for support.
Does this method supports for ‘Tags’ and ‘Categories’ ?
Hello Shriyash,
Thanks for updating the thread.
Above solution is using WordPress conditional tags. You can use conditional tags to make the necessary changes. To learn more, please refer following resource.
https://codex.wordpress.org/Conditional_Tags#A_Category_Page
https://codex.wordpress.org/Conditional_Tags#A_Tag_Page
Thanks.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.