Wordpress Taxonomy Term Titles - wordpress

I'm trying to display the title of a taxonomy term simply based on what the title of the taxonomy term is, NOT based on what posts are listed in the taxonomy.
Currently my taxonomy term and single post pages are displaying the titles of all taxonomies associated with each post.
For example...
I have a taxonomy called 'Residential', with a variety of terms associated with the taxonomy. Here's a link: http://desrosiers.robertrhu.com/residential/
There is a post called 'West Shore' that is associated with two taxonomy terms in the 'Residential' taxonomy, 'Renovations' and 'Contemporary'.
When I go to either the 'Contemporary' or 'Renovations' terms page OR to the 'West Shore' post, the heading lists BOTH taxonomy terms as the title. Here are some links: http://desrosiers.robertrhu.com/residential-category/contemporary/ and http://desrosiers.robertrhu.com/residential/west-shore/
So, if I click on 'Renovations', I want that page to only display the title 'Renovations'. If I click on 'Contemporary', I want that page to only display 'Contemporary'. And if I click on the single post in a particular taxonomy term, I want that single post to display the taxonomy term title that the post was navigated from.
Thanks in advance for your help!
Here is the code for the taxonomy term archive page:
<?php
/*
* Template Name: Residential Category Template
* Description: Template for Residential Project Types archive
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Taxonomy Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3 style="border-right: none; padding-left: 0;">
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h1>
<?php
$terms = get_the_terms( get_the_ID(), 'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
echo $term->name;
}
}
?>
</h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>
Here is the code for the single page:
<?php
/*
* Template Name: Residential Single Template
* Description: Template for Residential Project Types single
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Single Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3>
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h3>
<?php
$terms = get_the_terms( get_the_ID(),
'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
echo '<a href="' .esc_url( $term_link ) . '">' .
$term->name . '</a>';
}
}
?>
</h3>
<h1><?php the_field('project_title'); ?></h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>

Related

Taxonomy Custom field image is not showing

I want to show taxonomy custom field images on loop on the home page
"developers" is taxonomy name
and "developer_logo" is image field slug
I used that code only name is showing but image is not showing
<?php
$terms = get_terms( array( 'taxonomy' => 'developers', 'hide_empty' => false ) );
$image = get_field('developer_logo');
foreach ( $terms as $term ) : ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo $term->name; ?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name; ?></h4>
</div>
</div>
</div>
<?php
endforeach
?>
I just want to show the images of taxonomy custom field
**In the below code, i have added the term Id as second parameter in get_field() function to get image URL & replaced the $image variable from outside of loop to inside the foreach loop.**
<?php
$terms = get_terms(array(
'taxonomy' => 'developers',
'hide_empty' => false
));
foreach ($terms as $term) {
$image = get_field('developer_logo', $term->id); ?>
<div class="col-lg-4 col-md-6">
<div class="product product-zoom product--card">
<div class="product__thumbnail">
<img src="<?php echo $image; ?>" alt="<?php echo $term->name;?>">
</div>
<div class="product-desc">
<h4 class="text-center mb-2"><?php echo $term->name;?></h4>
</div>
</div>
</div>
<?php
}
?>

Custom Taxonomy List Wordpress

I'm really a beginner for creating and displaying custom tax on WordPress.
I created a custom Genre taxonomy and I'm displaying this with this:
<?php $terms = get_the_terms( get_the_ID(), 'movie_genre' ); if( $terms ): ?>
<!-- Movie Genre -->
<div class="slideout-heading">
<div class="d-inline-block">
<h5><?php esc_html_e( 'Genre'); ?></h5>
</div>
</div>
<div class="row">
<div class="carousel mb-3 w-100" data-flickity='{ "pageDots": false, "imagesLoaded": true, "prevNextButtons": true, "cellAlign": "left", "contain": true, "groupCells": true }'>
<?php foreach( $terms as $term ): ?>
<?php
$attachment_id = get_field('taxonomy_image', $term);
$size = "wp-img-square-profile"; // (thumbnail, medium, large, full or custom size)
$genreimage = wp_get_attachment_image_src( $attachment_id, $size );
?>
<div class="col-3 py-3">
<div class="mb-2">
<a href="<?php echo get_term_link( $term ); ?>">
<?php if( $attachment_id ) {
echo '<img class="img-fluid border-class shadow-sm" src="'. $genreimage[0] .'" />';
} else {
wp_default_img_placeholder();
}
?>
</a>
</div>
<div class="author-list-name px-1">
<?php echo esc_attr ($term->name); ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
How could I display Genres Parent & Child together another and other? I can display selected parent and child for the custom taxonomy but could not relate with a parent it's just showing one by one not related with the parent but I would like to relate the group Parent-Child :)
-Action
best actor
best music
-Adventure
best music
output
Custom_Movie_Genre_Taxonomy
Thanks a lot for your help!

Title on a page with custom template

Good day!
I have a strange issue with Wordpress 5.1.1. I have two pages with custom templates, a homepage and a blog page. On other pages I use standard template. And on standard pages I can see page title like About us - Sitename, Contacts - Sitename.
But on these custom pages it's empty! I can see only Sitename and title tag is empty. What it can be?
Also, I use custom WP_Query on a blog page.
UPD
This is my custom blog page:
<?php
/**
* Template Name: Статьи
*/
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 4, 'paged'=> $page ));
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
get_header();
the_title();
?>
<div id="blog_cards" class="ui grid">
<div class="sixteen wide column">
<div id="categories">
<?php
foreach( $categories as $category ) {
$category_link = sprintf(
'<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo $category_link;
}
?>
</div>
</div>
<div class="sixteen wide column">
<div class="ui two cards">
<?php
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="card">
<div class="image">
<?php the_post_thumbnail();?>
</div>
<div class="content">
<div class="header"><?php the_title();?></div>
<div class="meta">
<a><?php the_time('d.m.Y');?></a>
</div>
<div class="description">
<?php the_content();?>
</div>
</div>
<div class="extra content">
<?php
$post_cats = get_the_category();
foreach( $post_cats as $category ) {
$category_link = sprintf(
'<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo $category_link;
}
?>
</div>
</div>
<?php endwhile;?>
</div>
</div>
<div class="sixteen wide column">
<?php if (function_exists('wp_corenavi')) wp_corenavi(array( 'wp_query' => $wp_query )); ?>
</div>
<?php
endif; ?>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
Also, I tried to call the_title() and it returned page title in a body of template. But title tag is empty.
And I use standard storefront theme for woocomerce.
Please move get_header() on the top of the page (before $page).

how to add pagination in wordpress

I have posts in different custom taxonomies. I need to display posts for one taxonomy in a page. Now I'm getting the all the posts in all taxonomies in a single page. I have a foreach loop for taxonomy and inside the loop all the posts corresponding to that taxonomy is displaying through post method.I have never used pagination before. How can I add pagination in this case?
I am enclosing my code below
<div class="main">
<section class="brands-sec product-sec">
<div class="container">
<?php
$siteurl = home_url('/');
$tax = 'product'; // slug of taxonomy
$terms = get_terms($tax);
foreach ($terms as $term) {
$id = $term->term_id;
$slug = $term->slug;
$description = $term->description;
$image_url = z_taxonomy_image_url( $id, NULL, TRUE ); // category image display
$link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>";
echo '<img src="' . $image_url . '">'; ?>
<div class="col-md-8 pull-right col-sm-10 pull-right col-xs-12 brnd prdct">
<img src="<?php echo $image_url ; ?>" class="img-responsive pdt-logo" alt="loyd"/>
<div class="brand-logos pdt">
<p><?php echo $description ; ?></p>
<h4>Product</h4>
<?php $args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
$posts = get_posts($args);
foreach($posts as $data){
$thumb = wp_get_attachment_url( get_post_thumbnail_id($data ->ID) );
$custom_fonts = get_post_custom($data->ID);$custom_fonts_key= $custom_fonts['category'];$custom_fonts_array = $custom_fonts_key[0]; ?>
<div class="row mb40">
<div class="col-md-4 col-sm-4 col-xs-12 brand-single product-single">
<img src="<?php echo $thumb; ?>" class="img-responsive" alt="allegro products"/>
<h5><?php echo $data->post_title; ?></h5>
<p><?php echo $data->post_content; ?></p>
</div>
<div class="col-md-8 col-sm-8 col-xs-12 brand-single product-detail">
<ul class="products">
<?php
$attachments = new Attachments( 'my_attachments',$data->ID ); /* pass the instance name */ ?>
<?php if( $attachments->exist() ) : ?>
<?php while( $attachments->get() ) : ?>
<li><img src="<?php echo $attachments->url(); ?>" class="img-responsive" alt="allegro products"/></li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
</div>
<?php } ?>
</div><!--end brand-logos-->
</div><!--end brnd-->
<?php } ?>
</div>
Here product is custom taxonomy . In that there are more than one terms say loyd,Nycofee,.... In Both these terms there are more than one posts. I need to display posts in loyd in one page and ncofee in next page. How to add pagination in this case?
Try this:
You have the post_per_page to be -1
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products" );
change it to the number you would like. and add to the end
'paged' => $paged
before Ending the PHP here
</div>
<?php } ?>
</div><!--end brand-logos-->
Add
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $args )); ?>
<?php wp_reset_postdata(); ?>
Here is the basic pagination for wordpress
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Soruce: https://codex.wordpress.org/Pagination "Example Loop with Pagination"
If it still show the full list.
Try this: http://callmenick.com/post/custom-wordpress-loop-with-pagination

woocommerce products by category repeated first 10 products on each page so how to display all product?

I created custom code for woocommerce products show as per selected category, first 10 product display as per the category but on the second page of pagination same 10 products are displayed, also at all page the same product are display, when products are order by rand then result is correct but i want result by title so please give me the solution for that my code is as below.
<ul class="products">
<?php $cat_slug=get_queried_object()->slug; ?>
<?php
$args = array( 'post_type' => 'product', 'product_cat' => $cat_slug, 'orderby' => 'title' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="product_cust ">
<div class="woo_100">
<div id="woo_c">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<div class="woo_thumb">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
</div>
</a>
</div>
<div id="woo_d">
<div class="woo_desc">
<div class="nil_desc">
<a href="<?php echo get_permalink( $loop1->post->ID ) ?>" title="<?php echo esc_attr($loop1->post->post_title ? $loop1->post->post_title : $loop1->post->ID); ?>">
<h3><?php the_title(); ?></h3>
</a>
<span class="price"><?php echo $product->get_price_html(); ?></span><br>
</div>
<div class="nil_cart"><?php woocommerce_template_loop_add_to_cart( $loop1->post, $product ); ?>
</div>
</div>
</div>
</div>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
You have not passed any variable to paginate it.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'product', 'product_cat' => $cat_slug, 'orderby' => 'title', 'paged'=>$paged);
Also after your loop use nav.php to get pagination control links.

Resources