Display number of posts from database in WordPress

Posted by on Aug 20, 2009 in Wordpress | 0 comments

WordPress does not have a function to do that by default, but with a little work you can get this example. With this code actualy whe will learn wordpress what to count, and to print how many posts are in database.

We are using the $wpdb object to make a custom query to WordPress database:

<?php $numposts = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = ‘publish’”);if (0 < $numposts) $numposts = number_format($numposts);?>

The $numposts variable contains the total number of posts. All whe have to do is to display it ( in sidebar, in content, etc.. ).

<?php echo $numposts.’ has been published in database’; ?>

Read More

WP: display posts from specific categories

Posted by on Aug 7, 2009 in Wordpress | 0 comments

With one simple code, wordpress can display posts from specific categories. WordPress can be modified to actually behave like a very expensive tool and application. Many peoples that use wordpress and actually write daily news and articles in blogs are so called “plugins fans”. Yes plugins are quite interesting and helpful but in many times, installing more plugins can make the blog to load and behave very slow.

The idea of this post is that I can give you an example to use an simple code, instead of an fancy plugin that will cause to load the page very slow, it can be modified very easy using stylesheet.

<?php $recent = new WP_Query("cat=1&showposts=3");
while($recent->have_posts()) : $recent->the_post();?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark"
title="<?php the_title(); ?>">
<?php the_title(); ?>
</a>
</li>

<?php endwhile; ?>
</ul>

Explications:
In the code you will find WP_Query:
cat= is for number of the category;
showposts= number of the post that will be displayed from this category.

Read More

WP: insert images in wordpress template

Posted by on Aug 7, 2009 in Wordpress | 0 comments

Display automaticaly images in wordpress template without “/wp-content/themes/the_theme” In wordpress theme coding becouse of the css stylesheet and the order of the template, images inserted into html files must have the precise like:

wp-content/themes/your-theme/images/image.png

This problem can be solved very easy in an elegant way, by replacing “wp-content/themes/the_theme” patch with:

<?php bloginfo('template_directory'); ?>/images/midCol/search.png

You can integrate it like:

 
<img src="<?php bloginfo('template_directory'); ?>
/images/post/comment.png" alt="comment" width="20" height="20">
Read More

Code in wordpress posts

Posted by on Aug 2, 2009 in Wordpress | 2 comments

If you write about  Javascript, CSS, HTML/XHTML,  and a lot of other code, programming, and calculations, you are going to need to be able to write code in your blog. This is a painful and frustrating process, and you will need some help about it.

Syntax Highlighter WordPress Plugins – can help in writing programing code in wordpress posts/pages/archives.

This plugin highlights and colour-codes all PHP-code in a post given that the PHP-code is wrapped in a code-element. This allows for easy interpretation of code that’s included in a WordPress post as it uses the standard PHP colours for highlighting. The plugin only highlights text that’s enclosed in a code-element and that includes a <?php-tag.

Here is an list of highlighter plugins, useful in posting code over wordpress posts.

The download link:

Read More