function add_taxonomies_to_pages() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'add_taxonomies_to_pages' );
if ( ! is_admin() ) {
add_action( 'pre_get_posts', 'category_and_tag_archives' );
}
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');
if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
$wp_query->set( 'post_type', $my_post_array );
if ( $wp_query->get( 'tag' ) )
$wp_query->set( 'post_type', $my_post_array );
}
add_action( 'woocommerce_after_shop_loop_item_title', 'custom_show_product_cat', 7 );
function custom_show_product_cat() {
global $product;
echo wc_get_product_category_list( $product->get_id(), ', ', '<div class="product-cat">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</div>' );
}
function x_theme__remove_name_cat( $title ){
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'x_theme__remove_name_cat' );
$terms_array = array(
'taxonomy' => 'services', // you can change it according to your taxonomy
'parent' => 0 // If parent => 0 is passed, only top-level terms will be returned
);
$services_terms = get_terms($terms_array);
foreach($services_terms as $service): ?>
<h4><?php echo $service->name; ?></h4>
<?php
$post_args = array(
'posts_per_page' => -1,
'post_type' => 'service', // you can change it according to your custom post type
'tax_query' => array(
array(
'taxonomy' => 'services', // you can change it according to your taxonomy
'field' => 'term_id', // this can be 'term_id', 'slug' & 'name'
'terms' => $service->term_id,
)
)
);
$myposts = get_posts($post_args); ?>
<ul>
<?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; // Term Post foreach ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endforeach; // End Term foreach; ?>
$newsLoop = new WP_Query(array(
'posts_per_page' => 10,
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'post_delete',
'value' => '0',
'compare' => 'LIKE',
)
),
));
if ( $newsLoop->have_posts() ) : ?>
<div class="news-wrapper">
<?php while ( $newsLoop->have_posts() ) : $newsLoop->the_post();
$post_delete = get_post_meta( $post->ID, 'post_delete' );
?>
<?php if ( !$post_delete ): ?>
<?php get_template_part( 'template-parts/loop', get_post_format() ? : 'video' ); ?>
<?php endif ?>
<?php endwhile;?>
</div>
<?php endif; wp_reset_query(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'custom_post_type_name',
'posts_per_page' => 10,
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// CPT content
endwhile;
?>
<div class="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );
?>
</div>
<?php wp_reset_postdata(); ?>
/**
* Add quantity field on the shop page.
*/
function ace_shop_page_add_quantity_field() {
/** @var WC_Product $product */
$product = wc_get_product( get_the_ID() );
if ( ! $product->is_sold_individually() && 'variable' != $product->get_type() && $product->is_purchasable() ) {
woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
}
}
add_action( 'woocommerce_after_shop_loop_item', 'ace_shop_page_add_quantity_field', 12 );
/**
* Add required JavaScript.
*/
function ace_shop_page_quantity_add_to_cart_handler() {
wc_enqueue_js( '
$(".woocommerce .products").on("click", ".quantity input", function() {
return false;
});
$(".woocommerce .products").on("change input", ".quantity .qty", function() {
var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button");
// For AJAX add-to-cart actions
add_to_cart_button.attr("data-quantity", $(this).val());
// For non-AJAX add-to-cart actions
add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val());
});
// Trigger on Enter press
$(".woocommerce .products").on("keypress", ".quantity .qty", function(e) {
if ((e.which||e.keyCode) === 13) {
$( this ).parents(".product").find(".add_to_cart_button").trigger("click");
}
});
' );
}
add_action( 'init', 'ace_shop_page_quantity_add_to_cart_handler' );
<?php
$prod_cat_args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => 0
);
$woo_categories = get_categories( $prod_cat_args );
?>
<?php foreach ( $woo_categories as $woo_cat ) :
$woo_cat_id = $woo_cat->term_id;
$woo_cat_name = $woo_cat->name;
$woo_cat_slug = $woo_cat->slug;
$woo_cat_descr = $woo_cat->description;
$category_thumbnail_id = get_term_meta($woo_cat_id, 'thumbnail_id', true);
$thumbnail_image_url = wp_get_attachment_url($category_thumbnail_id);
$cat_link = get_term_link( $woo_cat_id, 'product_cat' );
?>
<div class="product-cat-item">
<a href="<?php echo $cat_link ?>"><?php echo $woo_cat_name ?></a>
<?php if ($thumbnail_image_url) : ?>
<img src="<?php echo $thumbnail_image_url ?>" alt="<?php echo $woo_cat_name ?>">
<?php endif; ?>
<p><?php echo $woo_cat_descr ?></p>
</div>
<?php endforeach; ?>