• Eliran

    (@bstyler)


    Hi there,

    This is currently my code:

    [loop type="post" category="news" tag="apples, green" count="3"]
    <h3 class="title title-small">[field title-link]</h3>
    [field image-link size="vw_small"]
    [/loop]

    However, I’m looking to show 3 related posts that share any of the tags or categories of the current post.

    So far, I didn’t found out how I can get a list of tags/categories of the current post. Is that possible by code or I must manually type down the categories and tags that I want to loop?

    Many thanks!

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    Recently I added a shortcode to display posts related by category or tags:

    [related taxonomy="category" count="3"]
      [field title-link]..
    [/related]

    It excludes the current post automatically. The shortcode is documented at the bottom of the “For/Each” section. In the same page, you can see examples of listing the current post’s category or tags also.

    At this point, it’s only possible to show related posts by category or tags, but it’s a good idea to be able to use both like:

    [related taxonomy="category, tag"]

    I’ll make a note to include this in a future update.

    Thread Starter Eliran

    (@bstyler)

    Thanks a lot for the response and for consideration my suggestion for a future update.

    Can you please update me once that feature is being introduced?
    I hope that’s not much of a hassle,

    Many thanks, both for this and for your great plugin!

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I included your suggestion in the latest update. It’s now possible to get posts related by multiple taxonomies:

    [related taxonomy="category,tag" count="3"]
      [field title-link]..
    [/related]

    This should show 3 related posts that share any of the tags or categories of the current post.

    Julie

    (@habannah)

    Thanks so much for adding this functionality, Eliot!

    Thread Starter Eliran

    (@bstyler)

    Many thanks Eliot,

    Quick question before I mark this case as solved:

    Can I also mention specific categories and tags to show?

    For example:

    [related category="apple" tag="orange" count="3"]
      [field title-link]
    [/related]

    Thanks a lot for the update!

    Plugin Author Eliot Akira

    (@miyarakira)

    At this point, it’s not possible to specify taxonomy terms for related posts. I’m looking in the code, but it doesn’t seem to fit with the current algorithm (get taxonomy terms from current post, then query for them).

    Hmm..there are a couple different ways you might achieve this.

    Using [loop], you can query multiple taxonomies by specific terms, and exclude the current post. However, this goes back to your original question, which is to manually type each term.

    [loop type="post" category="apple" tag="orange" exclude="this" count="3"]

    ..or..you could filter the [related] loop conditionally:

    [related taxonomy="category, tag" count="3"]
      [if category="apple"]
         [field title-link]
      [/if]
    [/related]

    ..but the [if] shortcode doesn’t yet provide querying by multiple taxonomies.

    Woo, this is a tough one. I’ll update this thread if I figure out a good way to solve it.

    Thread Starter Eliran

    (@bstyler)

    Thanks a lot Eliot.

    Your plugin is outstanding!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to automatically list related posts that share tags with the current post.’ is closed to new replies.