Thursday, July 15, 2010

Post Pic Add a login form on your WordPress Theme

Are you using WordPress as a cms or as a community site? If yes, it can be a cool idea to display a login form in your blog sidebar or on a specific page. Here’s a simple code to do it.
Nothing hard at all. Simply paste the following code where you'd like to display your login form. (For example, on your blog sidebar, or on a page template)

<?php if (!(current_user_can('level_0'))){ ?> 
<h2>Login</h2>
<form action="<?php echo get_option('home');
?>/wp-login.php" method="post">
<input type="text" name="log"
id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>"
size="20" />
<input type="password" name="pwd" id="pwd" size="20" />
<input type="submit" name="submit" value="Send" class="button" />
<p>
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox"
checked="checked" value="forever" /> Remember me</label>
<input type="hidden" name="redirect_to"
value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
</p>
</form>
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">
Recover password</a> <?php } else { ?>
<h2>Logout</h2>
<a href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>">
logout</a><br />
<a href="http://XXX/wp-admin/">admin</a>
<?php }?>

Once saved, your theme will display a login form. Definitely easier and quicker for login!

Post Pic Display all thumbs related to a specific page on a media page in WordPress

Today, here is a nice piece of code to display all thumbs related to a specific page on a media pages. Very nice for galleries!
Simply paste the following function into your functions.php file:

function wallthumb($id=false,$beforelist='
<ul class="gallerythumb">',$afterlist='</ul>',$beforeitem='<li>',$afteritem='</li>')
{
global $wp_query;
$goquery = $wp_query->post;//contenu de la requète
if(is_attachment()){
$ptitre = $goquery->post_title;//le titre de l'image
$idparent = $goquery->post_parent;//l'id de la page parente
if(!$id){//si pas d'id en argument, on tente de la recuperer
$id = $goquery->ID;
}
if($idparent == null || $idparent == '' || $idparent == 0){
return;//si l'image est orpheline (sans page parente) on stop la fonction
}

//$twice = get_posts('post_type=attachment&post_mime_type=image&numberposts=-1&order=ASC&post_status=null&post_parent='.$idparent);//recup des infos des pièces jointes a la page parente
$twice = get_children('post_type=attachment&post_mime_type=image&order=ASC&post_parent='.$idparent);//recup des infos des pièces jointes a la page parente
$stocklienimage = array();//pour stocker les liens images
if($twice){//si pièces jointes
foreach ($twice as $value) {//boucle
$classthumbactu = '';
if($value->ID == $id){
//detection de l'image courante dans la boucle pour ajout d'une classe pour la differencier
$classthumbactu=' thumbactu';
}
$stocklienimage[$value->ID] = $beforeitem.'<a class="wallthumb'.$classthumbactu.'" href="'.get_attachment_link($value->ID).'" title="'.wp_specialchars( get_the_title($value->ID), 1 ).'" rel="attachment">'.wp_get_attachment_image( $value->ID, 'thumbnail' ).'</a>'.$afteritem;
}
}
else{

return;
}
echo $beforelist.implode('', $stocklienimage).$afterlist;//affichage de la liste
}
}
Once done, you just have to call the function:
<?php wallthumb() ?>

WordPress hack : Automatically output the content in two columns


Printed magazines often display text in columns, so why blogs shouldn’t be able to do the same? Juste read on to find out how to easily and automatically display your post content in columns

This code is poweful but definitely easy to implement. Just paste it on your functions.php file and it will automatically output your post content in columns.
Your post content will be splitted on

tags.
function my_multi_col($content){
$columns = explode('<h2>', $content);
$i = 0;
foreach ($columns as $column){
if (($i % 2) == 0){
$return .= '<div class="content_left">' . "\n";
if ($i > 1){
$return .= "<h2>";
} else{
$return .= '<div class="content_right">' . "\n <h2>";
}
$return .= $column;
$return .= '</p></div>';
$i++;
}
if(isset($columns[1])){
$content = wpautop($return);
}else{
$content = wpautop($content);
}
echo $content;
}
}
add_filter('the_content', 'my_multi_col');
Don't forget to add the following styles to your style.css file
.content_right, .content_left{
float:left;
width:45%;
}

.content_left{
padding-right:5%;
}


Display the number of tweets for each page or post

Twitter is a very cool tool, especially if you’re a blogger. Using some php it is easy to display how many times a specific blog post has been tweeted. This is what you’re going to learn in this recipe.
To apply this hack, you have to make sure that the SimpleXML PHP extension is loaded. If you're using WpWebHost or HostGator, it is.

The first step is to place the following piece of code in your functions.php file:
function tweetCount($url) { 
$content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
$element = new SimpleXmlElement($content);
$tweets = $element->story->url_count;
echo $tweets." tweets!";
}


Once done, open your single.php file and call the function like this:
<?php tweetCount($post->permalink); ?>

WordPress tip: Send article to a friend by email



Post Pic
WordPress tip: Send article to a friend by email

In order to create more traffic on your blog, it can be a good idea to let your readers send your posts to their friends by email. A few month ago, I already shown you a function to do that, here is an improved version for today.

To apply this recipe to your blog, simply paste the following function into your functions.php file, and that's all. Hard to do something simpler!
function direct_email($text="Send by email"){   
global $post;
$title = htmlspecialchars($post->post_title);
$subject = 'Sur '.htmlspecialchars(get_bloginfo('name')).' : '.$title;
$body = 'I recommend this page : '.$title.'. You can read it on : '.get_permalink($post->ID);
$link = '<a rel="nofollow"
href="mailto:?subject='.rawurlencode($subject).'&amp;body='.rawurlencode($body).'"
title="'.$text.' : '.$title.'">'.$text.'</a>';
return $link;
}

Customize WordPress login logo without a plugin


WordPress login logo looks nice, but sometimes you may want to change it, for example when building a site for a client. In that case, you can use a plugin, or simply take advantage of this cool hack
Nothing hard with this recipe. The only thing you have to do is to copy the following piece of code, and paste it on your functions.php file:

function my_custom_login_logo() { 
echo '<style type="text/css">
h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
</style>'; }
add_action('login_head', 'my_custom_login_logo');

How to remove “private” and “protected” from the post title

Each time you define a specific post as being private or password-protected, WordPress automatically add “Private” or “Protected” to your blog post title. If you don’t want it, nothing simpler: Just apply this great hack.

The only thing you have to do is to paste the following piece of code in your functions.php file. Once you'll save the file, the hack will be applied to your your posts.
function the_title_trim($title) {
$title = attribute_escape($title);
$findthese = array(
'#Protected:#',
'#Private:#' );
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with );
$title = preg_replace($findthese, $replacewith, $title);
return $title;
}
add_filter('the_title', 'the_title_trim');

Post Pic How to display an incrementing number next to each published post

The first thing to do is to paste the function into your functions.php file:

function updateNumbers()
{ global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 0 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach; endif;
}
add_action ( 'publish_post', 'updateNumbers' );
add_action ( 'deleted_post', 'updateNumbers' );
add_action ( 'edit_post', 'updateNumbers' );
Once done, you can display the post nimber by pasting the following on

your theme file, within the loop:

<?php echo get_post_meta($post->ID,'incr_number',true); ?> 

Display list of wordpress pages in two columns

<?php

$page_s = explode("</li>",wp_list_pages('title_li=&echo=0&depth=1&style=none'));

$page_n = count($page_s) - 1;

$page_col = round($page_n / 2);

for ($i=0;$i<$page_n;$i++){

 if ($i<$page_col){

  $page_left = $page_left.''.$page_s[$i].’</li>’;

 }

 elseif ($i>=$page_col){

  $page_right = $page_right.”.$page_s[$i].’</li>’;

 }

}

?>

<ul class=”left”>

<?php echo $page_left; ?>

</ul>

<ul class=”right”>

<?php echo $page_right; ?>

</ul>


.right {float:left; width:200px;}

.left {float:left; width:200px;}



.right {float:left; width:200px;}
.left {float:left; width:200px;}

Display your categories in two columns

The stadard wp_list_categories() functions echoes a list of all your categories. Let’s see how we can easily force the display of categories on two columns.

<?php

$cats = explode("<br />",wp_list_categories('title_li=&echo=0&depth=1&style=none'));

$cat_n = count($cats) - 1;

$cat_col = round($cat_n / 2);

for ($i=0;$i<$cat_n;$i++){

if ($i<$cat_col){

$cat_left = $cat_left.'<li>'.$cats[$i].’</li>’;

}

elseif ($i>=$cat_col){

$cat_right = $cat_right.’<li>’.$cats[$i].’</li>’;

}

}

?>

<ul class=”left”>

<?php echo $cat_left;?>

</ul>

<ul class=”right”>

<?php echo $cat_right;?>

</ul>

.right {float:left; width:200px;}

.left {float:left; width:200px;}

WordPress and Conditional Comment CSS

<!--[if condition]>
(what to output if the condition is true) <![endif]-->

Specific Examples


<!--[if IE]>[...]<![endif]-->

If the browser is Internet Explorer (any version)


<!--[if IE 7]>[...]<![endif]-->

If the browser is Internet Explorer 7


<!--[if lt IE 7]>[...]<![endif]-->

If the browser is less than Internet Explorer 7


<!--[if lte IE 7]>[...]<![endif]-->

If the browser is less than, or equal to, Internet Explorer 7


<!--[if gte IE 6]>[...]<![endif]-->

If the browser is greater than, or equal to, Internet Explorer 6


<!--[if gt IE 6]>[...]<![endif]-->

If the browser is greater than Internet Explorer 6


<!--[if IE]>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/ie.css"
media="screen" type="text/css" />
<![endif]-->

<!--[if lte IE 7]> <link rel="stylesheet"
href="<?php bloginfo('template_directory'); ?>/ie7.css"
media="screen" type="text/css" /><![endif]-->

 


<!--[if lte IE 7]>
<script src="<?php bloginfo('template_directory'); ?>/focus.js"
type="text/javascript"></script><![endif]-->

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"
type="text/css" media="screen" /><!--[if IE 7]>
<link rel="stylesheet"
href="<?php bloginfo('template_directory'); ?>/ie7.css" media="screen"
type="text/css" /><![endif]-->

http://wordpress.org/support/topic/417213
http://www.code-styling.de/english/development/wordpress-plugin-page-columnist-en

Wednesday, July 14, 2010

image is within your theme

<?php bloginfo('template_url'); ?>/images/button.jpg" border="0"/>



Feed:
http://codex.wordpress.org/WordPress_Feeds

Tuesday, July 6, 2010

Dynamic Menu Highlighting


if you use the Pages sidebar widget (that comes with wordpress) to display your menu, it already has a CSS class current_page_item, which you can use to achieve the same effect. You can access it like this in your CSS:
.widget_pages li.current_page_item a{
background-image:url(images/activelink.gif);
}

<ul id="menu"> 
<!-- To show "current" on the home page -->
<li<?php if (is_home())
{
echo " id=\"current\"";
}?>>
<a href="<?php bloginfo('url') ?>">Home</a>
</li>
<!-- To show "current" on the Archive Page (a listing of all months and categories),
individual posts, but NOT individual posts in category 10 -->
<li<?php if (is_page('Archive') || is_single() && !in_category('10'))
{
echo " id=\"current\""; }?>>
<a href="<?php bloginfo('url') ?>/archive">Archive</a> </li>
<!-- To show "current" on any posts in category 10, called Design -->
<li<?php if (is_category('Design') || in_category('10') && !is_single())
{ echo " id=\"current\""; }?>>
<a href="<?php bloginfo('url') ?>/category/design">Design</a> </li>
<!-- To show "current" on the About Page -->
<li<?php if (is_page('About'))
{
echo " id=\"current\""; }?>>
<a href="<?php bloginfo('url') ?>/about">About</a>
</li> </ul>
#current
{
background-color: #336699;
}

Friday, July 2, 2010

Applying different formatting to just the first post on the first page

<?php if (have_posts()) : ?>
<?php $post = $posts[0]; $c=0;?>
<?php while (have_posts()) : the_post(); ?>
<?php $c++; if( $c == 1) :?>
<h1>The first post on the main index page</h1>
<?php the_title(); ?> <?php the_excerpt(); ?>
<?php else :?> <h2><?php the_title(); ?></h2>
<?php the_content(); ?> <?php endif;?>
<?php endwhile; ?> <!-- page nav -->


More -->
http://wordpress.org/support/topic/302408?replies=6

show me more than the post really in the current category

if ( is_single() ) {  
$cats = wp_get_post_categories($post->ID);
if ($cats) { $first_cat = $cats[0];
$args=array( 'cat' => $first_cat, //cat__not_in wouldn't work
'post__not_in' => array($post->ID), 'showposts'=>5,
'caller_get_posts'=>1 ); $my_query = new WP_Query($args);
if( $my_query->have_posts() ) { echo 'Related Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></p>
<?php endwhile; } //if ($my_query) } //if ($cats)
wp_reset_query(); // Restore global post data stomped by the_post().
} //if (is_single())
?>


More--->
http://wordpress.org/support/topic/310930