Plugin attempt: singleChildRedirect
-
Hi all,
I’m trying to achieve a simple behaviour: when a category has only one post assigned, then when the category is clicked, please WordPress, directly show this post (indestead of bugging me with an category overview with only one post listed).
# Pseudo code
//check how many post are in a category query = "Select COUNT from CATEGORIES have articles" if (count == 1) { //check the post ID query2 = "Select the above postID" //and redirect wordpressRedirect(postID) }It might become 15 lines in total but not far more I think.
# Where
The most difficult question for me is: where to place my code and which hook to use (as far as I understood, hooks are specific points during runtime when WordPress renders a page and I can add my behaviour at those hooks)?
hooks documentation# Why
This behaviour would be very helpful setting up WordPress as a CMS: you could build the whole navigation up on categories (and not on pages as seen often) and whenever the category is clicked you don’t see an article listing with one article but directly get redirected there.
Any help would be apreciated.
Rgds,
Henning
The topic ‘Plugin attempt: singleChildRedirect’ is closed to new replies.