Disabling Plugin Stylesheet

You must have seen that WordPress plugins can slow your site down with additional HTTP Requests such as adding their own stylesheet. For advanced users, who are adding custom styles for the announcement, you do not need to have an additional HTTP request for a useless stylesheet. Then add the following function in your theme’s functions.php file:

<?php
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    function my_deregister_styles() {
    wp_deregister_style( 'ninja-annc-css' );
}
?>
Advertisements

WordPress: Disabling Plugin Stylesheet

You must have seen that WordPress plugins can slow your site down with additional HTTP Requests such as adding their own stylesheet. For advanced users, who are adding custom styles for the announcement, you do not need to have an additional HTTP request for a useless stylesheet. Then add the following function in your theme’s functions.php file:

<?php
add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
    function my_deregister_styles() {
    wp_deregister_style( 'ninja-annc-css' );
}
?>

WordPress 2.9 Post Thumbnail Function

post_thumbnailWordPress 2.9 brings a new function for users of gallery’s the add_theme_support(‘post-thumbnails’) function. with this you will get a new item on your new post window named Post Thumbnail (see right).  After you have added a post Thumbnail to a post, you need to display it.  By using a “gallery” category, creating the below two files (or adding the code to files) and editing your category.php file, you may display a custom gallery page.

To start, create a new file named gallery-function.php and add the following code to it, this file should live in the root of your current theme’s directory.

gallery-function.php

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>gallery-function.css" type="text/css" media="screen" />
<div id="gallerypost-<?php the_ID(); ?>">
    <div id="gallerypost_main-<?php the_ID(); ?>">
	<div id="gallerypost_thumbnail-<?php the_ID(); ?>">
		<?php post_thumbnail(); ?>
	</div>
	<div id="gallerypost_body-<?php the_ID(); ?>">
		<?php $images =& get_children( 'post_type=attachment&post_mime_type=image' ); ?>
		<h2><a rel="bookmark" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
		<div><small>Posted by <?php the_author_posts_link(); ?> on <?php the_time('F jS, Y') ?></small></div>
		<div>
			<?php the_excerpt(); ?>
		</div>
	</div>
    </div>
    <div id="gallerypost_sub-<?php the_ID(); ?>">
	<div id="gallerypost_sub_left-<?php the_ID(); ?>">
		<p><?php echo get_the_term_list( $post->ID, 'people', 'Who: ', ', ', '<br />' ); ?></p>
		<p><?php echo get_the_term_list( $post->ID, 'events', 'What: ', ', ', '<br />' ); ?></p>
             	<p><?php echo get_the_term_list( $post->ID, 'places', 'Where: ', ', ', '' ); ?></p>
	</div>
	<div id"gallerypost_sub_right-<?php the_ID(); ?>">
		This Album contains <?php echo $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type = 'attachment'" ); ?> items.
	</div>
    </div>
</div>

Next create a file named gallery-function.css and also add it to our current theme’s root directory.
gallery-function.css

.gallerypost {
        background-color:#fff;
        display: block;
        hNeight: 300px;
        margin: 0px 0px 10px 0px;
        padding: 20px 10px 10px 10px;
        overflow: hidden;
        border-bottom: 1px solid #D2C4A2;
        }
.gallerypost_body {
        float: right;
        width: 430px;
        margin: 0 20px 0 0;
        }
.gallerypost_body p {
        margin: 50px 0px 0px 0px;
        }
.gallerypost_body .entry p {
        margin: 0px 0px 0px 0px;
        }
.gallerypost_body .entry {
        margin: 0px 0px 0px 0px;
        }
.gallerypost_main {
        width: 690px;
        }
.gallerypost_sub {
        display: block;
        padding: 210px 0px 0px 10px;
        }
.gallerypost_sub {
        display: block;
        padding: 210px 0px 0px 10px;
        }
.gallerypost_sub p {
        vertical-align: bottom;
        margin: 0;
        }
.gallerypost_sub_left {
        width: 220px;
        display: block;
        float: left;
        }
.gallerypost_sub_right {
        width: 220px;
        display: block;
        float: right;
        }
.gallerypost_thumbnail {
        float: left;
        }
.gallerypost_thumbnail img {
        margin: 0 0 0 10px;
        color: #000;
        }

And lastly you will need to add the following to your functions.php file in your current theme’s root directory (you may add it anywhere in functions.php).

add_theme_support('post-thumbnails');
set_post_thumbnail_size(200, 200);

Now that we have our functions built, we need to add some code to your category.php file.

Right after:

<?php while (have_posts()) : the_post(); ?>

Add the following code.  This will display the gallery-function.php code when a post is in the “gallery” category.

<? if ( is_category( 'gallery' )) {
                    include('gallery-index.php');
               } else { ?>

Next Before:

<?php endwhile; ?>

Add the following to close the if statement.

<?php } ?>

And that should do it, you should now see the post image on the gallery category page similar to below.

Gallery-screenshot

Displaying one category on your WordPress main page

If you would like to only display a single category on your WordPress main page, here’s how you do it. You will need to start out by getting ID of the category you wish to display.   In WordPress 2.7+,  start out by going to your categories tab under posts(1), then hover over the category you would like to display in your post(2), don’t click on it, just hover over it.  On the bottom of your screen, you will be shown then URL of the category your hover over(3), remember the ID number that being displayed.   In the below example the number we need to remember is “23”.

Getting Category id

After you have gotten your categories ID number, you will next need to change your index.php file.  In your index.php file look for the line with “have_post” and add the below code after.

<?php if (have_posts()) : ?>; Look for this line and add below
<?php query_posts('showposts=10&amp;;cat=23'); ?>;
<?php while (have_posts()) : the_post(); ?>;

Last, change “cat” to the category id from above. “showposts” is the number of posts to display on the page.

Displaying one category on your WordPress main page

If you would like to only display a single category on your WordPress main page, here’s how you do it. You will need to start out by getting ID of the category you wish to display.   In WordPress 2.7+,  start out by going to your categories tab under posts(1), then hover over the category you would like to display in your post(2), don’t click on it, just hover over it.  On the bottom of your screen, you will be shown then URL of the category your hover over(3), remember the ID number that being displayed.   In the below example the number we need to remember is “23”.

Getting Category id

After you have gotten your categories ID number, you will next need to change your index.php file.  In your index.php file look for the line with “have_post” and add the below code after.

<?php if (have_posts()) : ?> //Look for this line and add below
<?php query_posts('showposts=10&;cat=23'); ?>
<?php while (have_posts()) : the_post(); ?>

Last, change “cat” to the category id from above. “showposts” is the number of posts to display on the page.