wordpress Facebook “Like” Button for WordPress

by in , 0

Some very easy copy-and-paste code here to add to the template for blog posts to allow for Facebook "liking" of the article. Probably best in the single.php template underneath where it outputs the content of the post.

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo rawurlencode(get_permalink()); ?>&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" id="facebook-like"></iframe>

wordpress Enable All Possible Post Formats

by in , 0

For your functions.php file in the theme.

add_theme_support( 'post-formats', 
	array( 
		'aside', 
		'gallery',
		'link',
		'image',
		'quote',
		'status',
		'video',
		'audio',
		'chat'
	) 
);
add_post_type_support( 'post', 'post-formats' );
add_post_type_support( 'page', 'post-formats' );
// and other custom post types if you have them

Reference URL

wordpress Embed a Page inside a Page

by in , 0

<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_content(); ?>
<?php endwhile; ?>

The above code can be used within the regular page loop. Replace **ID** with the ID of the page you wish to embed.

wordpress Dynamic Title Tag

by in , 0

<title>
   <?php 
      if (function_exists('is_tag') && is_tag()) { 
         single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; } 
      elseif (is_archive()) { 
         wp_title(''); echo ' Archive - '; } 
      elseif (is_search()) { 
         echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; } 
      elseif (!(is_404()) && (is_single()) || (is_page())) { 
         wp_title(''); echo ' - '; } 
      elseif (is_404()) { 
         echo 'Not Found - '; } 
      if (is_home()) { 
         bloginfo('name'); echo ' - '; bloginfo('description'); } 
      else {
          bloginfo('name'); }
      if ($paged>1) { 
         echo ' - page '. $paged; } 
   ?>
</title>

Reference URL

wordpress Dump All Custom Fields

by in , 0

WordPress has a built in function, the_meta(), for outputting all custom fields. But this function is limited in that it doesn't always output all of them. For example, it misses custom fields added by plugins which begin with an _ underscore.

This bit of code uses an alternate function, get_post_custom() which will return all of them, and display all values. Good for debugging.

<h3>All Post Meta</h3>

<?php $getPostCustom=get_post_custom(); // Get all the data ?>

<?php
    foreach($getPostCustom as $name=>$value) {

        echo "<strong>".$name."</strong>"."  =>  ";

        foreach($value as $nameAr=>$valueAr) {
                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo $nameAr."  =>  ";
                echo var_dump($valueAr);
        }

        echo "<br /><br />";

    }
?>

Reference URL

wordpress Display Post Divider In Between Posts

by in , 0

Right before the closing of the The Loop, insert this code:

<?php
if (($wp_query->current_post + 1) < ($wp_query->post_count)) {
   echo '<div class="post-item-divider">Post Divider</div>';
}
?>

This will create a <div> you can style as a post divider. The cool part being, it only gets inserted between two posts, skipping the last one. Thanks to Craig Maclean.

wordpress Display Image Next To Each Tag

by in , 0

<?php
$posttags = get_the_tags(); // Get articles tags
$home = get_bloginfo('url'); // Get homepage URL

// Check tagslug.png exists and display it
if ($posttags) {
 foreach($posttags as $tag) {
       $image = "http://cdn.css-tricks.com/images/tag-images/$tag->slug.png";

       if (file_exists("images/tag-images/$tag->slug.png")) {
         echo '<a href="' . $home . '/tag/' . $tag->slug . '" /><img title="' . $tag->name . '" alt="' . $tag->name . '" src="' . $image . '" /></a>';

       // If no image found, output something else, possibly nothing.
       } else {
         echo '<p>Not found</p>';
       }
  }
}
?>

This code belongs inside the loop. It will look in a specific directory for any images that match the slugs of article tags, display them and link them to the relevant tag archive.