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.
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!
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}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.