Created
March 2, 2011 02:34
-
-
Save nojimage/850365 to your computer and use it in GitHub Desktop.
WPでソーシャルボタンをハードに追加するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ..snip.. */ | |
/* ここでは df_social として関数を定義していますけど適当な名前でOKです */ | |
function df_social() { | |
?> | |
<div class="socialLink"> | |
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="<?php the_permalink(); ?>" data-text="<?php the_title(); ?>" data-via="nojimage">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> | |
<a href="http://b.hatena.ne.jp/entry/<?php the_permalink(); ?>" class="hatena-bookmark-button" data-hatena-bookmark-title="<?php the_title(); ?>" data-hatena-bookmark-layout="standard" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script> | |
<iframe src="http://www.facebook.com/plugins/like.php?href=<?= urlencode(get_permalink()) ?>&layout=button_count&show_faces=true&width=120&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px;" allowTransparency="true"></iframe> | |
</div> | |
<?php | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php get_header(); ?> | |
<div id="content"> | |
<?php if (have_posts()) : ?> | |
<div class="content-header"><?php include('includes/content-header.inc.php'); ?></div> | |
<?php while (have_posts()) : the_post(); ?> | |
<div class="post" id="post-<?php the_ID(); ?>"> | |
<h2> | |
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'default'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a> | |
</h2> | |
<div class="postmetadata"> | |
<?php df_get_postmetadata( array( "date", "author", "comment" ), 'span' ); ?> | |
</div> | |
<?php df_social(); /* 記事パーツ中で functions.php で定義した関数を読み出し */ ?> | |
<div class="entry"> | |
<?php the_content(); ?> | |
</div> | |
<div class="postmetadata"> | |
<?php df_get_postmetadata( array( "category", "tag", "edit" ), 'span' ); ?> | |
</div> | |
</div><!-- end of post --> | |
<?php endwhile; ?> | |
<?php df_pagenavigator('<div id="pagenavigator">', '</div>'); ?> | |
<?php else : /* NO posts */ | |
if ( '' != get_404_template() ) | |
include( get_404_template() ); | |
else | |
echo( "<h3><?php _e( 'Upss, not found...', 'default' ); ?></h3>" ); | |
endif; ?> | |
</div><!-- end #content --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp-content/themes/{some_theme_name}/functions.php にボタンを表示するための関数を追記で定義します。
( twitterのdata-via属性とかは適当に書き換えてね
あとは、
wp-content/themes/{some_theme_name}/index.phpやsingle.phpなど、各テンプレートの表示させたい部分で、functionで定義したボタン表示関数を読み出すようにします。
こんなことを自動するプラグインもあるだろうけど。。