Expression Engine - Next entry in specific category? - php

OK, another problem with Expression Engine. I know it pretty well but i'm sort-of just learning categories!
I've searched around for this answer but can only find the same thing. I need to have a next button on a title_permalink page that goes to the next entry in that category. I know how to manually specify a category but that won't work as it will only ever give me entries from that category! I need a way for ee to know what category the entry is in. My code is very simple at the moment, it's :
{exp:channel:next_entry}Next Project{/exp:channel:next_entry}
I could add category_id="2" but then what happens whenever the person goes into a category that isn't 2, they are all using the same view template.
My structure is like follows:
Category Selection page - list of categories using category_name tag
Project List page - links here using channel:entries tag
Project View page - linked here by a title_permalink tag
Thanks for any help!

The default ExpressionEngine Next/Previous Entry Linking Tag Pairs allow you to generate links to the next or previous entry, based on the date of the current entry.
However, the biggest limitation is that they not as robust when it comes to restricting or filtering entries with multiple categories.
If your needs are simple, you can use the following code to restrict the Previous/Next links to showing entries within the current entry's category:
{exp:channel:entries channel="channel_name"}
...
{exp:channel:prev_entry category="{categories}{category_id}|{/categories}"}
« Previous
{/exp:channel:prev_entry}
{exp:channel:next_entry category="{categories}{category_id}|{/categories}"}
Next »
{/exp:channel:next_entry}
...
{/exp:channel:entries}
You'll notice that the {exp:channel:prev_entry} and {exp:channel:next_entry} links are nested inside the {exp:channel:entries} tag and use the {categories} tag pair to restrict the Next/Previous links to the current entry's category.
Realize, however, that this code works best when entries are classified using a single category.
Otherwise, when using the {categories} tag pair with an entry having multiple categories, the Previous/Next links will default to the first category output ... which may be different than the next or previous entry's order of categories.
For a more robust solution, you'll find there are many third-party solutions on Devot-ee for entry linking.
Two of my favorite plugins for handling linked entries are Nearby Entries by Adam Khan and Entries List by Laisvunas.

Related

Navigating through custom post types in WordPress

I want to redesign my website using WordPress (as CMS) and Bootstrap (as front-end).
Now, I've been pretty successful at doing so, but I have one specific problem.
I have a tutorial website and I want the navigation structure to look like this :
If the user is on my 'website-name/tutorials' then display to him all of the tutorial series titles in an unordered list (so for example C++, XHTML and CSS - but not individual tutorials in each series)...
If the user clicks on some specific serie, then display an ordered list of the elements (so, if he clicks C++, then URL will be 'website-name/tutorials/cplusplus' and he will be able to see all of the tutorial in an ordered list).
If the clicks on one specific tutorial, then the URL goes (for example) 'website-name/tutorials/cplusplus/installing-the-program' and user gets all the content related to the tutorial.
Now, I have been experimenting with this and concluded that the best solution is to create custom post type named "Tutorial" and then make every single tutorial that post type.
However, since on 'website-name/tutorials/cplusplus' I want to display the list of tutorials in "C++" tutorial series and on 'website-name/tutorials' I want to display only the tutorial names, I don't know how to do that.
I tried to do that using Hiearchical posts (so, for example, I made a parent post named "C++" and it's children were all of the tutorials in the C++ serie).
However, I have a problem with that, because my C++ tutorial series has 100 tutorials, but it shows me 101 list elements (I made the website display all the custom post types in an ordered list), with the first one on the list being C++ (the parent post).
So, I'd like to echo the series name only on the 'website-name/tutorials' not on the beginning of the list.
I researched and people seem to use archive in custom post types, rather than parent/child system for this kind of navigation.
I just wanted some of the WP experienced users here to tell me, which is the better solution for my problem? Dealing with these parent/child problems or switching from parent/child posts to archive posts?
If I understand fully perhaps using standard posts and categories will do the trick? Your '/tutorials/' page can display the full list of all posts and when a user clicks on a specific category (e.g. C++) only the relevant posts will display.
You can use the following code to list posts of a specific category:
<?php query_posts( 'cat=20' ); ?>
Changing "20" with the chosen category ID.
Hope this helps!

Using ExpressionEngine's {category_name} on a permalink page?

I need help with a simple issue I'm having on a site built with ExpressionEngine 2.
I have a category which links to a "view" page using {title_permalink='product/view'}. On this page, I want to create a link to take the users "back" to the category (e.g. Back to Toys). How do I create this link?
For example, I would've thought this code would work:
{exp:channel:category_heading channel="project"}
<p class="pfloatRight"> Back to {category_name}</p>
{/exp:channel:category_heading}
But it doesn't as ExpressionEngine doesn't know which category the entry is in. I tried enabling related_categories_mode but it didn't help.
Any ideas? I know this is a simple fix, I'm just not used to working with categories.
If you don't mind outputting all the categories an entry is assigned to, you can offer a link "back to a category" from your product view permalink page.
Put the following code within your exp:channel:entries tag loop:
<p class="pfloatRight">
Back to
{categories backspace="2"}
{category_name},
{/categories}
</p>
Which would output something like:
<p class="pfloatRight">
Back to Category Name, Category Name
</p>
You'll notice I placed the "Back to" text outside the {categories} variable pair so it doesn't get repeated and used the backspace parameter to remove the comma from the last category.
The apparent downside is that if there's more than one category assigned to an entry, it may be confusing for the user to remember which category they navigated from.
I'd argue that most people are accustomed to using their browser's Back button rather than any on-page links, so trying to determine the actual category they came from may provide little return on investment.
However, even if these "Back to Category" links aren't necessarily useful to users, they do provide SEO benefits for people who may land on a product page from a search result and want to see more items in the same category.
If you only have one category assigned to the product, you can do this within your channel:entries loop:
{categories limit="1"}
<p class="pfloatRight">Back to {category_name}</p>
{/categories}
If you're using multiple categories per-product, then you'd have to use an add-on (or custom code) that stores the URL history for you (like this one) and retrieve the last-visited page that way.
Your code looks like it should work. What's the URL you're trying to execute this code from?

How do you create a "linked list" of Story nodes in Drupal 6?

I'm trying to link together a number of pages in a regular flow in Drupal. The way I've been doing it recently, is to create a new Menu and then seperately create a page for each menu item.
For example, I have a menu block with links One through to Six. I then create six pages and link One to node/1, Two to node/2, Three to node/3 and so on.
This is fine, but I'm told that I can create a number of story nodes instead, and they'll link together at the bottom of the page like so (http://imgur.com/xCtYe) without my intervention, almost like a linked list of page nodes.
How would I achieve this?
I worked it out. I had to enable the book module. Co-worker just explained to me after reading the question :)
You might also check out NodeQueue
I see you already solved it, but just FYI, you can also use the Custom Pagers module to do this as an alternative to the book module. Here is an excerpt from its project page:
... allows administrators to define context-sensitive previous/next pagers for any node type. The list of nodes to be cycled through is generated by a user-selectable view, and each pager can be displayed above or below the node body or in a sidebar block. This makes it possible to duplicate the paging functions of forum.module and book.module, as well as more complex stuff like comic strip navigation.

Drupal: Duplicate blog tags showing in block

I've got a Druapl-based website with a blog. I'm using a custom view block to list the different tags I've assigned to my posts. Although it lists them just fine (links work fine too), I'm getting alot of duplicates. For example, if I tag 3 differents posts with "sometag", then my block lists "sometag" 3 times in a row.
How do I fix this so each tag only appears ONCE in the block?
View export (in PHP): http://pastebin.com/m7b4724b7
View screenshot: http://i49.tinypic.com/2vmsthk.gif
Thanks!
select Term at Views creation, not Node.
Two options:
Click the little cog next to Style: HTML List, and select group by Taxonomy: Term.it.
Do as Nikit suggested and do a Taxonomy view instead of a Node view. That way, you can just select to filter duplicates and it will work as expected (by filtering duplicate terms instead of duplicate nodes)
Either should work fine. Just do whatever makes more sense to you.

Drupal 6: Views: Listing taxonomy terms with tagged nodes underneath

I need to create a view that lists out taxonomy terms and then list the top 3 recent(sort by node:date updated) nodes with that tag
example out put:
Article
Article 1
Article 2
Article 3
Podcast
Podcast 1
Podcast 2
Podcast 3
.
.
.
I created a view of type "Term" and I can get the view to output all of the terms. However, I don't see how to link in the nodes tagged with the taxonomy term. I looked around in the view of type node, but I couldn't get anywhere close to what I needed to output.
Outside Views, this appears to be exactly what Taxonews.module does. HAve you considered it ?
(disclaimer: I'm its author)
(Only the first part of a possible solution -- maybe it'll help you get to the full solution)
What about a view "node", with something like that (I use Drupal in French, so it might not always be the right words, sorry) :
fields
Taxonomy : term
Node : title (as link to node)
filters
whatever you want ^^
sorting
whatever you want
on the left of the screen, "base parameters" or something like this:
style : HTML list (or table)
the little "wheel icon" on the right of "style" : when you click on it, you have to possibility to choose, in a select list, a "grouping field" ; select "taxonomy: term"
It should list the nodes, grouped by taxonomy terms.
The only thing I don't know is how to list only 3 nodes of each taxonomy term ; if you do find out, I'm interested !
You could do this pretty easily with panels. Actually panels is not needed but it's a nice module that let you do a lot of stuff. Basically you can create a view for each term and make a blok display. In panels you can then create a page where you can put all of the bloks. You could also put the bloks in the content area only to be displayed in an empty page but that is in many ways not as elegant.
Or you can create a term view and add the node into the relationships, then you get all the nodes with a term, and as above, display as list and group according to term (with exclude from display). If you have as your primary sort Taxonomy by weight you can control the order of the grouping (something I couldn't do with a normal node view), then you could display in the order you want.
All that said, can't see how to limit it to 3 nodes per category!
If you still wander how to finish you recipe for taxonomy view.
You may like the video tutorial on topic of drupal calendar which uses exactly the technique needed to complete displaying the terms.
The tutorial is available at: http://vimeo.com/6547042
You've given a good start in direction many on the web dependents would like to step onto.

Categories