Skip to content

Instantly share code, notes, and snippets.

@meetKowshik
Created October 23, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meetKowshik/c0b9b95cbcb86895ff69d27d95cebdc9 to your computer and use it in GitHub Desktop.
Save meetKowshik/c0b9b95cbcb86895ff69d27d95cebdc9 to your computer and use it in GitHub Desktop.
Sitemap template for WC
<?php
/**
* Template Name: Sitemap
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
$page_bg_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) )
?>
<header class="entry-header page-header" <?php if( $page_bg_image ): ?> style="background-image:url('<?php echo $page_bg_image; ?>');" <?php else: ?> style="background-image:url('https://kratorastaging.wpengine.com/wp-content/uploads/cat-banner.jpg');" <?php endif; ?>>
<div class="container">
<div class="page-header-content">
<h1 class="page-title"><?php the_title(); ?></h1>
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
</div>
</div>
</header><!-- .entry-header -->
<div class="entry-content sitemap">
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-md-4 col-lg-4">
<h3>Pages</h3>
<ul>
<?php
// Add pages you'd like to exclude in the exclude here
wp_list_pages( array( 'exclude' => '2121,2124,2126,405052,2125,2127,16839,428612', 'title_li' => '', ) );
?>
</ul>
</div>
<div class="col-12 col-sm-6 col-md-4 col-lg-4">
<h3>Products</h3>
<?php
$args = array(
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'product',
'post_status' => 'publish'
);
$post_array = new WP_Query( $args );
?>
<?php if( $post_array->have_posts() ){ ?>
<ul>
<?php while ( $post_array->have_posts() ) {
$post_array->the_post(); ?>
<li><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<div class="col-12 col-sm-6 col-md-4 col-lg-4">
<h3>Product Categories</h3>
<ul>
<?php
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<li><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a></li>';
$args2 = array(
'taxonomy' => 'product_cat',
'child_of' => 0,
'parent' => $category_id,
'orderby' => 'name'
);
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo '<li><a href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .'</a></li>';
}
}
}
}
?>
</ul>
</div>
</div>
<div class="row">
<div class="col-6">
<h3>Categories</h3>
<ul>
<?php
// Add pages you'd like to exclude in the exclude here
wp_list_categories( array( 'exclude' => '', 'title_li' => '', ) );
?>
</ul>
</div>
<div class="col-6">
<h3>Posts</h3>
<?php
$args = array(
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'post',
'post_status' => 'publish'
);
$post_array = new WP_Query( $args );
?>
<?php if( $post_array->have_posts() ){ ?>
<ul>
<?php while ( $post_array->have_posts() ) {
$post_array->the_post(); ?>
<li><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
</div>
</div>
</div><!-- .entry-content -->
</div>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment