Next/Previous Links within Secondary Category
Posted
#3389
(In Topic #668)
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.
Code (php)
Code (php)
Posted
EDIT: I was correcting my code, but realised it would be going in another direction to yours, so I'm correcting yours.
Code
$prev_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'news_entry', array('news_entry_category' => $secondary_cat), ' AND news_entry<' . strval($us_id));
Code
$prev_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'MAX(news_entry)', array('news_entry_category' => $secondary_cat), ' AND news_entry<' . strval($us_id));
Code
$next_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'news_entry', array('news_entry_category' => $secondary_cat), ' AND news_entry>' . strval($us_id));
Code
$next_id = $GLOBALS['SITE_DB']->query_select_value_if_there('news_category_entries', 'MIN(news_entry)', array('news_entry_category' => $secondary_cat), ' AND news_entry>' . strval($us_id));
i.e. MAX/MIN is needed to maximise/minimise the ID within the constraint given.
Posted
Automated fix message
This issue has now been filed on the tracker in issue #5614, with a fix.crkgb said
Hello,
Still a newby to this system. Trying to figure out how to limit number of news on the index/main page to a specific number. I was able to locate where it's done in the news component but was unable to locate this limitation for the index. In other words where do I enable pagination for the index page?
Also is there a way to disable user registration whyle keeping the site opened to public?
Thank you
Posted
0 guests and 0 members have recently viewed this.