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!
Related
i try to get posts via query wordpress
i need to fetch the posts thats's in spacfic taxonamy
تصميم تطبيقات
<?php
get_query_var('taxonomy');
$taxonomy = 'eposd_category';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
?>
<?php foreach ( $terms as $term ) { ?>
<div class="col-sm-3">
<div class="item">
<div class="load">
<?php echo z_taxonomy_image($lug term->term_s); ?>
<div class="load-icon text-center">
<i class="fa fa-play"></i>
</div>
</div>
<div class="item-content">
<h2><?php echo $term->name; ?></h2>
</div>
</div>
</div>
<?php } ?>
<?php endif;?>
تصميم العاب
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
}
?>
How can I wrap the content in the overlay div with a permalink that corresponds to the category. I want the image to be clickable and also pull the category name with the matching image. I want this to be dynamic in the event new categories are added.
<?php
/**
*
* Catergory Display
*
*/
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
) );
?>
<div class="container">
<div class="row">
<?php
foreach( $categories as $category ) {
$image = get_field('category_image', 'category_' . $category->term_id);
$size = 'featured-thumbnail'; // (thumbnail, medium, large, full or custom size)
$cat_link = get_category_link($category->cat_ID);
?>
<div class="category-holder col-lg-4 col-md-6 col-sm-12 ">
<div class="category-display-img">
<?php echo wp_get_attachment_image( $image, $size ); ?>
<a href="<?php echo esc_url( get_permalink($cat_link) )?>">
<div class="overlay"><?php echo '<a class="" href="'.$cat_link.'">'.$category->name.'</a>'; // category link ?></div>
</a>
</div>
</div>
<?php
// echo '<pre>';
// print_r($cat_link);
// wp_die();
} ?>
</div>
</div>
You can wrap the anchor tag around the div with the overlay class.
Delete this part
<a href="<?php echo esc_url( get_permalink($cat_link) )?>">
<div class="overlay"><?php echo '<a class="" href="'.$cat_link.'">'.$category->name.'</a>'; // category link ?></div>
</a>
And use this in its place
<a href="<?php echo $cat_link ?>">
<div class="overlay">
<?php echo $category->name ?>
</div>
</a>
I am trying to show categories in archive page instead of posts which by clicking on category name, show all related posts again in archive page.
<?php
$categories = get_categories();
foreach($categories as $category) {
?>
<!-- Single gallery Item -->
<div class="col-12 col-md-6 single_gallery_item entre wow fadeInUp" data-wow-delay="0.2s">
<!-- Welcome Music Area -->
<div class="poca-music-area style-2 d-flex align-items-center flex-wrap">
<div class="poca-music-content text-center">
<span class="music-published-date mb-2">December 9, 2018</span>
<h2>
<?php echo '' . $category->name . ''; ?>
</h2>
<div class="music-meta-data">
<p>By Admin | Tutorials | 00:02:56</p>
</div>
<div>
<?php
$category_description = category_description();
echo $category_description;
?>
</div>
</div>
</div>
</div>
<?php
}
?>
this is my code for listing categories, but I do not know how to show categories' description and feature images which I added by a plugin by the name of Category featured image.
This quick example:
$categories = get_categories();
foreach($categories as $category) {
$featured_image_id = get_term_meta( $category->term_id, 'featured_image_id', true );
$category_image = wp_get_attachment_image( $featured_image_id, 'thumbnail' );
?>
<p><?php echo $category->name ?></p>
<p><?php echo $category->description ?></p>
<p><?php echo $category_image; ?></p>
<?php
}
Hope it help you.
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