Important: This website is now read only (except to admins) to comply with the UK Online Safety Act. Composr CMS is in the process of migrating to a new Constitutional governance model and Bazaar development model, with functionality of the old website (constructed by ocProducts Ltd, the prior copyright holder, a UK company) spread between GitLab and the new website (which has no connections to the UK).
Navigate between news entries within the same secondary category
Greetings,
Last week during our first Composr Community Chat, I asked Chris if there was a way to add next/previous buttons to the news entry screen, so users can navigate backward and forward through a category directly from the news pages, without having to go back to a category page between each one. Chris kindly wrote some miniblocks for this purpose, which he posted for download in this thread.
Unfortunately, I found that the blocks didn't work as expected on my own website, for several reasons. One of those reasons was that I utilize secondary categories for my video series, and the miniblocks Chris wrote were for primary categories. The other reason was something to do with timestamps, as I found that the "Next" link skipped over around 15 videos even within the primary category.
The reason secondary categories are tricky to work with is that they're stored in a separate table in the database. The first thing I did was modify Chris's miniblock to find the desired category from that second table, rather than using the intval($map['cat']) mechanism that Chris used, which only returns the primary category. Next, I added a second query which searches the second table for the ID of a news entry greater than the current ID that we're viewing. Using the ID instead of the timestamp means that I don't have to worry about cross-referencing the primary table that stores the timestamp, and it also means I don't have to worry about whatever sorting issue was happening before. It does assume that you're adding your news entries in the correct order and not rearranging the times afterwards, which is fine for my needs.
The "Next" button is now working flawlessly with secondary categories on my website. I haven't gotten the "Previous" button working quite yet. The query is returning the first news entry in the secondary category table located in the desired category, which means it's always returning Episode 1 of the series, no matter which episode is being viewed. We need the highest ID that's lower than the current ID. I'm not fluent enough in SQL/PHP/Composr to solve that one easily, so any suggestions are welcome, or I'll just come back to it and figure it out myself eventually.
Attached are the modified miniblocks as I'm using them now.Attachment
Whoops, I did make a mistake in my code. EDIT: I was correcting my code, but realised it would be going in another direction to yours, so I'm correcting yours.
If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Last week during our first Composr Community Chat, I asked Chris if there was a way to add next/previous buttons to the news entry screen, so users can navigate backward and forward through a category directly from the news pages, without having to go back to a category page between each one. Chris kindly wrote some miniblocks for this purpose, which he posted for download in this thread.
Unfortunately, I found that the blocks didn't work as expected on my own website, for several reasons. One of those reasons was that I utilize secondary categories for my video series, and the miniblocks Chris wrote were for primary categories. The other reason was something to do with timestamps, as I found that the "Next" link skipped over around 15 videos even within the primary category.
The reason secondary categories are tricky to work with is that they're stored in a separate table in the database. The first thing I did was modify Chris's miniblock to find the desired category from that second table, rather than using the intval($map['cat']) mechanism that Chris used, which only returns the primary category. Next, I added a second query which searches the second table for the ID of a news entry greater than the current ID that we're viewing. Using the ID instead of the timestamp means that I don't have to worry about cross-referencing the primary table that stores the timestamp, and it also means I don't have to worry about whatever sorting issue was happening before. It does assume that you're adding your news entries in the correct order and not rearranging the times afterwards, which is fine for my needs.
The "Next" button is now working flawlessly with secondary categories on my website. I haven't gotten the "Previous" button working quite yet. The query is returning the first news entry in the secondary category table located in the desired category, which means it's always returning Episode 1 of the series, no matter which episode is being viewed. We need the highest ID that's lower than the current ID. I'm not fluent enough in SQL/PHP/Composr to solve that one easily, so any suggestions are welcome, or I'll just come back to it and figure it out myself eventually.
Attached are the modified miniblocks as I'm using them now.Attachment
news_next.php
Attachment
news_previous.php
This issue has now been filed on the tracker in issue #5614, with a fix.
Sorry, I have no idea why the Composr bugfix tool posted here instead of the correct forum...
Need support for version 10? The core development team is no-longer offering it for free (unless it's a critical bug that breaks your entire site or a serious security hole). Please consider hiring me instead if you need v10 support or a non-critical bug fix. Or, ask the community in the forums!
Do you enjoy Composr? Please consider contributing your talent to the project or recommending Composr to others. Even small contributions make a big impact in the Composr community.
Do you have feedback for us? You can report bugs, suggest features, or give feedback on the Free support options page.
Do you need professional service with your Composr website? Please consider contracting me for your needs through my company, PDStig, LLC. Doing so will also help fund Composr development.
Want to watch live streams of me developing Composr CMS? Please subscribe to me on Twitch to be notified when I stream. Composr development streams are usually spontaneous / not scheduled in advance as work priorities come first.