My Wordpress implementation – a bunch of dirty hacks
As I’ve implemented this site I’ve realized Wordpress is a bit limited compared to what I’m used to, but I hope there’s some better solutions than I’m already using. I’ve basically figured out that it’s better to get it how I want it with some crappy hacks than nothing at all, so until I learn better ways, that’s the way I do it. These are hacks for left sidebar menu and top menu.
They are still useful for something I guess, on the portfolio page I use this code to check if the current page is, or is inside one of the portfolio categories. It also checks that the current page is not the front page. If it all checks out, it shows that menu in the left sidebar, if not it shows the normal one. Simple and dirty.
$category = get_the_category();
if (is_category('43') || in_category('43') || is_category('44') || in_category('44') || is_category('45') || in_category('45') || is_category('46') || in_category('46') && !is_front_page()) {
include (TEMPLATEPATH . '/sidebar-portfolio.php');
} else {
include (TEMPLATEPATH . '/sidebar.php');
}
?>
Also, I had problems getting the top menu to show which item should be selected as you browse through the sub categories and all. I needed this since I needed post functionality on portfolio, and I didn’t think the posts in pages plugin was any good. I solved this with this code. I can’t exactly guarantee that this code is correct, I’m no programmer, but hey, it works for me
.
The code in the first “li” sets the item to be current page if the variables page_id, cat and p is 0 or non-existing. The second “li” checks if the current page is one of the specified categories, or is IN the specified categories. And also that they are not the frontpage, if it all checks out it sets Portfolio to be the current page in the menu.
<li <?php if ($page_id == 0 && $cat == 0 && $p == 0) { echo " id=\"current\"";} ?>>
<a href="http://www.bee-digital.com">Home</a></li>
<li <?php if (is_category('43') || in_category('43') || is_category('44') || in_category('44') || is_category('45') || in_category('45') || is_category('46') || in_category('46') && !is_front_page()) { echo " id=\"current\"";} ?>><a href="http://www.bee-digital.com/?cat=43">Portfolio</a></li>

3 Comments Leave a comment
Bah, Wordpress.
and where’s my implementation of the Rock-Paper-Scissors-Lizard-Spock game?
Rock-paper-scissors-lizard-spock game? Link?
I had to use the same solution. I was looking a way to switch between 3 different sidebars and change the style of the selected category. Kind of dirty but after 2 days looking for a solution is the only one that works… the problem is when you have more than 100 categories.
Thank you
TrackBack URL