• I am interested in making a list of all pages on my site, except for child pages and parent pages, if the parent has 2 or more children.

    I was considering looping through children of a given parent, and if there wasn’t anything in that set I would display the parent?

    [loop type="page" clean="true" list="true" exclude="children"]
      [-loop parent="this" orderby="title" clean="true" list="true"]
        [if empty]
          // do something?
        [/if]
      [/-loop]
    [/loop]

    https://ww.wp.xz.cn/plugins/custom-content-shortcode/

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

    (@miyarakira)

    This part is tricky:

    ..except for child pages and parent pages, if the parent has 2 or more children

    Something that might help is the [pass] shortcode, which you can use to pass the ID of the current post in the loop.

    [loop ..]
      [pass field=id]
        [-loop ..]
          [if empty]
            [--loop type=page id={FIELD}]
              ..
            [/--loop]
          [/if]
        [/-loop]
      [/pass]
    [/loop]

    That looks pretty wild, so I’m not sure if it’s possible to do this with shortcodes.

    Thread Starter mockingbirdAlex

    (@mockingbirdalex)

    Thank you for the response. I think I aimed a little too high making something fancy when it didn’t need to be so I’ll just keep children in my list.

    Thread Starter mockingbirdAlex

    (@mockingbirdalex)

    I actually have a follow-up question. I’m currently displaying all my pages with two nested loops as follows:


    [loop type=”page” clean=”true” list=”true” exclude=”children”]
    [field title-link]
    [-loop parent=”this” clean=”true” list=”true”]
    [field title-link]
    [/-loop]
    [/loop]

    However, this creates whitespace between each bullet point. It appears the space occurs because I am entering the second loop on every bullet point, even if there are no children. Is there a way to check if a given page is a parent before going into the loop, or remove this whitespace another way?

    Plugin Author Eliot Akira

    (@miyarakira)

    Hi mockingbirdAlex,

    this creates whitespace between each bullet point

    This sounds like an issue with the post content being automatically formatted. You can avoid it by using [raw] shortcode (must be enabled in settings):

    [raw]
      ..the whole code block..
    [/raw]

    ..or by putting the code in one line where you don’t want any line breaks:

    [loop type="page" clean="true" list="true" exclude="children"][field title-link][-loop parent="this" clean="true" list="true"][field title-link][/-loop][/loop]
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Display all posts except parents’ is closed to new replies.