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

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?

Related

How to change a URL for a specific page in WordPress?

I'm not talking about site URL.
I mean like changing from mysite.com/our-team/john-doe to mysite.com/our-volunteers/john-doe
I just want to rename the /our-team/ to /our-volunteers/. There's only one john-doe page. Now, John Doe is NOT our team per se, but he's a volunteer. So, I need to change the slug to "our volunteers."
The current premium I'm using does not create a WordPress typical page for this so I can't modify the url of the page. So, this does not work -> https://www.competethemes.com/blog/change-page-url-wordpress/
Is there like a hook i can use? Permalinks only allow changing the url structure of the entire site.
What you exactly looking for is Page attributes
https://wordpress.com/support/pages/page-options/#parent-page
You have parent page Our volunteers
http://example.com/our-volunteers
And pages of children pages
http://example.com/our-volunteers/john-doe
http://example.com/our-volunteers/foo
http://example.com/our-volunteers/bar
Set our-volunteers as page slug when you create Our volunteers page
Assign pages John doe, foo, bar to Parent page (Our volunteers) from Page attributes section bottom right on 'creating new page' page
One hack could be to edit .htaccess for this particular issue. It's kinda hacky and might get you into other problems. There's also plugins to do rewrites for you.

Wordpress custom menu for each user?

I was wondering, is it possible to give a registered user to create his own menu based on his chosen categories for the website on WordPress? Let's say he chooses which menu items he wants to see & only sees those menu's when logged in.
This is not a built-in feature, but yes, this would be possible on a custom WordPress site (i.e. WordPress.org, not WordPress.com), and there are a lot of different ways you could structure it.
It would not be trivial to implement, however.
My initial approach would be to have an actual WordPress menu hold all possible items, and then store user preferences as to which of the items are shown or hidden. On their user profile edit page, you could output the menu items as a checkbox list, and then store their selection as a user option. On the rest of the site, when you output the menu, you'd first pull that user option, then output the menu items manually one at a time if they have the option for that item checked.
There are of course other ways, but they would be similarly complex -- well beyond copying and pasting a code snippet, or me typing up a solution for you here.

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!

Where to find a list of pages automatically renderable in Drupal and how it works?

In the pages .tpl.php of my theme i can find several lines like
render($action_links)
displaying whole pages with a single command. Sometime i saw that the render argument is a block from my theme .info, but other times i see arguments i cannot identify that render default pages or elements of drupal.
How it works? And where i can find a list of default displayable pages?
In particular, i needed to display the content of the default drupal page "add content" in one of my pages, and i'm pretty sure i can do it using this render method, but i cannot find the correct argument.
EDIT: I found something like
drupal_render(node_add('NODE_TYPE'));
that seems to allow the display of a node add form, but what i need is the main add content page, containing the list of all the type of nodes that a user can add.
Are you new to Drupal? When I read your post, I'm almost sure that you have missed something with the Drupal's working. The variables you found in render() functions are "calculated" somewhere else in the code (in the modules part for the most).
You cannot find a list of constant variables to display them just like this.
I found this article about these mysterious variables that are rendered and I hope it will help: http://newsignature.com/articles/the-magic-behind-drupals-render-elements
If you just want to display the "add content" form somewhere on your site, just call its path (node/add).
EDIT AFTER CLARIFICATIONS:
First of all, you can set on which page you want the user lands after login. (I don't know why you're still talking about user profile template. Maybe I missed something again.)
But if I did understand what you're trying to achieve, I'll do that:
Create a menu (or simply use the "Navigation" menu that seems to be exactly what you need) with all the actions users can do. And I'll place this menu in the main content region. Do create a menu, go to Administration>Structure>Menus>Add menu. And add links like "node/add/article" or "node/add/news" or "node/add/page" or whatever your content-types are.
Place this menu in the region you want. If you want it to be like the main content of the page, place it in the main container. To do so, go to Administration>Structure>Blocks> Drag and drop your menu in the right region and Save.
Configure this block to appear only on the front page (the first page on user arrives after logged in) if you want so. To do so, in the Blocks administration page, click on "Configure" next to your block and check "show block on specific pages: Only the listed pages" and write down <front>
Create roles and permissions for your different sorts of users. That will automatically show them the links they are allowed to see. To set permissions, go to Administration>People>Permissions and check in the "Node" section which content-type each role can create.
I hope I didn't forget anything. Please tell me if it is clear enough.

Expression Engine - Next entry in specific category?

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.

Categories