Code Snippets
Include tracking code in your header file.
This code also keeps from tracking any admin related activity in WordPress. In the example below, pages that include “preview” or “wp-admin” are excluded. As well, two IP addresses are being excluded.
Located near top of header.php.
<?php
global $wp_query;
$page_id = $wp_query->post->ID;
$url= $_SERVER['PHP_SELF'];
$ip= $_SERVER['REMOTE_ADDR'];
$preview = (@$_GET['preview']) ? $_GET['preview'] : false;
$isWPAdmin = strstr($url, "wp-admin");
$isfhcrc= strstr($ip, "000.111.000.111");
$ishome = strstr($ip, "111.000.000.111");
if((!$isWPAdmin) && (!$preview) && (!$isfhcrc) && (!$ishome))
{
?>
insert javascript here
< ?php } ?>
Display post title following by blog name in bar of browser (great for bookmarking).
Located near bottom of header.php.
< title>
<?php wp_title(''); print_r(" | ");
bloginfo('name'); ?>
</title>
Show category title and description for posts belonging to a category.
If the post is not in a category, the blog title and tag line will display. Located at bottom of header.php.
<h1><?php wp_title(''); ?></h1>
< div class="description">
<?php
if( !is_page() )
{
$category = get_the_category();
echo $category[0]->cat_name;
print_r("
");
echo $category[0]->category_description;
}
else
{bloginfo('description');}
?>
</div>
Include the sidebar for single posts.
In SinglePost.php
<div id="content" class="narrowcolumn">
add the sidebar() above the footer at the bottom:
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Includes not working?
If you’re having problems getting an include to work:
include "somefile.php";
Try this instead:
require_once(dirname(__FILE__) . '\\somefile.php');
Display something depending on the category you are in.
Change 3 to which ever category you are interested in.
<?php if ( in_category('3') ) { ?>
do something
?>
Place a news flash at the top of each posts in a certain category
Add this to the bottom of your header.php file. Then create a PHP file to hold news flash content and upload into your themes\yourtheme folder. The PHP file can be plain text. Using a PHP file for content now allows you to edit the content from Presentation | Theme Editor. Continue adding ORs to the first IF statement for additional categories. Then inside the main IF, add IF statements to handle each category.
<?php if(in_category('3')) { ?>
<div style="background-color: white;
margin: 5px auto;
padding: 5px;
width: 660px;
border: 1px solid #666666;
font-size: 1.2em">
<?php if(in_category('3')){
$content = file_get_contents(TEMPLATEPATH . '/flashSomeCatName.php');
echo $content; }
?>
</div>
<?php } ?>
Remove >> from the title bar and preceding descriptions
Replace occurances of wp_title(); with
wp_title('’);
Categories:





_507.png)
August 17th, 2007 at 10:46 am
Hi,
How did you achieve expandable category list?
Thanks
August 18th, 2007 at 8:59 am
Hi Igor,
This is the expand category code for the sidebar. Hope it helps.