• Resolved Murtaza Frosh

    (@maimooninc)


    Hello guys;

    I am developing a WP website for a client selling electronic safes. He wants his current static site in to CMS using WP. I am trying to replicate this page from his static website https://www.ktindia.co.in/products/electronicsafes/ into a WP loop.

    I have created a custom taxonomy called ‘safe-type’ under which I have made terms ‘fire-resistant-series’, ‘laptop-series’, ‘large-series’, ‘medium-series’, ‘small-series’, ‘standalone-series’ & I want them all to be in a loop and display just like in the link mentioned above.

    I tried this code, but it only shows the linked terms not the data inside them.

    <?php
    //list terms in a given taxonomy
    $taxonomy = 'industry';
    $tax_terms = get_terms($taxonomy);
    ?>
    <ul>
    <?php
    foreach ($tax_terms as $tax_term) {
    echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
    }
    ?>
    </ul>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Murtaza Frosh

    (@maimooninc)

    Well after further searching I got lucky & found this code

    $terms = get_terms('custom-post-type-name');
       foreach ($terms as $term) {
          $wpq = array ('taxonomy'=>'custom-post-type-name','term'=>$term->slug);
          $myquery = new WP_Query ($wpq);
          $article_count = $myquery->post_count;
          echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
          echo $term->name;
          echo "</h3>";
          if ($article_count) {
             echo "<ul>";
             while ($myquery->have_posts()) : $myquery->the_post();
                echo "<li><a href=\"".get_permalink()."\">".$post->post_title.      "</a></li>";
             endwhile;
             echo "</ul>";
          }
    }

    This code lists all terms under ‘safe-type’ taxonomy. Displays linked titles of all the products under a term, but can any tell me how to to attach post thumbnail along with the title.

    Regards
    Murtaza Frosh
    Maimoon Inc.

    Thread Starter Murtaza Frosh

    (@maimooninc)

    Guys upon some R&D with the code I have reached half way through, but the code is not rendering as I want it to. The below code that works renders the post thumbnail outside the ‘li’ and does not wrap inside the ‘href’ as seen in the code. Which is the reason I cannot style it. Please help.

    <?php
    $terms = get_terms('safe-type');
       foreach ($terms as $term) {
          $wpq = array ('taxonomy'=>'safe-type','term'=>$term->slug);
          $myquery = new WP_Query ($wpq);
          $article_count = $myquery->post_count;
          echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
          echo $term->name;
          echo "</h3>";
          if ($article_count) {
             echo "
    <ul>";
             while ($myquery->have_posts()) : $myquery->the_post();
                echo "
    <li><a>".the_post_thumbnail() .$post->post_title."" .get_field('price') . "</a></li>
    ";
             endwhile;
             echo "</ul>
    ";
          }
    }
    ?></a>

    Thread Starter Murtaza Frosh

    (@maimooninc)

    Resolved yipee!

    <?php get_header(); the_post(); ?>
    <div id="sidebar"><?php get_sidebar(); ?></div>
    
    <div id="content">
        <h1><?php the_title(); ?></h1>
    
    <?php
    $terms = get_terms('safe-type');
       foreach ($terms as $term) {
          $wpq = array ('taxonomy'=>'safe-type','term'=>$term->slug);
          $myquery = new WP_Query ($wpq);
          $article_count = $myquery->post_count;
          echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
          echo $term->name;
          echo "</h3>";
    
          if ($article_count) {
             echo "<ul>";
             while ($myquery->have_posts()) : $myquery->the_post();
    		 echo "<div class='pcontainer'><a href=\"".get_permalink()."\">";
                echo "<li>".the_post_thumbnail() .$post->post_title."<p class='price'>";
    
    			if(get_field('new_price'))
    			{
    				echo '<span class="old_price">Rs. ' .get_field('price') . '</span> > Rs. ' . get_field('new_price') . '';
    			}
    			else
    			{
    				echo 'Rs. ' . get_field('price') . '';
    			}
    
    		 echo "</p></li></a></div>";
             endwhile;
             echo "</ul><div class='clear'></div>";
          }
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Listing Custom Taxonomy Terms loop’ is closed to new replies.