I can’t really understand why you need to sub category. The category page can list all the posts in that category for you to click on?
Okey, I understand it’s essential to be understood in order to be helped 🙂 so I’m gonna explain more in detail…
If you don’t put the post in a subcategory with the same name – there’s no way to see its name in the main drop-down menu.
So this way I’m exposing the existence of the product without making the user to search it anywhere. It’s just visible from the first mouseOver.
I guess there’s a way to make some very complex menu script…. but at this point it seems to me more easier to find an elegant solution to bypass the category subpage if there’s only one post in it.
category.phpin your theme folder, with this code:
<?php if(have_posts()) : while (have_posts()) : the_post(); wp_redirect(get_permalink($post->ID)); endwhile; endif; ?>
If you just want it for certain categories (so as not to fudge up your other category listings), name it
category-x.phpwhere x is the ID of the category. If you’re running WordPress 2.9, you can also name it
Thank you, stiand!
The redirect script works just fine.
The thing is that now every time I want to make a new product / or my friend, the client… will have to make such a page and that’s why I want more automatic solution.
I’ll read a few more days.. and then I think I’m gonna copy-paste all 40 products as “pages”… since this looks like the most easy way.
Then… I’ll have to figure out a way for making their slug automatically skip the category and the child category word and produce simple address like : http://site.com/product1
I still believe more in the potential of the post for better choice for the product pages so how can I expand the script you gave me in order to make it like:
“”if there’s only one post in category (3) – redirect straight to post(4)”
1 Products > 2 category > 3 category with product name > 4 post with product.
Here’s a solution everyone can use >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
What I’ve done is to make second category plugin.
<?php /* Category Template: skip-to-post Template URI: http://ralev.com/ Description: redirects to the first post in cat */ ?> <?php if(have_posts()) : while (have_posts()) : the_post(); wp_redirect(get_permalink($post->ID)); endwhile; endif; ?>
and then call if with the plugin :
“Idealien Category Enhancements”
Now for every created category with one post I can select from a drop-down menu ( in the category panel ) the secondary “skip” template 🙂
Works like a charm with WP 2.9! 🙂
PS: if somebody write an automatic condition script that could be attached to the main category.php and checks if there’s just one post in the category and redirects… then it will be even better, so we don’t have to choose a template – it will decide automatically if it needs redirect 🙂
PPS: thank you, “stiand” for your help! 🙂
Have yet to give Ralevs solution a go, but would love an automatic script/plugin. I’ve been searching for some thing like this for a while now.
I can’t get Ralevs solution to work. If any one does know of a plugin, fucntion or snippet of code that will bypass the category page straight to the post if only one post in category, that would be great.
i saved and uploaded your code as categories.php, but no redirect happens..
Filename should be
here is my solution: “an automatic condition script that could be attached to the main category.php and checks if there’s just one post in the category and redirects.”
<?php if(have_posts()) : $category = get_the_category(); if ($category->category_count == 1) : while (have_posts()) : the_post(); wp_redirect(get_permalink($post->ID)); endwhile; else : include(TEMPLATEPATH . '/index.php'); endif; endif; ?>
- The topic ‘Go to post from a category link ?’ is closed to new replies.