- - - --

Thursday, September 22, 2011

خندون دات آی آر

خندون دات آی آر


سفارشی سازی قالب های وردپرس برای همه

Posted: 26 Aug 2011 03:54 PM PDT

Customize wordpress سفارشی سازی قالب های وردپرس برای همه

افرادی که برای اولین بار اقدام به راه اندازی یک وبگاه با سیستم مدیریت محتوای وردپرس می کنند اگر بخواهند تا قالب مخصوص به خود را داشته باشند ناچارند یا اقدام به طراحی قالب کنند که منطقا کار ساده ای نیست و یا یک راه راحت تر که ویرایش و سفارشی سازی قالب های موجود را در پیش می گیرند. پس بر آن شدم تا مجموعه ای نسبتا کامل از کدهایی که هر طراحی مطمئنا برای سفارشی سازی خود نیاز دارد را  آماده کنم تا کمی از دغدغه های افراد مشتاق برای حضور در این عرصه کم شود. شما هم اگر کد های دیگری مد نظرتان است که در اینجا آورده نشده است و لازم می دانید که اضافه شود می توانید در قسمت نظرات ارسال کنید تا اضافه شود. 

کدها به شرح زیر است:

نمایش ارسال های جدید

برای تغییر تعداد می توانید عدد ۵ را تغییر را دهید:

<?php query_posts('showposts=5'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul>

نمایش به آخرین بروزرسانی های پست و صفحات

<?php $today = current_time('mysql', 1); $howMany = 5; //Number of posts you want to display if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")): ?> <h2><?php _e("Recent Updates"); ?></h2> <ul> <?php foreach ($recentposts as $post) { if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID); echo "<li><a href='".get_permalink($post->ID)."'>"; the_title(); echo '</a></li>'; } ?> </ul> <?php endif; ?>

نمایش آخرین نظرات

<?php global $wpdb; $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; $output .= "\n<ul>"; foreach ($comments as $comment) { $output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."</a></li>"; } $output .= "\n</ul>"; $output .= $post_HTML; echo $output;?>1  نمایش برترین مطالب  1<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");  foreach ($result as $topten) {  $postid = $topten->ID;  $title = $topten->post_title;  $commentcount = $topten->comment_count;  if ($commentcount != 0) { ?>  <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>  <?php } } ?>

ویا به صورت زیر کد زیر را در فایل functions.php قرار دهید:

<?php function popularPosts($num) { global $wpdb;   $posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");   foreach ($posts as $post) { setup_postdata($post); $id = $post->ID; $title = $post->post_title; $count = $post->comment_count;   if ($count != 0) { $popular .= '<div>'; $popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '">' . $title . '</a> '; $popular .= '</div>'; $popular .= '<div></div>'; } wp_reset_query(); } return $popular; } ?>

برای نمایش از کد زیر استفاده کنید:

<?php echo popularPosts(5); ?>

برای تغییر تعداد می توانید عدد ۵ را تغییر را دهید. نمایش موضوعات در سایدبار

<h2>Categories</h2> <ul> <?php wp_list_cats('sort_column=name'); ?>  </ul>

نمایش موضوعات به صورت لیست بازشو

<form action="<?php bloginfo('url'); ?>/" method="get"> <?php $select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0'); $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?> <noscript><input type="submit" value="View" /></noscript> </form>

نمایش بایگانی

<h2>Archives</h2> <ul> <?php wp_get_archives('type=monthly'); ?> </ul>

نمایش بایگانی سایت به صورت لیست بازشو

<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'> <option value=\"\"><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>

نمایش برگه ها در نوار کناری

<h2>Pages</h2> <ul> <?php wp_list_pages('title_li='); ?> </ul>

نماش آواتار در نظرات
[

<?php echo get_avatar( get_the_author_email(), '80' ); ?>[/php نمایش لینک دوستان 1<ul> <?php get_links_list(); ?> </ul>

نمایش بخش مدیریت

<ul> <?php wp_register(); ?> <li><?php wp_loginout(); ?></li> <li><a href="http://www.wordpress.org/">WordPress</a></li> <?php wp_meta(); ?> <li><a href="http://validator.w3.org/check?uri=referer">XHTML</a></li> </ul>

نمایش برگه و زیر برگه در نوار کناری

<?php$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');if ($children) { ?><ul> <?php echo $children; ?> </ul> <?php } ?>

نمایش برچسب های وردپرس

<?php the_tags(); ?>[p/php] نمایش ابر برچسب ها 1<?php wp_tag_cloud('smallest=8&largest=36&'); ?>

نام قالباین دستور به شما اجازه می دهد تا قالب سفارشی برای برگه ها ایجاد کنید:

<?php /* Template Name: Portfolio */ ?>

عنوان دینامیک

<title><?phpif (is_home()) { echo bloginfo('name'); } elseif (is_404()) { echo '404 Not Found'; } elseif (is_category()) { echo 'Category:'; wp_title(''); } elseif (is_search()) { echo 'Search Results'; } elseif ( is_day() || is_month() || is_year() ) { echo 'Archives:'; wp_title(''); } else { echo wp_title(''); } ?></title>

نمایش PHP بر روی یک صفحهجایگزین کردن خانه با یک برگه دلخواه شما :

<?php if ( is_home() ) { include ('file.php'); } ?>

نمایش خوراک RSS خارجی

<?php include_once(ABSPATH.WPINC.'/rss.php'); wp_rss('your_url', 5); ?>

نمایش آخرین ورودی توییتر

<?php // Your twitter username. $username = "TwitterUsername"; // Prefix - some text you want displayed before your latest tweet. // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\") $prefix = ""; // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) $suffix = ""; $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet = str_replace(">", ">", $tweet); return $tweet; } $twitterFeed = file_get_contents($feed); echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); ?>

نمایش مطالب تصادفی

<?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) { ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </li> <?php } ?>

برای تغییر تعداد پست ها عدد ۵ را تغییر دهید. برای گذاشتن آمار سایت توسط افزونه statpresscn در قالب از کد زیر استفاده کنید

<li><?php StatPress_Print(" اسم: کد"); ?></li>

برای مثال:

<li><?php StatPress_Print(" افراد آنلاین: %visitorsonline%"); ?></li>  <li><?php StatPress_Print(" بازدید امروز: %pagevisits%"); ?></li>  <li><?php StatPress_Print(" بازدید دیروز: %yesterdaypagevisits%"); ?> </li>  <li><?php StatPress_Print(" کل بازدیدها: %totalpagevisits%"); ?></li>  <li><?php StatPress_Print(" آی پی: %ip%"); ?></li>  <li><?php StatPress_Print(" سیستم عامل شما: %os%"); ?></li>  <li><?php StatPress_Print(" مرورگر شما: %browser%"); ?></li>  <li><?php StatPress_Print(" بیشترین آمارمرورگر: %topbrowser%"); ?></li>

نمایش مطالب مرتبط بر اساس موضوع

<?php $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'showposts'=>5, // Number of related posts that will be shown. 'caller_get_posts'=>1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo '<h3>بدنیست بخوانید:</h3><ul>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <li><img src="<?php bloginfo('url'); ?>/wp-content/themes/mha/images/footer_arrow.gif" /> <a href="<?php the_permalink() ?>" rel="bookmark" title="خواندن مطلب <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php } echo '</ul>'; } else { echo '<h2>مطلبی یافت نشد.</h2>'; } } $post = $backup; wp_reset_query(); ?>

پ.ن:این پست به مرور زمان کامل می شود.

0 comments:

Post a Comment