• Resolved thomas

    (@beloutte)


    hello,

    I’m trying to do something simple I guess, but I can’t find out how…

    I have a custom post type “reference”
    and a taxonomy “marque”

    I want to display all the taxonomies on a page

    I tried this but I only get all the posts of “reference”…

    $myquery = array(
       'post_type' => 'reference',
       'taxonomy'=> 'marque'
    );
    query_posts($myquery);

    how can I get the categories of “marque” ??

    thanks !

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter thomas

    (@beloutte)

    maybe I can explain better…

    in my taxonomy “marque” I have, for exemple, marque1, marque2, marque3…

    what I would like to do is to display it all on a page like this :

    <div id="marque1">
      <h1><a href="taxonomy">marque1</a></h1>
      <img src="taxonomy_thumbnail" alt="" />
    </div>

    in order to create illustrated links to my taxonomies…
    but I can find out how to do that…

    thanks if you can help…

    You can use a plugin like taxonomy images to assign images to your categories.

    Because you’re trying to retrieve categories, you’ll want to use get_categories. For example:

    $args = array('taxonomy' => 'marque');
    $baz = get_categories($args);
    // use $baz however you want

    Make sense?

    Also, in the future, use WP_Query to create a secondary loop, rather than using query_posts to modify the main loop.

    Thread Starter thomas

    (@beloutte)

    thanks for your answer !

    you mean using $baz to display the categories ?
    I’m not sure I see how to do… but I’ll search in that direction

    <?php
    $args=array(
      'taxonomy' => 'marque',
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $baz=get_categories($args);
      foreach($baz as $category) {
        echo '<div id="marque1">'
        echo '<h1><a href=" ' . get_category_link( $category->term_id ) . ' "  ' . '>' . $category->name.'</a> </h1> ';
        echo '<img src=" '. $category->image . ' "  ' . ' />;
        echo '</div>';  }
    ?>

    would it be correct ?

    Yea, is your code not working?

    $category probably won’t have an image though.

    Thread Starter thomas

    (@beloutte)

    yes it works, I just tried it !

    I will try the taxonomy image plugin, to get my ” $category->image “

    thank you !

    Thread Starter thomas

    (@beloutte)

    finally it does not work…
    the div are displayed, and the titles as well but there’s a problem with the links…
    they don’t show up. seems like “get_category_link( $category->term_id )” is not working
    any idea ?

    my final code (still need to get taxonomy images to work)

    <?php
    $args=array(
      'taxonomy' => 'marque',
      'orderby' => 'name',
      'order' => 'ASC'
      );
    
    $img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN' );
    
    $marques=get_categories($args);
      foreach($marques as $category) {
    
    	  echo '<div class="vignette-cata"><figure>';
    	  echo '<a href=" ' . get_category_link( $category->term_id ) . ' "  ' . '>';
    	  echo '<img src=" '.$img.' "  ' . ' />';
    	  echo '</a>';
    	  echo '<figcaption><a href=" ' . get_category_link( $category->term_id ) . ' "  ' . '>' . $category->name.'</a></figcaption> ';
    	  echo '</figure></div>';  }
    
    ?>
    Thread Starter thomas

    (@beloutte)

    hopefully I managed to display images with taxonomy image plugin 🙂

    still have to make the links to work…

    my code :

    <?php
    $args=array(
      'taxonomy' => 'marque',
      'orderby' => 'name',
      'order' => 'ASC'
      );
    
    $marques = get_categories($args);
      foreach($marques as $category) {
    
     	$tax_term_id = $category->term_taxonomy_id;
     	$images = get_option('taxonomy_image_plugin');
    
    	echo '<div class="vignette-cata"><figure>';
    	echo '<a href=" ' . get_category_link( $category->term_id ) . ' "  ' . '>';
    	echo wp_get_attachment_image( $images[$tax_term_id], 'medium' );
    	echo '</a>';
    	echo '<figcaption><a href=" ' . get_category_link( $category->term_id ) . ' "  ' . '>' . $category->name.'</a></figcaption> ';
    	echo '</figure></div>';  }
    
    ?>

    Can you just use $category->slug?

    <?php
    $args=array(
      'taxonomy' => 'marque',
      'orderby' => 'name',
      'order' => 'ASC'
      );
    
    $marques = get_categories($args);
      foreach($marques as $category) {
    
     	$tax_term_id = $category->term_taxonomy_id;
     	$images = get_option('taxonomy_image_plugin');
    
    	echo '<div class="vignette-cata"><figure>';
    	echo '<a href=" ' . $category->slug . ' "  ' . '>';
    	echo wp_get_attachment_image( $images[$tax_term_id], 'medium' );
    	echo '</a>';
    	echo '<figcaption><a href=" ' . $category->slug . ' "  ' . '>' . $category->name.'</a></figcaption> ';
    	echo '</figure></div>';  }
    
    ?>

    Thread Starter thomas

    (@beloutte)

    thank you so much andrew, it works !

    I just had to add the good relative path :

    echo '<a href="../marque/ ' . $category->slug . ' " ' . '>';

    so, final code if it can be useful for someone else :

    <?php
    $args=array(
      'taxonomy' => 'marque',
      'orderby' => 'name',
      'order' => 'ASC'
      );
    
    $marques = get_categories($args);
      foreach($marques as $category) {
    
     	$tax_term_id = $category->term_taxonomy_id;
     	$images = get_option('taxonomy_image_plugin');
    
    	echo '<div class="vignette-cata"><figure>';
    	echo '<a href="../marque/' . $category->slug . ' "  ' . '>';
    	echo wp_get_attachment_image( $images[$tax_term_id], 'medium' );
    	echo '</a>';
    	echo '<figcaption><a href="../marque/' . $category->slug . ' "  ' . '>' . $category->name.'</a></figcaption> ';
    	echo '</figure></div>';  }
    
    ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘A query for taxonomies’ is closed to new replies.