• Resolved philipt18

    (@philipt18)


    So I’m trying to create some index pages of the resources on my site. It mostly for being able to do some sanity checking, and I’m not planning on exposing these pages to the general public. In any case, I idea is that they list all of the pages that have the same source, where the source is a specific web site, such as Wikipedia. I’ve tried to structure it so I can include the same text file on each page, and it will simply grab the source from the title of the index page. I thus don’t need to change the code for each index page. This is what I have:

    <table>
    [pass field=title]
    [loop type=page parent=213024 include=children field=type value=resource,dependency field_2=source value_2={Field}]
    <tr><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    [/pass]
    </table>

    Except I get nothing. I also tried simplifying it as:

    <table>
    [pass field=title]
    [loop type=page parent=213024 include=children field=source value={FIELD}]
    <tr><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    [/pass]
    </table>

    But it still returns nothing. By the way, which should be quicker? The first query or the second?

    In any case, what is wrong with this? Why isn’t it returning a list of all pages with the source that matches the title? I also tried hardcoding the source and it didn’t help, i.e.:

    <table>
    [loop type=page parent=213024 include=children field=source value="Wikipedia"]
    <tr><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    </table>

    I tried the above with and without quotes. Neither worked, but which is right?

    In any case, any ideas why this isn’t working?

    Thanks.

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

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

    (@miyarakira)

    By the way, which should be quicker? The first query or the second?

    I would say the second query is quicker, since it checks only 1 field.

    To see why the query is not finding the posts, can you see what is the value of the field source?

    [loop type=page parent=213024 include=children]
    [field title-link] - [field source]
    [if field=source value=Wikipedia] is [else] is NOT [/if]Wikipedia<br>
    [/loop]
    Thread Starter philipt18

    (@philipt18)

    That output somereally strange stuff like:

    Bahrain -
    is Wikipedia
    [/loop][/if]
    Bangladesh -
    is NOT Wikipedia
    is NOT Wikipedia
    [/loop][/if]
    Belarus -
    is NOT Wikipedia

    The structure is that there is the main page (213024) and its children are topics (Countries) and those topics have children which are Resources and could have the source field set to Wikipedia. And yes, I had the editor in text mode.

    Thread Starter philipt18

    (@philipt18)

    I’m not sure what was happening above but I’ve gotten this to work, mostly. This is my current code:

    <table>
    <tr><th>#</th><th>Topic</th><th>Resource</th></tr>
    [loop type=page parent=213024 include=children field=source value=Wikipedia]
    [calc]total = total + 1[/calc]
    <tr><td>[calc]total[/calc]</td><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    </table>

    The only thing that is wrong is that the total is not being displayed in the left column. I think I can do this a different way without the math module, using loop-count, but I’m just trying to understand why this isn’t displaying the number. Thanks.

    Thread Starter philipt18

    (@philipt18)

    Just to be clear I do:

    [set total]0[/set]

    earlier in the code.

    Thread Starter philipt18

    (@philipt18)

    Ok, so I’ve gotten this to work with loop-count as follows:

    [pass fields=id,title]
    [cache name=index-{ID} expire='1 day' update=true]
    <div id=zebra>
    <table>
    <tr><th>#</th><th>Topic</th><th>Resource</th></tr>
    [loop type=page parent=213024 include=children field=source value=Wikipedia orderby=field key=topic]
    <tr><td>[loop-count]</td><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    </table>
    </div>
    [/cache]
    [/pass]

    Note that I pass two fields at the beginning. The first field is used in the [cache] and I tried to use the second field in the loop to define the source (which I grab from the title). So above I replace Wikipedia with {Title}. However, that gets no results. Next I’ll try a separate [pass] around that loop, but I was wondering why/if that was necessary.

    Thread Starter philipt18

    (@philipt18)

    So this did actually work:

    [pass field=id]
    [cache name=index-{FIELD} expire='1 day' update=true]
    <div id=zebra>
    <table>
    <tr><th>#</th><th>Topic</th><th>Resource</th></tr>
    [-pass field=title]
    [loop type=page parent=213024 include=children field=source value={-FIELD} orderby=field key=topic]
    <tr><td>[loop-count]</td><td>[field topic]</td><td>[field title-link]</td></tr>
    [/loop]
    [/-pass]
    </table>
    </div>
    [/cache]
    [/pass]

    I’m still not sure why the previous code didn’t work though. It would seem easier to be able to pull in fields at the beginning and pass them to each thing separately than need to do two separate pass statements.

    Thread Starter philipt18

    (@philipt18)

    I thought the code was working, but I then I realized it only worked sometimes. If the Title/Source is a single word, the code works.

    If the Title/Source has multiple words, it doesn’t work, with an odd caveat. If there is is a single-word Title/Source with the same first word as the multi-word source, when displaying the multi-word index, it actually displays the index for the single word Title/Source that shares the same first word. It’s as if only the first word of the Title is getting passed to the loop.

    I’m thinking maybe about using the slug, but I’m matching against a field that is not sluggified, which means I’d have to deslug the field, which even though you do have a deslug tag, I’m not sure I could do between a pass and a loop.

    Any idea why only the first word of the Title is getting passed? Thanks.

    Thread Starter philipt18

    (@philipt18)

    Any idea why the only the first word of the Title is getting passed? This is very frustrating.

    Thread Starter philipt18

    (@philipt18)

    So I think I figured this out, for the most part. I simply wrapped the {-FIELD} in quotes. For some reason one of my index pages isn’t displaying any results, but for the moment I’m going to assume it’s a different problem since the rest of the pages are working normally.

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

The topic ‘Creating index pages’ is closed to new replies.