2013最も実用的なWordpressテクニック、コードクリップ
2013最も実用的なWordpressテクニック、コードクリップ
2013年のWordpressは急速に発展した.様々なフォーラムには優秀なコードクリップがたくさんあります.私はここで私の好きないくつかのテクニックと断片を整理して、すべてのWordpress開発者にあげます.
ズームではなくクリップを使用してアップロードされた画像を処理
Wordpressでアップロードした画像を適切なサイズにカットして、適切なサイズにスケールするのではなく、適切なサイズにしたいと思っていますか?そうしたいなら、次のコードを見てください.
コードクリップをfunctionsに追加する.phpこのファイルでは:
コードクリップをfunctionsに追加する.phpこのファイルでは:
プラグインを使用せずにwp_をクリーンアップhead()
WordPressの通過wp_head()は多くのものを増やした.多くのトピックもこの関数に関連付けられます.しかし、全く使えないものもあります.ここには無駄な内容を整理できる簡単な整理方法があります.コードクリップをfunctionsに追加する.phpこのファイルでは:
強制ページsslリンクの使用
サーバでsslが有効になっている場合は、次のコードでページにsslでアクセスするように指定できます.コードクリップをfunctionsに追加する必要がありますphpこのファイルでは、特殊なページのidを指定します.
Wordpress以外でのページのループアクセス
WPの外では、文章情報にアクセスする必要があります.ここでは、wp以外の他のphpファイルで文章情報にアクセスするのに役立ちます.以下のコードをアクセスする必要があるphpページの下に置きます.ライン4:WordPress wp-blog-header.phpファイルの正しいパスを入力します.line 5:query_を通過posts()は、必要な情報を取得する.
2013年のWordpressは急速に発展した.様々なフォーラムには優秀なコードクリップがたくさんあります.私はここで私の好きないくつかのテクニックと断片を整理して、すべてのWordpress開発者にあげます.
ズームではなくクリップを使用してアップロードされた画像を処理
Wordpressでアップロードした画像を適切なサイズにカットして、適切なサイズにスケールするのではなく、適切なサイズにしたいと思っていますか?そうしたいなら、次のコードを見てください.
コードクリップをfunctionsに追加する.phpこのファイルでは:
// Standard Size Thumbnail
if(false === get_option("thumbnail_crop")) {
add_option("thumbnail_crop", "1"); }
else {
update_option("thumbnail_crop", "1");
}</p>
<p>// Medium Size Thumbnail
if(false === get_option("medium_crop")) {
add_option("medium_crop", "1"); }
else {
update_option("medium_crop", "1");
}</p>
<p>// Large Size Thumbnail
if(false === get_option("large_crop")) {
add_option("large_crop", "1"); }
else {
update_option("large_crop", "1");
}
ソース:[weblink url=]http://wp-snippet.com/snippets/activate-cropping-for-all-thumbnail-sizes/「]cropping-for-all-thumbnail[/weblink]##Wordpressでtwitterユーザー名を自動的にリンクコードクリップをfunctionsに追加する.phpこのファイルでは:
function twtreplace($content) {
$twtreplace = preg_replace('/([^a-zA-Z0-9-<em>&])@([0-9a-zA-Z</em>]+)/',"$1<a href=\\"http://twitter.com/$2\\" target=\\"_blank\\" rel=\\"nofollow\\">@$2</a>",$content);
return $twtreplace;
}</p>
<p>add_filter('the_content', 'twtreplace'); <br />
add_filter('comment_text', 'twtreplace');
ソース:[weblink url=]http://snipplr.com/view/70977/automatically-link-twitter-usernames-in-wordpress/"]automatically-link-twitter[/weblink] プラグインを使用せずにwp_をクリーンアップhead()
WordPressの通過wp_head()は多くのものを増やした.多くのトピックもこの関数に関連付けられます.しかし、全く使えないものもあります.ここには無駄な内容を整理できる簡単な整理方法があります.コードクリップをfunctionsに追加する.phpこのファイルでは:
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'start_post_rel_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
ソース:[weblink url=]http://www.themelab.com/remove-code-wordpress-header/"]remove-code-wordpress-header[/weblink] 強制ページsslリンクの使用
サーバでsslが有効になっている場合は、次のコードでページにsslでアクセスするように指定できます.コードクリップをfunctionsに追加する必要がありますphpこのファイルでは、特殊なページのidを指定します.
function wps_force_ssl( $force_ssl, $post_id = 0, $url = '' ) {
if ( $post_id == 25 ) {
return true
}
return $force_ssl;
}
add_filter('force_ssl' , 'wps_force_ssl', 10, 3);
ソース:[weblink url=]http://wpsnipp.com/index.php/functions-php/force-specific-pages-to-be-secure-ssl-https/"]specific-pages-https[/weblink] Wordpress以外でのページのループアクセス
WPの外では、文章情報にアクセスする必要があります.ここでは、wp以外の他のphpファイルで文章情報にアクセスするのに役立ちます.以下のコードをアクセスする必要があるphpページの下に置きます.ライン4:WordPress wp-blog-header.phpファイルの正しいパスを入力します.line 5:query_を通過posts()は、必要な情報を取得する.
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
query_posts('posts_per_page=1');
?></p>
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
<?php endwhile; ?>
ソース:[weblink url=]http://css-tricks.com/snippets/wordpress/run-a-loop-outside-of-wordpress/"]loop-outside-of-wordpresss[/weblink]