I am trying to turn on and off a section of navigation based on if a published entry has a status of open or closed.
So my intent is something like:
{if particluarpage == "closed"}
content
{if:elseif}
content
{/if}
Thanks
There are a couple of ways of achieving this. The simplest option would probably be to issue a query via the query module.
{exp:query sql="SELECT status FROM exp_channel_titles WHERE entry_id = '4'"}
{if status == 'open'}
Show Block A
{if:else}
Show Block B
{/if}
{/exp:query}
Shouldn't that be something like this?
{if "{exp:channel:entries channel="yourchannel" entry_id="X"}{status}{/exp:channel:entries}" == "closed"}
content
{if:else}
content
{/if}
Maybe you'll need the dynamic="no" parameter too.
Related
I am working on an Expression Engine site and am trying to fix a bug with pagination. A user performs a search which displays paginated results. The search terms are in a query string, so all I need to do is include the query string in the pagination links. However, I don't know how to configure this in Expression Engine. This is all I have to work with:
{paginate}
<div class="results-pager">
Page {current_page} of {total_pages} pages {pagination_links}
</div>
{/paginate}
Can I pass some sort of option to {pagination_links} to include the query string in the links it generates? Or do I need to write this code myself?
I found a way to do it. If you enable PHP code in your templates, you can manually recreate the pagination_links functionality and include the query string in the generated links.
Replace this:
{pagination_links}
With this:
{if total_pages > 1}
<div class="pagination">
{pagination_links}
{first_page}‹ First{/first_page}
{previous_page}‹ Prev{/previous_page}
{page}
{if current_page}
<strong>{pagination_page_number}</strong>
{if:else}
{pagination_page_number}
{/if}
{/page}
{next_page}Next ›{/next_page}
{last_page}Last ›{/last_page}
{/pagination_links}
</div>
{/if}
You might take a look at this free add-on:
http://devot-ee.com/add-ons/better-pagination
Not sure it's the exact fit for what you're doing though, it might allow you to do what you want without turning PHP on.
I am using the channel:categories tag to pull in categories for a section navigation. This works fine, but I also would like to tag the current active category as the active item in the navigation for styling purposes:
a class="active"
I tried two approaches neither of which works.
Attempt 1 (per the documentation):
<a {if active} class="active"{/if} href="{path='internal-staff-center/{category_url_title}'}">{category_name}</a>
Attempt 2:
<a {if segment_2 == "{category_url_title}"}class="active"{/if} href="{path='internal-staff-center/{category_url_title}'}">{category_name}</a>
I would appreciate some input from another viewpoint out there.
Thanks.
The {path} variable within Channel Categories will output a path using your category trigger word or the C(n) URL segment (C2, C15, etc). So it's doubtful that {segment_2} is actually your category_url_title ... it's more likely {segment_3}.
What is an example URL structure of these pages?
{if segment_X == category_url_title} should work so long as the comparison is correct.
Try
{if "{segment_2}" == "{category_url_title}"} class="current"{/if}
I have a single entry url structure like:
www.site.com/template_group/template_1/entry_id
But I want it to be:
www.site.com/template_group/template_1/entry_id/url_title.
Entry_id would be the segment feeding exp:channel:entries. How can I redirect www.site.com/template_group/template_1/entry_id to www.site.com/template_group/template_1/entry_id/url_title.
Thanks a lot!
Something like the following should work - it's untested, but it'll give you a good idea of how to go forward with it.
{if segment_4==""}
{exp:channel:entries channel="x" limit="1" dynamic="no" entry_id="{segment_3}"}
{redirect="template_group/template_1/{entry_id}/{url_title}"}
{/exp:channel:entries}
{/if}
put this at the very top of your template:
{if segment_4 == ""}
{exp:channel:entries channel="channel_goes_here" entry_id="{segment_3}"}
{redirect="{site_url}/{segment_1}/{segment_2}/{segment_3}/{url_title}
{/exp:channel:entries}
{/if}
This will check if you have set a fourth segment, if not it takes the third segment containing your entry_id, feeds it to the channel entries tag, which returns the url_title you need. With this url_title you can easily redirect to the correct page.
Good answers from janvl and madebyhippo
Quick note if you are using complex conditionals (the ones in the answers are simple ones so you will not have that problem) is that EE will parse the channel entries tags they contain, wich can slow down performance.
If you find yourself in that situation, best to avoid the problem altogether using Mark "The croxton" addons like switchee or ifelse
I have a series of entries that need to be displayed as part of a Category Archive.
I did the code this way:
{exp:channel:category_archive channel="botanical_gardens" style="linear"}
{categories}
<h3>{category_name}</h3>
{if category_description}
<p>{category_description}</p>
{/if}
{/categories}
{entry_titles}
{title}<br />
{/entry_titles}
{/exp:channel:category_archive}
This works with the exception of the URL which ties into the site url. Since each of these entries link to outside sites, how do I write the code to get the correct URL?
Thanks!
Custom fields can't be displayed within the Category Archive tag. Instead, you'll have to use the Channel Categories tag, and put a Channel Entries tag within it.
{exp:channel:categories channel="botanical_gardens" style="linear" disable="category_fields"}
<h3>{category_name}</h3>
{if category_description}
<p>{category_description}</p>
{/if}
{exp:channel:entries channel="botanical_gardens" category="{category_id}" disable="member_data|pagination|categories"}
{title}<br />
{/exp:channel:entries}
{/exp:channel:categories}
I’ve set up a site with eight channels divided into two sections.
One of the sections is called “Articles” and within that section there are two channels, “Features” and “News”.
Everything was working great until I introduced pagination into the equation.
On the Articles index page, I have tabs for “Latest”, “Features” and “News” and I navigate through them and select entries based on the segment:
<ul id="tabs">
<li>{if segment_2 == ''}<strong>Latest</strong>{if:else}Latest{/if}</li>
<li>{if segment_2 == 'features'}<strong>Features</strong>{if:else}Features{/if}</li>
<li>{if segment_2 == 'news'}<strong>News</strong>{if:else}News{/if}</li>
</ul>
{if segment_2 == ''}{exp:channel:entries channel="features|news" limit="10" dynamic="no" order="date" paginate="both"}{/if}
{if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both"}{/if}
{if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both"}{/if}
site.com/articles brings up all entries
site.com/articles/features/ brings up all entries in the Features channel
site.com/articles/news/ brings up all entries in the News channel
This works great until there is a channel with multiple pages and something like “P4” is added to the URL and then {segment_2} for the unfiltered index becomes P4 instead of what I am doing to navigate the channel entries.
Paginate URL:
site.com/articles/P4
I guess my question is this:
Am I navigating or filtering entries correctly? If so how would I do so now with pagination?
Thanks!
There are two possible solutions here.
You can use the paginate_base parameter to explicitly tell EE to use a specific path before the pagination argument:
{if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/features"}{/if}
{if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/news"}{/if}`
Alternately - and my preferred solution - is to create two new templates under the "articles" group, named "news" and "features", and list your entries there. You can avoid any duplication of code by turning your tab navigation (and even the markup/logic you plan on placing between your channel:entries tags, if it will be the same for each section) into snippets.