I have a template which uses some php and a db query to fetch the contents. I had help putting it together in the first place and now it no longer works in v3, so I am not sure how to update it.
<?php
global $DB;
global $IN;
$results = $this->EE->db->query("SELECT * FROM exp_channel_data WHERE channel_id = '32' AND field_id_141 LIKE '" . $this->EE->db->escape_str($this->EE->uri->segment(3)) . "%'");
$entries = array();
if($results->num_rows > 0)
{
foreach($results->result() as $row)
{
$entries[] = $row->entry_id;
}
$results_returned = true;
}
else
{
$results_returned = false;
}
?>
<title>{exp:channel:entries channel="{current_channel}" limit="1" orderby="{current_channel_id}_number_sorting" sort="asc" dynamic="off" <?= (($results_returned == true) ? 'entry_id="' . join('|', $entries) . '"' : ''); ?>}{channel} - {{current_channel_id}_number_display} {title}{/exp:channel:entries}</title>
<?php
global $DB;
global $IN;
$results = $this->EE->db->query("SELECT * FROM exp_channel_data WHERE channel_id = '32' AND field_id_141 LIKE '" . $this->EE->db->escape_str($this->EE->uri->segment(3)) . "%'");
$entries = array();
if($results->num_rows > 0)
{
foreach($results->result() as $row)
{
$entries[] = $row->entry_id;
}
$results_returned = true;
}
else
{
$results_returned = false;
}
?>
{exp:channel:entries channel="{current_channel}" orderby="{current_channel_id}_number_sorting" sort="asc" dynamic="off" <?= (($results_returned == true) ? 'entry_id="' . join('|', $entries) . '"' : ''); ?>}
What type of field is field_id_141
? This looks like code that originally started on v1 before you could filter channel entries tags by field content.
ref: search://field_name= parameter
I think you can get rid of this PHP rather than trying to debug it.
This particular channel is a kind of encyclopaedia, arranged according to specific topics with sub topics four layers deep. The main page still works and shows the layout: http://www.westeros.org/Citadel/Concordance/
The Section template allows someone to click anywhere on the main index and get the content belonging to the level chosen and all levels below. For example, this is one part of the tree:
If you click on 4. Iron Islands, the Section template will show everything that matches 4.(x). If you click on 4.2.1. Pyke, it will show everything that matches 4.2.1.(x).
I have no idea if this can be done without the php, since the matching is pretty specific.
Your matching is just comparing the start of the field with the 3rd segment, but looks like with your current content design, you do need the “starts with” matching which you currently can’t do with the tag parameter. Long term—and this is probably a large project considering the scope of your content—you would be best served by using relationships for section.subsection.article schema, rather than storing string partials in a field and matching based on strings.
Second best would be converting this PHP to a plugin, which would not be difficult. For a quick fix though, replace all of the PHP above with:
<?php
$query = ee()->db->select('entry_id')
->where('channel_id', 32)
->like('field_id_141', ee()->uri->segment(3), 'after')
->get('channel_data');
$entry_ids = '';
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$entry_ids .= $row->entry_id.'|';
}
}
?>
{exp:channel:entries channel="{current_channel}"
orderby="{current_channel_id}_number_sorting"
sort="asc" dynamic="off"
entry_id="<?=trim($entry_ids, '|')?>"
}
The title code block would use the same PHP, but:
<title>
{exp:channel:entries channel="{current_channel}"
orderby="{current_channel_id}_number_sorting"
sort="asc" dynamic="off"
entry_id="<?=trim($entry_ids, '|')?>"
}
{channel} - {{current_channel_id}_number_display} {title}
{/exp:channel:entries}
</title>
The PHP would not change for use in a plugin, but you’d instead just return the trimmed text, e.g.:
{exp:channel:entries channel="{current_channel}"
orderby="{current_channel_id}_number_sorting"
sort="asc" dynamic="off"
entry_id="{exp:my_plugin}"
}
Thank you so much, that (mostly) did the trick. The only issue that I see now is that the title ends up containing all entry titles that it matches, as opposed to just the highest level. limit=”1” was taking care of that before but does not seem to work now.
I will definitely look at making it into a plugin. Never made one, but sometime has to be the first I suppose. 😊 Relationships sound like an intriguing approach, though I cannot quite picture how to get this fine-grained control with it. And, as you say, it is a massive project.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.