Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9772

    Hi guys,

    Great theme but I have a question with regards to the Related work part of the template. I saw a similar request to add tag support for the theme and have the related posts order by tags instead of categories. As I want the related work to be from other categories, not necessarily the same category or sub category from the current piece of work.

    The other topic said to do the following:

    2) you can try to add tags support for portfolio items open up angularincludesadminregister-portfolio.php and replace:

    'show_in_nav_menus'=> false,

    with:

    'show_in_nav_menus'=> false,
    'taxonomies'=> array('post_tag'),

    Then open up includes/related-portfolio-posts.php and replace:

    $tags = wp_get_object_terms( $post->ID, 'portfolio_entries');

    with

    $tags = wp_get_post_tags( $post->ID, 'portfolio_entries');

    now you should be able to use tags instead of categories which is a more versatile solution imho.

    I did this, exactly as is however the related posts doesn’t appear at all now. I did a print_r of $tag_ids and the tags are being grabbed and the tags are exactly the same as within another project. I’m testing both projects in the same category and projects in another category.

    Yet there is still nothing appearing at all.

    I was wondering if you could please take a look at this for me, this is my first and last issue :)

    You can test this on our site here:

    Click Me

    Thanks

    Scott

    #65796

    Not sure if you’ll need it but this is my related-portfolio-posts.php file currently:

    <?php

    /**
    * These functions shows a number of posts related to the currently displayed post.
    * Relations are defined by tags: if post tags match, the post will be displayed as related
    */

    $columns = 4;
    $reladed_posts = false;
    $this_id = $post->ID;
    $slidecount = 0;
    $postcount = ($columns * 1);
    $single_class = "one_fourth";

    // $tags = wp_get_object_terms( $post->ID, 'portfolio_entries');

    $tags = wp_get_post_tags( $post->ID, 'portfolio_entries');

    if ($tags) {

    $tag_ids = "";
    foreach ($tags as $tag ) $tag_ids .= $tag->slug.",";

    $tag_ids = substr_replace($tag_ids ,"",-1);
    $tag_ids = str_replace(" ", "-",$tag_ids);

    if($tag_ids)
    {
    $my_query = new WP_Query(array('portfolio_entries'=>$tag_ids, 'showposts'=>$postcount, 'ignore_sticky_posts'=>1, 'orderby'=>'rand', 'post__not_in' => array( $this_id ) ) );

    if ($my_query->have_posts())
    {
    $count = 1;
    $output = "";

    $output .= avia_advanced_hr(__('Related Entries','avia_framework'));
    $output .= "<div class ='twelve units related-portfolio'>";
    $output .= "<div class='content_slider autoslide_false'>";

    while ($my_query->have_posts()) : $my_query->the_post();
    if($post->ID != $this_id)
    {
    $reladed_posts = true;
    $slidecount ++;

    if($count == 1)
    {
    $output .= "<div class='single_slide single_slide_nr_$slidecount'>";
    }

    $image = "<span class='related_posts_default_image'>{image}</span>";
    $slides = avia_post_meta(get_the_ID(), 'slideshow', true);

    //check if a preview image is set
    if( $slides != "" && !empty( $slides[0]['slideshow_image']) )
    {
    //check for image or video
    if(is_numeric($slides[0]['slideshow_image']))
    {
    $invisible_image = $image = avia_image_by_id($slides[0]['slideshow_image'], 'portfolio', 'image');
    }
    else
    {
    $invisible_image = $image = "<span class='related_posts_default_image related_posts_video'></span>";
    }
    }

    $output .= "<div class='$single_class relThumb relThumb".$count."'>n";
    $output .= "<a href='".get_permalink()."' class='relThumWrap noLightbox'>n";
    $output .= "<span class='related_image_wrap'>";
    $output .= $image;
    $output .= "</span>n";
    $output .= "<span class='relThumbTitle'>n";
    $output .= "<strong class='relThumbHeading'>".avia_backend_truncate(get_the_title(), 50)."</strong>n";
    $output .= "</span>n</a>";
    $output .= "</div><!-- end .relThumb -->n";

    $count++;

    if($count == $columns+1)
    {
    $output .= "</div>";
    $count = 1;
    }
    }
    endwhile;

    if($count != 1) $output .= "</div>";

    $output .= "</div></div>";
    $output = str_replace("{image}",$invisible_image,$output);

    if($reladed_posts) echo $output;

    }

    wp_reset_query();
    }
    }

    Thanks in advance,

    Scott

    #65797

    If this falls outside the scope of your support then please let me know. I just thought that being as you had attempted to answer correctly before then perhaps you would be able to help?

    I’m happy to pay for extended support if required.

    Best Regards,

    Scott

    #65798

    Hey,

    obviously I misunderstood the output of wp_get_post_tags.

    You need to replace:

    $tags = wp_get_object_terms( $post->ID, 'portfolio_entries');

    if ($tags) {

    $tag_ids = "";
    foreach ($tags as $tag ) $tag_ids .= $tag->slug.",";

    $tag_ids = substr_replace($tag_ids ,"",-1);
    $tag_ids = str_replace(" ", "-",$tag_ids);

    if($tag_ids)
    {
    $my_query = new WP_Query(array('portfolio_entries'=>$tag_ids, 'showposts'=>$postcount, 'ignore_sticky_posts'=>1, 'orderby'=>'rand', 'post__not_in' => array( $this_id ) ) );

    with:

    $tags = wp_get_post_tags( $post->ID, 'portfolio_entries');
    $tag_ids = '';

    foreach ($tags as $tag){
    $tag_ids .= $tag->term_id;
    }

    if ($tags) {

    if($tag_ids)
    {
    $my_query = new WP_Query(array('post_type'=>'portfolio', 'tag__in' => $tag_ids, 'showposts'=>$postcount, 'ignore_sticky_posts'=>1, 'orderby'=>'rand', 'post__not_in' => array( $this_id ) ) );

    #65799

    Great thanks a bunch.

    Just a slight adjustment for anyone who views this in the future.

    $tag_ids .= $tag->term_id;

    should be something like

    $tag_ids .= $tag->term_id.", ";

    as tag__in needs comma delimitated arrays :/ Works now :) thanks

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Related Work As Tags Not Categories’ is closed to new replies.