ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Query Help

June 29, 2010 5:48pm

Subscribe [4]
  • #1 / Jun 29, 2010 5:48pm

    msfarrel

    33 posts

    Not sure how to do this. I need to select the last 4 entry ids posted in category id 149. Then I need to exclude these 4 entry ids from another weblog tag pair on the page. Would the query module be the best solution for this? If so what would the query look like? I can select the last 4 entry_ids from exp_weblog_titles but I’m not sure how to add the category part. Thanks in advanced…

  • #2 / Jun 29, 2010 6:35pm

    lebisol

    2234 posts

    Weblog has parameters to help you get this.You can pick out Entry IDs as well as specific Category IDs...

  • #3 / Jun 30, 2010 12:28am

    msfarrel

    33 posts

    Right, but you have to hard code the entry ids. Let me explain better.

    I have two weblog tags on the home page. The first one displays the last 4 posts in any of the three weblogs that have the category “featured”.

    {exp:entries:weblog weblog="articles|gallery|videos" category="149" sort="desc"  limit="4"}
    featured content
    {/exp:entries:weblog}

    The second weblog tag displays all the posts from the three different weblogs.

    {exp:entries:weblog weblog="articles|gallery|videos" sort="desc" limit="20"}
    seconday content
    {/exp:entries:weblog}

    I want to grab the 4 entry ids from the featured section so they aren’t duplicated in the second weblog. The entry id parameter doesn’t work because I would have to update the template with the excluded entry id every time a new post is featured. The offset parameter doesn’t work because not every post is featured so offseting by 4 wouldn’t work. And excluding the entire category wouldn’t work because when a post is no longer the last 4 in the feature category it wouldn’t appear in the section below. Does that make sense?

    I thought maybe by doing a query to grab the entry ids and an embed this could be accomplished

    {embed="secondary_weblog" entryids="query that grabs the 4 entry ids"}

    embeded template:

    {exp:entries:weblog weblog="articles|gallery|videos" entry_id="not {embed:entryids}" limit="20"}
    seconday content
    {/exp:entries:weblog}

    But I’m not sure that would work and if it would I’m not sure what the query would be.

  • #4 / Jun 30, 2010 2:57am

    Wouter Vervloet

    758 posts

    Hi msfarrel,

    You’re not far off with your embedded template:

    // Main template
    {exp:weblog:entries weblog="articles|gallery|videos" entry_id="not {embed='embeds/entryids'}" limit="20"}
    seconday content
    {/exp:weblog:entries}
    // Embedded template (entryids)
    {exp:weblog:entries weblog='secondary_weblog' limit='4' dynamic='off' category='149'}{entry_id}|{/exp:weblog:entries}

    That should work.

    Greetz,
    Wouter

  • #5 / Jun 30, 2010 12:14pm

    msfarrel

    33 posts

    Hi Wouter,

    Thanks for the reply. I’ve been trying to get your example to work however I think it’s misssing something. How do you get the entry id’s from the embedded template into the main template? You used {embed:entryids} but where is entryids being defined?

    Thanks again,
    Mike

  • #6 / Jun 30, 2010 2:40pm

    Wouter Vervloet

    758 posts

    Hi Wouter,

    Thanks for the reply. I’ve been trying to get your example to work however I think it’s misssing something. How do you get the entry id’s from the embedded template into the main template? You used {embed:entryids} but where is entryids being defined?

    Thanks again,
    Mike

    My bad… I copied most of your code and forgot to change the following:

    {embed:entryids}

    to:

    {embed='embeds/entryids'}

    You would create a template called entryids in the template group embeds (or whatever you prefer).

    Greetz,
    Wouter

  • #7 / Jun 30, 2010 2:54pm

    lebisol

    2234 posts

    Sorry I fell of this thread…and skimmed through it.
    Maybe I am missing something but how does embedding entry IDs solve the issue of having to hand pick them?
    Isn’t this:

    entry_id="not {embed='embeds/entryids'}"

    the same as hard coding them?

    entry_id="not 149"

    Since “featured” trigger is nothing more than fact that entry belongs to categoryID=149 why can’t it be hardcoded?

  • #8 / Jun 30, 2010 3:05pm

    Wouter Vervloet

    758 posts

    Sorry I fell of this thread…and skimmed through it.
    Maybe I am missing something but how does embedding entry IDs solve the issue of having to hand pick them?
    Isn’t this:

    entry_id="not {embed='embeds/entryids'}"

    the same as hard coding them?

    entry_id="not 149"

    Since “featured” trigger is nothing more than fact that entry belongs to categoryID=149 why can’t it be hardcoded?

    He will need show some entries in that category (149), just not the newest 4. That embedded template will return a string of entry id’s containing the last 4 entry id’s (for example: “54|49|46|41|”).

    Greetz,
    Wouter

  • #9 / Jun 30, 2010 3:41pm

    lebisol

    2234 posts

    Oh I just re-read

    I want to grab the 4 entry ids from the featured section so they aren’t duplicated in the second weblog.

    So I guess he needed a ‘subquery’ so to say.

  • #10 / Jun 30, 2010 11:01pm

    msfarrel

    33 posts

    Wouter,

    That’s what I assumed you meant the first time and when I gave it a try it outputed as if the exluded entry ids were ignored. I just went back and tried again and the same thing. When I place the embed outside the weblog tags it outputs the 4 entry ids like 94|93|92|50|. When I place the embed inside the entry id parameter its ignored for some reason.

    My weblog tag looks like this:

    {exp:weblog:entries weblog="articles|videos|gallery"  limit="10" dynamic="off" entry_id="not {embed='includes/featured_entryids'}"}

    However in template debug mode its displaying:

    Tag: {exp:weblog:entries weblog="articles|videos|gallery" limit="10" dynamic="off" entry_id="not {embed='includes/featured_entryids'}</code></pre>
    
    The closing welbog tags are being left out
    <pre><code>"}

    and the embed is not being parsed.

    Any idea why this doesn’t work? I’m stumped. Thanks man…

  • #11 / Jul 01, 2010 4:07am

    Studio Meta

    105 posts

    You may use PHP in your template to achieve this :

    First weblog :

    <?php $arr = array(); ?>
    
    {exp:entries:weblog weblog="articles|gallery|videos" category="149" sort="desc"  limit="4"}
    // Build an array of the 4 featured ids
    <?php $arr[] = "{entry_id}"; ?>
    {/exp:weblog:entries}
    
    // Then displays the others
    {exp:weblog:entries weblog="articles|videos|gallery"  limit="10" dynamic="off" entry_id="not <?php echo implode("|", $arr); ?>"}
    <h2>{title}</h2>
    <p>{/exp:weblog:entries}

    This should work.

    By the way, for skipping entries, you may also use the offset parameter.

  • #12 / Jul 01, 2010 11:26am

    msfarrel

    33 posts

    Studio Meta,

    Thanks for the reply. Your solution gave me the same results… the entry ids are ignored. It seems that with both solutions the entry id variables are not processed in time for the weblog to use them?

    Mike

  • #13 / Jul 01, 2010 11:37am

    Studio Meta

    105 posts

    Have you tried to change the order of PHP processing in the templates manager (ie: input/output) ?

  • #14 / Jul 01, 2010 11:40am

    msfarrel

    33 posts

    Yeah I tried both input/output. One returned the entry id numbers and the other returned the actual {entry_id} tag. So I made sure I was using the right parsing stage.

  • #15 / Jul 01, 2010 11:45am

    Wouter Vervloet

    758 posts

    Have you tried to change the order of PHP processing in the templates manager (ie: input/output) ?

    Your example actually requires both… the first loop needs PHP to parse on output, the second on input.

    I still think either a embedded template or a custom query is the solution.

    Greetz,
    Wouter

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases