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.

2 Major Gripes with EE I would love a clean fix for:

September 15, 2013 8:14am

Subscribe [3]
  • #1 / Sep 15, 2013 8:14am

    Sunnyland

    66 posts

    There’s 2 major problems I have with Expression Engine that cause me endless problems between the 2 of them, which I would LOVE to have a clean, free, native fix for, if possible.

    The first being that it doesn’t seem to be native for Expression Engine to allow you to filter channels by author, or a random field from the channel.

    (When this is done by javaScript, or via a member table query, it seems to break the time-space continuum and causing things like counts and result checks to fail, disallowing numbering, total results, alternate messages for empty results, etc…) < or really any check that refers to a nested channel, which is being masked by the parent channel, the case that you try to get the extra variables via a database query.

    The other gripe being that there doesn’t seem to be option to display EE’s native error messages inline. whether under the fields, in a box together, in an overlay or any other method.. just a whole new navigation page with no relevance to the site whatsoever.

    (If one attempts to solve this problem by simply intercepting any such error messages with their own javaScript validation before the native ones can kick in, great, but how do we use a jquery validator to check captcha results and username and password descrepancies, search parameters etc, etc, etc… )

    ^^ This one also is in desperate need of a solution…

    To the community: Please point me in the right direction if I’m ignorant to any blatant solutions to any of these concerns.

    Thanks in advance.

  • #2 / Sep 19, 2013 11:56am

    Boyink!

    5011 posts

    Do you mean on the front end or in the CP?

    If the front end - for your first issue there is a search parameter for the Channel Entries tag that allows filtering by values in any field. You can also use author id as a parameter which would filter by author.

    On the second there is at least one add-on I’ve seen that allows you to style error pages.  Do a search on Devot-ee.

  • #3 / Sep 19, 2013 11:00pm

    Jérôme Coupé

    122 posts

    I believe the add-on Mike is referring to is custom system messages. It will not allow inline error messages per se but will let you customize all specialty templates from ExpressionEngine.

    Have a look on stackexchange as well for more info

    HTH,

    Jérôme

  • #4 / Sep 22, 2013 1:13am

    Sunnyland

    66 posts

    Ok thanks, well I’ve been going through finding templates and ways to edit the code manually to replace it with proper page layouts where necessary, and adding my own jquery validation for things I can actually catch with such validators…

    But as for the author filtering thing…

    I’ve made a simplified example of one thing I’m doing in attempt to get around not being able to sort natively by author (though it has some issues which I will get to):

    Bear with me, as this involves a few steps…


    I’ve been able to create members links to pages where channels are located, adding a url segment containing a member’s username via an sql query, like so:

    <ul class="members_list">
         {exp:query sql="SELECT username, screen_name FROM exp_members "}
          <li>
           <a href="http://{path=%27member_page/{username}%27}" title="View {screen_name}'s Page">_        {screen_name}_       </a>
          </li>
         {/exp:query}
       </ul>

    In this example, my main index is being used to display any untemplated urls, by turning off Strict URLs under Global Template Preferences. I’ve simply embedded a template into one of my content areas in the index like so:

    {embed="shared/blog_post"}

    In the embedded template, I’ve created a channel:entries expression, querying a channel called “blog” where members will post entries. I’ve then added basic conditionals so that this content only shows up when we’re on the on the correct URL (member_page, and not where those segments don’t exist), and I’m filtering the channel by the url segment_2 which should be the username of the member clicked from the members list created earlier, by comparing the segment to the author (for each result). (Basically everything between the main exp and if tags is just content, so don’t worry about that…)

    {exp:channel:entries channel="blog" sort="desc"}
      {if segment_1 AND segment_2 AND {"segment_1}" == "member_page" AND "{author}"=="{segment_2}" } 
      <div class="module blog article">
       <div class="article_header">
        {if image}
         <div class="article_image">
          {if image_link}
           <a href="http://{image_link}" title="{title}" target="_blank" rel="noopener">_        {site_url}images/blog/_thumbnail/{image}{filename}.{extension}{/image}_       </a>
          {if:else}
           {site_url}images/blog/_thumbnail/{image}{filename}.{extension}{/image}
          {/if}
         </div>
        {/if}
        <div class="article_title">
         <h2>
          {title}
         </h2>
    <p>    </p><h3>
          {if subtitle}{subtitle}{/if}
         </h3>
    <p>    </p><h4>
          {entry_date format="%F %d %Y"}
         </h4>
    <p>    </div><br />
       </div><br />
       {if body}<br />
        <br />
         {body}<br />
        <br />
       {/if}<br />
       {if read_more}<br />
        <div class="read_more_link"><br />
         Read More<br />
        </div><br />
        <div class="read_more_content"><br />
         <br />
          {read_more}<br />
         <br />
        </div><br />
       {/if}<br />
      </div><br />
     {/if}</p>
    
    <p>{/exp:channel:entries}

    The problem with this, is that I must first read in every entry for the whole blog channel (from all users) and then filter to the user in the url_segment. Aside from time and resource wastage, I am also unable to use count and result related values, since as far as the channel is aware, all entries are pulled as results.

    This means that I can’t count, I can’t use no_results to create alternate text and I can’t use limits, since these will apply to ALL results PRIOR to the filter by author.

    For example, exp:channel:entries sort=“desc” limit=“1” will always be blank, unless the user whose page we’re looking at happens to be the last user to make a post.

    I discovered an alternative to this method, in that it’s possible to filter a channel by the ‘author_id’ “note, this is no-where near as useful as the ‘author’ name in my case, since I’m using usernames in the url_segments, not user_ids, and using author=”{username}” seems to be not working at all, even if entered manually.

    HOWEVER I’ve discovered that while the user_id will work if MANUALLY ENTERED, using the url_segment variable in the entry tag to enter this value dynamically (in the case that I would be willing to change all my usernames in the url_segments to user_ids) has not worked at all.

    i.e.

    {exp:channel:entries channel="blog" sort="desc" author="john_doe"  }

    < This doesn’t work (yields all results for all members).

    {exp:channel:entries channel="blog" sort="desc" author_id="1"  }

    < This works (yields results only for said member).

    {exp:channel:entries channel="blog" sort="desc" author_id="{segment_2}"  }

    < This doesn’t work (yields results for all members).

    Note that the ONLY WAY I could manage to get this to work DYNAMICALLY was using a further SQL Query, as below.

    I wrap the channel in an sql query like so, pulling only the results for the username, where the username is equal to the url segment_2:

    {exp:query sql="SELECT username, screen_name, member_id FROM exp_members WHERE username = '{segment_2}' "}
     {exp:channel:entries channel="blog" sort="desc" author_id="{member_id}"  }
      content 
     {/exp:query}
    {/exp:channel:entries}

    This allows me to compare the author_id to the member_id, in order to dynamically filter the channel entries by author_id.

    Pretty cool, right?

    This seems to be working ok at this point, though I still can’t manage to get a

    {if no_results} content {/if}

    to fire off…. it seems to be referring to the exp:query, rather than the nested exp:channel:entries. so it’s applying the no_results variable to the query expression, and returning null, since there are results for the member query itself, just not the resulting channel:entries query against the author_id. I think there really just needs to be a native exp:channel:entries author parameter…

    i.e. PLEASE IMPLEMENT THE FOLLOWING

    {exp:channel:entries channel="channel_name" author="{segment_1}"}

     

  • #5 / Sep 22, 2013 2:29am

    Sunnyland

    66 posts

    Damn!

    Upon further testing, this is still not working, as now {count} is numbering every result as 1.

    While it seems to be working to pull the entries without a nested conditional, I can’t fathom why {count} is operating this way…

    I guess it’s back to the drawing board again :/

    If you know of a way to filter by ‘any field’ as a parameter directly in the template tag, would you be able to give me a pointer on that one?

    Cheers.

  • #6 / Sep 22, 2013 2:06pm

    Rob Allen

    3114 posts

    If you’re using /template/username URL’s then you need to state the username as a parameter, eg

    {exp:channel:entries channel="blog" username="{segment_2}" dynamic="no"}  
    {title}
    {/exp:channel:entries}

    The username parameter tells EE to use the “username” to filter by, author_id is a numerical value
    The dynamic=“no” parameter tells EE not to assume that segment_2 is an entry url title

  • #7 / Sep 24, 2013 11:58pm

    Sunnyland

    66 posts

    Aha!

    So it’s username, not author…

    In a channel:entries expression, this works great.

    It perfectly filters the entries at a channel level, resulting in clean and accurate result and count values.

    Thanks so much for your help on this.

    In the case that I am producing a members list, and wish to pull entries from channel entries (latest) for each user (not a specific user, as in the previous case) I am needing to run the channel:entries expression inside a query expression to grab each member by username, then run a channel:entries expression inside that to get some fields from the latest post by that user (for each member).

    This works fine in the way the ones above were, except that once again counts and result values are failing to print accurately, ie: counts are always 1 and no_results never fires).

    Example more or less as below:

    <ul class="member_list">
     {exp:query sql="SELECT username, screen_name, member_id FROM exp_members "}
      <li>
       {exp:channel:entries channel="channel" sort="desc" username="{username}" }
         {if no_results} 
          no_results_content <a href="http://path=%27{user_page/username}%27" title="{screen_name}'s Page">{username}</a> - 0 entries
         {if:else}
          {if "count"=="total_results"}
           {if field}{field}{/field} <a href="http://path=%27{user_page/username}%27" title="{screen_name}'s Page">{username}</a> - {count} entries
          {/if}
        {/if}
       {/exp:channel:entries} 
      </li>  
     {/exp:query}
    </ul>

    So in this case, I’ve got a ul called member_list, I am pulling all members, then creating an li for each member.
    Then I query a channel for each member to see if they have posted an entry to it.
    If no_results, I display some hard-coded content and a link to that user’s page, with ‘0 entries’ at the end.
    If there’s an entry, I display some field/s from the latest entry and a link to the user’s page, with ‘{count} entries’ at the end (should be the number of the latest entry, i.e. the number of entries).

    The problem is that the count seems to be relating the the parent sql query and not the nested channel query, so I can’t get total entries for that user, and a no_entries conditional…

    This seems to be pretty important to what I want to do on the site, so it would be really really great if I could find a solution to this one!

    Thanks a lot for your help.

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

ExpressionEngine News!

#eecms, #events, #releases