Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter soph87

    (@soph87)

    Hi! Thank you for your extended explanation, it was very usefull! I managed to make it work (after a lot of head scratching though) ??
    Thanks again!

    Thread Starter soph87

    (@soph87)

    Thank you! It works ?? Now I’m trying to create a shortcode that my clients can use in a post to link to another post and I have some trouble (still with the categories), maybe you can help for that too. Here’s what I have so far (in my functions.php) :

    
    function linkarticles($atts) {
    
      $thepostid = intval($atts[id]);
      $output = '';
      $post = get_post($thepostid);
      
    
      function categories_li(){
        $cats = get_the_category($post->ID);
        foreach ( $cats as $cat ) {
          echo "<ul class='post-categories'><li>{$cat->name}</li></ul>";
        };
      }
    
      if ($post) :
        $output .= '<article class="articles_miniatures"> <div class="vignettes_articles"> <a class="filtres filtre_bleu" href="' . get_the_permalink($post->ID) . '"> </a> <a class="img_intro" href="' . get_the_permalink($post->ID) . '"> <div class="img_wrap">' . get_the_post_thumbnail($post->ID, 'post-thumbnail', ['class' => 'img-responsive']) . '</div></a> <a class="texte_vignettes" href="'. get_the_permalink($post->ID) . '"> <p class="lire_article">lire l\'article</p> <p class="plus">+</p> </a>' . categories_li() . '</div><div class="centrage"> <h2 class="titre_bleu">' . get_the_title($post->ID) . '</h2> </div>'. get_wp_term_image() .' </article>';
    
      else :
      // failed, output nothing
      endif;
      return $output;
    }
    add_shortcode('include_post', 'linkarticles');

    As a result I don’t have the categories for the post ID, but for the post I’m writting and it’s not placed at the right place in the html. Any advice ?
    Sorry if I’m a pain, I only studied php for 5 days, still in the process of learning!!

    Thread Starter soph87

    (@soph87)

    I already tried to use get_the_category(), but all I managed to do is store the array in a variable, I don’t know how to then display it in a list.

Viewing 3 replies - 1 through 3 (of 3 total)