Hi All,
I created a new taxonomies called models, every post i will insert the model name. Now i am trying to listing all models on a page. Which i created a called models and using a custom template to views listed models. I manage to list all the models but i have a problem on link back to their taxonomies slug. Please advice. I suspect something not right with the code.
<a href="<?php echo get_category_link( get_cat_ID($term->name) ); ?>" title="<?php echo $term->name; ?>"><span><?php echo $term->name; ?></span></a>
Full code is here on below;
<?php
/**
* Template Name: Models
*
* @package WordPress
* @subpackage Novavideo
* @since Novavideo 1.0
*/
get_header(); ?>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<h1 class="border-radius-5"><?php the_title(); ?></h1>
<div id="page" class="post-content">
<?php the_content(); ?>
<?php
$terms = get_terms("models", $args);
$count = count($terms);
$models = array();
if ($count > 0) {
echo '<ul class="listing-cat">';
foreach ($terms as $term) {
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'show_count' => 1,
'orderby' => 'rand',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'models',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$video_from_models = new WP_Query( $args );
if( $video_from_models->have_posts() ){
$video_from_models->the_post();
}else{}
$term->slug;
$term->name;
?>
<li class="border-radius-5 box-shadow">
<?php echo novavideo_get_post_image();?>
<a href="<?php echo get_category_link( get_cat_ID($term->name) ); ?>" title="<?php echo $term->name; ?>"><span><?php echo $term->name; ?></span></a>
<span class="nb_cat border-radius-5"><?php echo $term->count; ?> <?php if ( $term->count > 1 ){
_e( 'videos', novavideo_get_theme_name() );
}else{
_e( 'video', novavideo_get_theme_name() );
} ?></span>
</li>
<?php
}
echo '</ul>';
echo '<div class="clear"></div>';
}
?>
</div><!-- #page -->
<?php endwhile; ?>
<?php endif; ?>
<div class="pagination"><?php novavideo_theme_pagination(); ?></div>
</div> <!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
__________________
Added after 13 Hours 11 minutes:
Nevermind. I manage to solve it. by using get_term_link instead get_cat_link
I created a new taxonomies called models, every post i will insert the model name. Now i am trying to listing all models on a page. Which i created a called models and using a custom template to views listed models. I manage to list all the models but i have a problem on link back to their taxonomies slug. Please advice. I suspect something not right with the code.
<a href="<?php echo get_category_link( get_cat_ID($term->name) ); ?>" title="<?php echo $term->name; ?>"><span><?php echo $term->name; ?></span></a>
Full code is here on below;
<?php
/**
* Template Name: Models
*
* @package WordPress
* @subpackage Novavideo
* @since Novavideo 1.0
*/
get_header(); ?>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<h1 class="border-radius-5"><?php the_title(); ?></h1>
<div id="page" class="post-content">
<?php the_content(); ?>
<?php
$terms = get_terms("models", $args);
$count = count($terms);
$models = array();
if ($count > 0) {
echo '<ul class="listing-cat">';
foreach ($terms as $term) {
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'show_count' => 1,
'orderby' => 'rand',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'models',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$video_from_models = new WP_Query( $args );
if( $video_from_models->have_posts() ){
$video_from_models->the_post();
}else{}
$term->slug;
$term->name;
?>
<li class="border-radius-5 box-shadow">
<?php echo novavideo_get_post_image();?>
<a href="<?php echo get_category_link( get_cat_ID($term->name) ); ?>" title="<?php echo $term->name; ?>"><span><?php echo $term->name; ?></span></a>
<span class="nb_cat border-radius-5"><?php echo $term->count; ?> <?php if ( $term->count > 1 ){
_e( 'videos', novavideo_get_theme_name() );
}else{
_e( 'video', novavideo_get_theme_name() );
} ?></span>
</li>
<?php
}
echo '</ul>';
echo '<div class="clear"></div>';
}
?>
</div><!-- #page -->
<?php endwhile; ?>
<?php endif; ?>
<div class="pagination"><?php novavideo_theme_pagination(); ?></div>
</div> <!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
__________________
Added after 13 Hours 11 minutes:
Nevermind. I manage to solve it. by using get_term_link instead get_cat_link
Last edited: