WordPress Active Tabs - wordpress

In my WordPress theme I included the following in the header.php for the menu:
<li>About Us</li>
<li>Contact</li>
However when I include the following code in the about us template:
<?php /* Template Name: About Us */ ?>
<?php $about = "active"; ?>
<?php get_header() ?>
The tab doesn't become "active", though if I include the code snippet $about = "active"; in the header.php file it works. Why is this? Is there an easier way to do this?

This probably has to do with the fact that the get_header() function isn't aware of the $about variable. This has to do with the PHP variable scope.
The way I solved this is by using the Wordpress API to generate a menu. This way, each page will automatically detect if it's the 'active' page and add that class to its relevant menu item.

I'd also suggest you to make your menu dynamic using wp_nav_menu(). However if you do not wish to use wp_nav_menu(), you could also make the menu items active using the page id in header.php

Related

Drupal - Block body is not saved/shown

i added this in my Drupal theme:
<div id="sidebar">
<?php print $sidebar; ?>
</div>
Additionally I added this in the .info file:
regions[sidebar] = Sidebar
I then created a new block with "Add block" in the admin panel and assigned the created Block to the sidebar. Unfortunately everything i wrote in the block body is not saved and therefore the sidebar does not show any contents. If I update the block body and click on save and go into edit mode to have a look, the block body is empty.
Anybody knows why this happens and how i can solve this?
Thanks.
If this is in your page.tpl.php, you should be using $page['sidebar'] rather than just $sidebar. You also have to call render() on the region. Lastly, it's a good idea to check if it's defined first. For instance:
<?php if($page['sidebar']): ?>
<div id="sidebar">
<?php print render($page['sidebar']) ?>
</div>
<?php endif ?>
Don't forget to clear the cache after adding a new region as well.
See the Bartik theme's page.tpl.php for a more complete example: http://cgit.drupalcode.org/bartik/tree/templates/page.tpl.php.

wordpress custom pre-fixed templates

I want to create a page template that has a pre-fixed css. Lets say I name it page-sevencol.php then I know that the content will have a fixed width and a specific style and so on. My pages have different layouts thats why I need to create these kind of templates.
Is it possible? if so how? Ive looked in the wp codex and it does not seem to have the answer. Please take a minute to help me.
Thank you!
you seem to need just a limited set of templates. The question is: do you want to apply them automatically? Basically, there are two techniques to apply a template to a page (or post or custom post, etc.) in WordPress.
First method: using the template naming convention to get the template automatically applied to a page (or post) with the same name.
In this case, you create a page page-mynewpage.php and this template will automatically get applied to your page named /mynewpage/.
Second method: you create a template by creating a page (let's say : template1.php) and declaring it as a template with a comment at the top of the page:
/**
* Template Name: Template1
*
*/
This template will now be selectable inside the admin of WordPress to be applied to any page:
So if A) you only need a limited set of templates & B) are ok to select them on a per-page basis in the admin, this is your solution. You would just need to create as many pages as you need templates, not forgetting to include the comments that declare them as templates and using a different name each time.
If you need your templates to be applied dynamically, then we need more info about the logic to use for select each template...
EDIT : That is it, Abel (just read your comment). Your page is mainly generated with 4 elements: header.php, sidebar.php, footer.php and another page to produce the content, but this page is different depending on where you are in the site. If you are on a page, it will be, by default, page.php. If you are reading a post, WordPress will by default use single.php.
To apply all your different templates, just go and open page.php in your theme folder. Save it under another name, like page-template7cols.php. Insert a comment like I just explained above, so this template will show in your admin next time you create a new page. Adapt it the way you want (changing the HTML / PHP and therefore adapting the way the content of the page will be displayed). Do the same for your other 9 templates.
Then, everytime you create a new page, just start by selecting the proper template in your dropdown (see previous screen capture). And whenever you will make a change to page-template7cols.php, for example, the changes will be reflected on all pages for which you have selected this template.
/**
Template Name: Template1
*/
<?php get_header(); ?>
<div class="content-wrap sevencol clearfix">
<div class="row clearfix">
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Wordpress 3 plugin to control widget visibility

Coming from a Joomla background one of the fist things I realised is that Wordpress 3 doesn't have native support for controlling the visibility of widgets (modules in Joomla).
I've tried:
Dynamic widgets - http://wordpress.org/extend/plugins/dynamic-widgets/screenshots/ but it seems to break the admin menus.
Also tried Widget context - but it doesn't display correctly and doesn't allow granularity on the page visibility level.
Can anybody recommend a solution?
Try Widget Logic -- http://wordpress.org/extend/plugins/widget-logic/
Hope this helps!
-æ.
You can use Display Widgets. It adds checkboxes to each widget to either show or hide it on every site page: http://wordpress.org/extend/plugins/display-widgets/screenshots/
Make sure to disable other similar plugins to avoid conflict.
Example from sidebar.php:
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
Lets say you want to display this only on a page called "about-us". use is_page() function provided by wordpress.
<?php if(is_page('about-us')) { ?>
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
<?php } ?>
And as for the user level:
<?php if(current_user_can('level_10')) { // Level 10 = Administrator ?>
<div class="sidebar-box border-radius-6px">
<h2>Dream Categories</h2>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
</div><!-- Sidebar Box End -->
<?php } ?>
Please see Wordpress User Levels
PS: I saw the plugin provided by aendrew and I had a look at it.
Try this:
Make a backup of widget_login.php file then open it, search for line 75 and replace it with update_option("widget_logic", "is_page('" . $wl_options . "')"); This should easy up the stuff a little, when you limit a widget you have to add is_page('bla-bla') in that input that line should only require bla-bla (If the page is called Bla Bla) [not tested, but you can give it a try.]
Try this:
http://wordpress.org/extend/plugins/conditional-widgets/
Really user friendly, hope it helps
For anyone still looking for a plugin for this purpose, check out my plugin Widget Visibility.
It's user friendly (uses checkboxes) and works inside the WordPress customizer too.

How to get wordpress plugin "Twitter hash" to show on page

I cannot for my life figure out how to get the downloaded plugin Twitter hash (http://wordpress.org/extend/plugins/twitter-hash-tag-widget/) to show on my index.php page. Read about it and this HTML code was given as an example in many places:
<li id=”twitter">
<ul>
<li><a href=”http://www.site1.com/”>Site One Name</a></li>
</ul>
</li>
But obviously all it does is a HTML list so it shows nothing of how to connect to the widget I have. I also added the file functions.php with the following lines:
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>
and dragged the widget to its place on the wordpress widget page.
All help appreciated for a very new wordpress user!
//Margareta
Right, solved it by using the Kubrick theme instead of the simplified theme that I had used earlier. Now it is showing on the side without me doing anything. Great stuff!

wordpress 3: create navigation menu for a custom post type

Just playing around with Wordpress 3.0 for the first time. I've installed the Custom Post Type UI plugin, and have created a custom post type: "composers".
How do I go about creating a navigation menu for all the composers? Ideally, I'd like a static page entitled 'composers' which has a nav menu of all the individual composers.
In the Appearance -> Menus page, I can create a menu and assign composers individually to it, but what do I need to do to just add the entire collection of composers to a menu, so that it updates when I add a new composer? Surely I don't have to add them all manually?
What you're trying to do might be better achieved as a plugin, or a little editing in your theme file, something along the lines of;
$composers = new WP_Query('post_type=composers');
if ($composers->have_posts():
?>
<ul class="composer-nav">
<?php while ($composers->have_posts()): $composers->the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
I know the idea behind custom menus was to try and avoid the need for plugins or theme editing, but I think it was truly designed for users to be able to pick and choose exactly what they wanted, rather than automatically listing items (just my opinion).

Resources