Sign in

How to know if there are no posts using getPostsByTags? (*SIGH* Again.)

  • This topic has 4 replies, 2 voices, and was last updated 3 months, 2 weeks ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #7372
    publii-slpa

    I need to know if there are any posts so that I can insert other html. For example, if I have vacancies (using posts with the tag vacancy) I will simply iterate through the posts – no big deal there. However if there are no posts found by tag vacancy, then I want to insert a blurb that there are no vacancies at this point.

    I noticed that if no posts are found using getPostsByTags the entire block is skipped. There is no logic I can use in this case within the block. Is there an other way to know?

    Is there a way to test if the getPostsByTags helper returns true or false? Maybe I could use a pre-test before calling getPostsByTags again.

    I tried @index == ‘0’ (zero) and found that within a getPostsByTags block where there are posts found, this would indicate the first post. I might be able to use this to answer the question below. I did find that once the getPostsByTags block has iterated through all of the posts level is undefined.

    As well, before I iterate through the posts, I need to insert some divs to setup the structure. I see unless level used in other places such as in a menu, can I use unless level within a getPostsByTags block?

    It would be nice if you could document level as used within unless and I assume checkif.

    Mean while I am still looking for a solution.

    Cheers!!

    #7373
    publii-slpa

    Part one of my question may be answered with

    {{#checkIf (getPostsByTags (concatenate "count=999&tag_as=slug&tags=vacancy&excluded=0&offset=0&orderby=modifiedAt&ordering=asc")) '==' false}}

    exploring further.

    Can someone solidify “level” for me?

    Cheers!!

    #7374
    publii-slpa

    Ok. SIGH.

    {{#checkIf (getPostsByTags (concatenate "count=999&tag_as=slug&tags=vacancy&excluded=0&offset=0&orderby=modifiedAt&ordering=asc")) '==' false}}

    …does indeed allow me to determine if the statement is true or not and insert “no vacancies” into the page.

    However, I cannot access the posts within the checkif or even run another getPostsByTags block.

    An eval helper would be nice.

    Any ideas?

    #7375
    thumb
    #7377
    publii-slpa

    Dear Thumb-

    I was hoping for a slicker way… [cheese eating grin]

    I did see this some time ago and I have forgotten all about it – completely.

    Thanks(!!) for the reminder.

    I am rather old fashioned anyway, perhaps I should stop banging my head on the wall and adopt a more natural way of coding this. The problem is, the stubbornness I have inherited from both sides of the family makes me dig my heals in like a mule. Perhaps I should learn to put this in check.

    I want to “Thank You” again for the reminder. This will have to be the solution – it just makes too much sense not to be.

    Cheers!!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.