List Documents of articles inside a given Section or with a Keyword

Dear all

I have another question:

Can I create a boucle to list out all Documents belong to articles of a given section?

Say, given rubrique=3, I would like to display the latest 50 documents attached to articles of this rubrique.

using this loop below, would give me documents of ALL articles accross the site, which I want to narrow down to a given section.

<BOUCLE_doc(DOCUMENTS){mode=image}{extension==jpg|png|gif}{par date}{inverse}{0,50}>
    ...
</BOUCLE_doc>

Also, instead of rubrique, what about keyword? Say I want to list out the latest 50 documents attached to those articles with mot=5 ??

Thanks in advance :slight_smile:

Vinc.

Hi,

you can use {doublons} to store the elements given by a first loop, and loop over them in a second one.

ex.
[(#REM) ]
<BOUCLE_store(ARTICLES){id_section}>
<BOUCLE_doc_art(DOCUMENTS){id_articles}{mode=image}{extension==jpg|png|gif}{doublons A}> </BOUCLE_doc_art>
</BOUCLE_store>

[(#REM) ]
<BOUCLE_doc(DOCUMENTS){! doublons A}{par date}{inverse}{0,50}>

</BOUCLE_doc>

But the problem of this method is that the first step looks for documents in all your articles. This is time consuming

So you can use a JOIN between spip_documents and spip_articles. The performance is better.

Sorry, this is a really poor documented feature (even in french) that appears with SPIP1.9 :
http://www.spip.net/en_article3416.html (chap. « automatic detection of tables SQL and joints »)

<BOUCLE_doc(DOCUMENTS articles){id_secteur}{mode=image}{extension==jpg|png|gif}{par date}{inverse}{0,50}>

</BOUCLE_doc>

{id_secteur} isn’t a criteria for DOCUMENTS loops, but spip automatically finds that some articles are related to documents, and use this criteria for the articles.
Normally, the other cirteria should be applied to documents

Note that you can use « DOCUMENTS » and « articles » because the are standard tables (you can use SPIP_DOCUMENTS ad spip_articles if you want, but it’s not necessary)

Hope it helps,

.Gilles

On Sat, Jan 10, 2009 at 3:30 PM, TN Media <info@tnmedia.net> wrote:

Dear all

I have another question:

Can I create a boucle to list out all Documents belong to articles of a given section?

Say, given rubrique=3, I would like to display the latest 50 documents attached to articles of this rubrique.

using this loop below, would give me documents of ALL articles accross the site, which I want to narrow down to a given section.

<BOUCLE_doc(DOCUMENTS){mode=image}{extension==jpg|png|gif}{par date}{inverse}{0,50}>

</BOUCLE_doc>

Also, instead of rubrique, what about keyword? Say I want to list out the latest 50 documents attached to those articles with mot=5 ??

Thanks in advance :slight_smile:

Vinc.


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Hi Gilles

Thanks for your help

The first approach:

[(#REM) ]
<BOUCLE_store(ARTICLES){id_section}>
<BOUCLE_doc_art(DOCUMENTS){id_articles}{mode=image}{extension==jpg|png|gif}{doublons A}> </BOUCLE_doc_art>
</BOUCLE_store>

[(#REM) ]
<BOUCLE_doc(DOCUMENTS){! doublons A}{par date}{inverse}{0,50}>

</BOUCLE_doc>

It works, but the return the page took a while (about 20+ seconds) to compile because I have a couple of hundred articles in the given section??? Is there a better loop to make it faster?

For the second approach, using multiple table in a loop, it return error as follow:

  • Error(s) in template

  • ُError in the site, loop unknown criterion id_rubrique

  • MySQL error
    documents.id_document FROM spip_documents AS documents WHERE (id_rubrique = ‹ 3 ›) AND (documents.mode = ‹ vignette ›) AND ((documents.id_document IN (0))) AND (documents.taille > 0 OR documents.distant=« oui ») ORDER BY documents.date DESC LIMIT 0,50
    Unknown column ‹ id_rubrique › in ‹ where clause ›``

This is my loop:

<BOUCLE_doc(DOCUMENTS articles){id_rubrique=3}{mode=image}{par date}{inverse}{! doublons art}{0,50}>
[(#EMBED_DOCUMENT||image_reduire{100,100})]
</BOUCLE_doc>

By looking at the error above, it seems like the « articles » table does not pass through. MySQL code only look inside spip_documents table and therefore it could not find column id_rubrique (non exist in spip_documents)

What did I do wrong???

Thanks

Vinc.

Gilles VINCENT wrote:

On Sun, Jan 11, 2009 at 9:43 AM, TN Media <info@tnmedia.net> wrote:

Hi Gilles

Thanks for your help

The first approach:

[(#REM) ]
<BOUCLE_store(ARTICLES){id_section}>
<BOUCLE_doc_art(DOCUMENTS){id_articles}{mode=image}{extension==jpg|png|gif}{doublons A}> </BOUCLE_doc_art>
</BOUCLE_store>

[(#REM) ]
<BOUCLE_doc(DOCUMENTS){! doublons A}{par date}{inverse}{0,50}>

</BOUCLE_doc>

It works, but the return the page took a while (about 20+ seconds) to compile because I have a couple of hundred articles in the given section??? Is there a better loop to make it faster?

Yes, it’s because the loop search for documents in all yours articles, so it’s a wrong method.
But in fact, it’s the same than the second one (that does the same thing, but faster) :

<BOUCLE_doc(DOCUMENTS documents_articles articles){id_rubrique=3}{mode=image}{par date}{inverse}{0,50}>

  • #ID_ARTICLE / #ID_RUBRIQUE: [(#EMBED_DOCUMENT||image_reduire{100,100})]
  • (in fact I didn’t test the previous suggestion)

    This loop uses spip_documents_articles as a joint table between spip_documents and spip_articles.

    {id_rubrique} is a criteria for the latest table, the other ones are for the first table.

    The generated query (use var_profile in your url to see it) is :
    SELECT documents.id_document, L1.id_article, L2.id_rubrique FROM adic.spip_documents_articles AS L1, adic.spip_articles AS L2, adic.spip_documents AS documents WHERE (L2.id_rubrique = ‹ 31 ›) AND (documents.mode = ‹ vignette ›) AND ((documents.id_document NOT IN (1))) AND (documents.taille > 0 OR documents.distant=« oui ») AND L1.id_article=L2.id_article AND documents.id_document=L1.id_document GROUP BY documents.id_document ORDER BY documents.date DESC LIMIT 0,50

    Exactly what you want !

    .Gilles

    For the second approach, using multiple table in a loop, it return error as follow:

    • Error(s) in template

    • ُError in the site, loop unknown criterion id_rubrique

    • <BOUCLE_doc>(documents)
      MySQL error
      documents.id_document FROM spip_documents AS documents WHERE (id_rubrique = ‹ 3 ›) AND (documents.mode = ‹ vignette ›) AND ((documents.id_document IN (0))) AND (documents.taille > 0 OR documents.distant=« oui ») ORDER BY documents.date DESC LIMIT 0,50
      Unknown column ‹ id_rubrique › in ‹ where clause ›``
      </BOUCLE_doc>
      This is my loop:

    <BOUCLE_doc(DOCUMENTS articles){id_rubrique=3}{mode=image}{par date}{inverse}{! doublons art}{0,50}>
    [(#EMBED_DOCUMENT||image_reduire{100,100})]
    </BOUCLE_doc>

    By looking at the error above, it seems like the « articles » table does not pass through. MySQL code only look inside spip_documents table and therefore it could not find column id_rubrique (non exist in spip_documents)

    What did I do wrong???

    Thanks

    Vinc.

    Gilles VINCENT wrote:

    Hi,

    you can use {doublons} to store the elements given by a first loop, and loop over them in a second one.

    ex.
    [(#REM) ]
    <BOUCLE_store(ARTICLES){id_section}>
    <BOUCLE_doc_art(DOCUMENTS){id_articles}{mode=image}{extension==jpg|png|gif}{doublons A}> </BOUCLE_doc_art>
    </BOUCLE_store>

    [(#REM) ]
    <BOUCLE_doc(DOCUMENTS){! doublons A}{par date}{inverse}{0,50}>

    </BOUCLE_doc>

    But the problem of this method is that the first step looks for documents in all your articles. This is time consuming

    So you can use a JOIN between spip_documents and spip_articles. The performance is better.

    Sorry, this is a really poor documented feature (even in french) that appears with SPIP1.9 :
    http://www.spip.net/en_article3416.html (chap. « automatic detection of tables SQL and joints »)

    <BOUCLE_doc(DOCUMENTS articles){id_secteur}{mode=image}{extension==jpg|png|gif}{par date}{inverse}{0,50}>

    </BOUCLE_doc>

    {id_secteur} isn’t a criteria for DOCUMENTS loops, but spip automatically finds that some articles are related to documents, and use this criteria for the articles.
    Normally, the other cirteria should be applied to documents

    Note that you can use « DOCUMENTS » and « articles » because the are standard tables (you can use SPIP_DOCUMENTS ad spip_articles if you want, but it’s not necessary)

    Hope it helps,

    .Gilles

    On Sat, Jan 10, 2009 at 3:30 PM, TN Media <info@tnmedia.net> wrote:

    Dear all

    I have another question:

    Can I create a boucle to list out all Documents belong to articles of a given section?

    Say, given rubrique=3, I would like to display the latest 50 documents attached to articles of this rubrique.

    using this loop below, would give me documents of ALL articles accross the site, which I want to narrow down to a given section.

    <BOUCLE_doc(DOCUMENTS){mode=image}{extension==jpg|png|gif}{par date}{inverse}{0,50}>

    </BOUCLE_doc>

    Also, instead of rubrique, what about keyword? Say I want to list out the latest 50 documents attached to those articles with mot=5 ??

    Thanks in advance :slight_smile:

    Vinc.


    spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

    
    ---
    
    _______________________________________________
    [spip-en@rezo.net](mailto:spip-en@rezo.net) - [http://listes.rezo.net/mailman/listinfo/spip-en](http://listes.rezo.net/mailman/listinfo/spip-en)
      
    
    

    Hi Gilles

    Thanks for your help

    The first approach:

    [(#REM) ]
    <BOUCLE_store(ARTICLES){id_section}>
    <BOUCLE_doc_art(DOCUMENTS){id_articles}{mode=image}{extension==jpg|png|gif}{doublons A}> </BOUCLE_doc_art>
    </BOUCLE_store>

    [(#REM) ]
    <BOUCLE_doc(DOCUMENTS){! doublons A}{par date}{inverse}{0,50}>

    </BOUCLE_doc>

    It works, but the return the page took a while (about 20+ seconds) to compile because I have a couple of hundred articles in the given section??? Is there a better loop to make it faster?

    For the second approach, using multiple table in a loop, it return error as follow:

    • Error(s) in template

    • ُError in the site, loop unknown criterion id_rubrique

    • MySQL error
      documents.id_document FROM spip_documents AS documents WHERE (id_rubrique = ‹ 3 ›) AND (documents.mode = ‹ vignette ›) AND ((documents.id_document IN (0))) AND (documents.taille > 0 OR documents.distant=« oui ») ORDER BY documents.date DESC LIMIT 0,50
      Unknown column ‹ id_rubrique › in ‹ where clause ›``

    This is my loop:

    <BOUCLE_doc(DOCUMENTS articles){id_rubrique=3}{mode=image}{par date}{inverse}{! doublons art}{0,50}>
    [(#EMBED_DOCUMENT||image_reduire{100,100})]
    </BOUCLE_doc>

    By looking at the error above, it seems like the « articles » table does not pass through. MySQL code only look inside spip_documents table and therefore it could not find column id_rubrique (non exist in spip_documents)

    What did I do wrong???

    Thanks

    Vinc.

    Gilles VINCENT wrote: