We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Alphabetical listing with categories AND custom fields

Development and Programming

Carlo Laitano's avatar
Carlo Laitano
99 posts
15 years ago
Carlo Laitano's avatar Carlo Laitano

I’m working on an alphabetical listing for a website. I’m using the query module. So far I can output entries to certain letters and categories.. but I can’t seem to figure out how to output custom fields to those entries.

This is the code I currently have:

{exp:channel:category_heading channel="comercios"}
{exp:query sql="SELECT title, 
url_title AS urlt, 
cat_id 
FROM exp_channel_titles NATURAL JOIN 
exp_category_posts WHERE 
channel_id = '1' AND 
cat_id = '{category_id}' AND 
title LIKE '{segment_5}%' 
ORDER BY title ASC"}
{/exp:channel:category_heading}

Any ideas on how to pull the custom fields with that query? I know I need to join the exp_channel_data table but I can’t figure out how.

       
Carlo Laitano's avatar
Carlo Laitano
99 posts
15 years ago
Carlo Laitano's avatar Carlo Laitano

Nobody helped but I did figure it out. Si i’m posting my solution here so anyone else can take a look. I used embeds to pass on the url_title output with the query command. I pass it on to an embed template and use it as the url_title parameter in the exp:channel:entries tag. Works like a charm.

Code in listing page:

{exp:channel:category_heading channel="comercios"}{exp:query sql="SELECT title, url_title AS urlt, cat_id FROM exp_channel_titles NATURAL JOIN exp_category_posts WHERE channel_id = '1' AND cat_id = '{category_id}' AND title LIKE '{segment_5}%' ORDER BY title ASC"}{/exp:channel:category_heading}

{embed="catalogo/alpha_listing" link="{urlt}"} //embed template

{/exp:query}

Code in embed template:

{exp:channel:entries channel="comercios" url_title="{embed:link}"}<!-- entry -->
        <div class="entry">
            {comercio_logo}
            <div class="info">
                <h3><a href="http://{baseurl}index.php/catalogo/entry/{url_title}">{title}</a></h3>
                {comercio_desc}
                <div class="contact">
                    {comercio_tel}

                    {comercio_cell}
                </div>
                <div class="address">
                    {comercio_address}
                </div>
            </div>
            <div class="util">
                <a href="http://{baseurl}index.php/catalogo/entry/{url_title}" class="view">Ver productos</a>
            </div>
            <div class="clear"></div>
        </div>{/exp:channel:entries}

Now I have listing pages by letter, filtered by categories, and custom fields displayed 😊. Voila!

       
elative's avatar
elative
8 posts
15 years ago
elative's avatar elative

Carlo,

I’m trying to do something similar; in my case, I have a series of entries, spread across a series of categories (all in the same category group), that I’d like to display grouped within their category.

Your code looks like it might work, but when I tried it, the

{/exp:query}

bit ended up rendering as plaintext, and none of my entries materialized. Here’s what I’ve got:

{exp:channel:category_heading channel="faq-question"}
    {exp:query sql="

        SELECT title, url_title AS urlt, cat_id

        FROM exp_channel_titles

        NATURAL JOIN exp_category_posts

        WHERE channel_id = '7' AND cat_id = '{category_id}'

        ORDER BY title ASC"}
    <section class="faq-category-container closed">
        <h1 class="faq-category-header"><a href="#">Category 1</a></h1>
{/exp:channel:category_heading}
        <dl>

    {embed="jazz-camp/faq-cat-list" link="{urlt}"}
        </dl>
    </section><!-- end .faq-category -->
{/exp:query}

And my embed looks like this:

{exp:channel:entries channel="faq-question" url_title="{embed:link}"}<!-- entry -->
            <dt>{title}</dt>
            <dd>
                {faq_content}
            </dd>
{/exp:channel:entries}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.