Let me take a different approach to this.
What I’m trying to do, overall, is to include entries from two weblogs that have certain statuses but to exclude others. This is easy enough to do with normal EE tags, but the problem comes when I want to have a set number of entries appear on each page.
For example, if I use EE tags and limit the entries to the most recent 20, but 6 of the most recent do not meet my criteria, then all I’ll get is 14 entries on the page. Here’s an example of the code, where I use the presence or absence of custom fields to determine which weblog an entry is pulled from:
{exp:weblog:entries weblog="doubletongued|citations" orderby="date" sort="desc" limit="20" status="Open|Used|Closed|McGH|Nonce" disable="member_data|trackbacks" offset="10"}
{if pos != ""}weblog 1 entry data{/if}
{if status != "Used" && citepos != ""}weblog 2 entry data{/if}
{/exp:weblog:entries}
Of, course, as I said, with this method, there’s no way to guarantee that I’ll always see 20 entries per page, since the 20 applies to *all* the recent entries and I can’t put the necesary limiting conditions on the exp:weblog:entries tags.
So that means that I have to use some kind of SQL query, like so:
{exp:query limit="20" sql="SELECT t.weblog_id, d.weblog_id, t.status, t.url_title, d.field_id_26, d.field_id_14, d.field_id_22, t.title, t.entry_date FROM exp_weblog_titles AS t LEFT JOIN exp_weblog_data AS d ON t.entry_id = d.entry_id WHERE (t.weblog_id='1' AND t.status='Used') OR (t.weblog_id='2' AND t.status='open') ORDER BY t.entry_date DESC"}
{if weblog_id == "2" AND status == "open"}weblog 2 entry
{if:elseif weblog_id == "1" AND status == "Used"}weblog 1 entry
{/if}
{paginate}
Page {current_page} of {total_pages} pages {pagination_links}
{/paginate}
{/exp:query}
This works for basica tags that can be found in exp_weblog_data. But the problem here is that I want to get the full range of tags out of each entry, like categories, which are stored in other tables, and I’m not sure how to go about getting them. It’s going to either have to involve complex joins or multiple queries. I don’t know enough about joins and nested queries seem not to work for me.
So, with a lot of searching of the forums, I came up with some code that Paul offered up to someone else who was having a similar problem. My version looks like this:
<?php
$entries = array();
$query = $DB->query("SELECT t.entry_id, d.entry_id, t.weblog_id, d.weblog_id, t.status, t.url_title, d.field_id_26, d.field_id_14, d.field_id_22, t.title, t.entry_date FROM exp_weblog_titles AS t LEFT JOIN exp_weblog_data AS d ON t.entry_id = d.entry_id WHERE (t.weblog_id='1' AND t.status='Used') OR (t.weblog_id='2' AND t.status='open') ORDER BY t.entry_date DESC");
if ($query->num_rows > 0)
{
foreach($query->result as $row)
{
$entries[] = $row['entry_id'];
}
}
$ids = implode('|', $entries);
?>
{exp:weblog:entries entry_id="<?php echo $ids; ?>"}
{entry_id}
{if weblog_id == '1'}weblog 1 data{/if}
{if weblog_id == '2'}weblog 2 dat{/if}
{/exp:weblog:entries}
But that doesn’t seem to work at all. I get no results. (Globals DB and TYPE are already called higher up on the page.)
So, does this make any sense?