انجمن


فراخوانی تصاویر شاخص از یک فولدر خاص؟  (۱ نوشته)

  • abbas khoshnazar

    آفلاین
    عضو
    تعداد نوشته‌ها: ۶
    # نوشته شده: ۱۰ سال پیش
    ۹ مرداد ۱۳۹۲ - ۰۴:۴۲

    سلام
    من یک موضوعی رو از یک طراح شنیدم که بهم گفت اگر بخوای میتونم برات کاری انجام بدم که به جای اینکه وردپرس عکس اول سایتتو از تصویر شاخص که همون عکس اول هر پست هست برداره به اندازه (220 در 220 ) که اندازه تعریف شده تو قالبم هست ریسایز کنه ، خودت عکساتو دقیقا ریسایز کنی به همون اندازه و اسم هر عکس هم باشه عدد ID اون پست و فقط بره از فولدر مربوطه بخونه و قرار بده.

    مثلا لینک مطالب من اینجوریه :
    http://www.example.com/?p=1430
    حالا من عکسامو ریسایز و کراپ کردم و همرو به اسمهای p=*** تغییر دادم و تو یه فولدر تو هاستم ریختم.
    من در حال حاظر از توابع زیر تو فانکشنم استفاده میکنم :

    <?php
    //widget ready
    if ( function_exists('register_sidebar') )
    	register_sidebar(array(
    	'before_widget' => '<div class="sidewidget">',
    	'after_widget' => '</div>',
    	'before_title' => '<div class="sidetitle"><h2>',
    	'after_title' => '</h2></div>',
    ));
    // retreives image from the post
    function getImage($num) {
    global $more;
    $more = 1;
    $content = get_the_content();
    $count = substr_count($content, '<img');
    $start = 0;
    for($i=1;$i<=$count;$i++) {
    $imgBeg = strpos($content, '<img', $start);
    $post = substr($content, $imgBeg);
    $imgEnd = strpos($post, '>');
    $postOutput = substr($post, 0, $imgEnd+1);
    $image[$i] = $postOutput;
    $start=$imgEnd+1;  
    
    $cleanF = strpos($image[$num],'src="')+5;
    $cleanB = strpos($image[$num],'"',$cleanF)-$cleanF;
    $imgThumb = substr($image[$num],$cleanF,$cleanB);
    
    }
    if(stristr($image[$num],'<img')) { echo $imgThumb; }
    $more = 0;
    }
    //retreive image ends
    
    //page
    function custom_wp_pagenavi($prelabel = '', $nxtlabel = '', $pages_to_show = 10, $always_show = false) {
    	global $request, $posts_per_page, $wpdb, $paged;
    	if(empty($prelabel)) {
    		$prelabel  = '<strong>&laquo;</strong>';
    	}
    	if(empty($nxtlabel)) {
    		$nxtlabel = '<strong>&raquo;</strong>';
    	}
    	$half_pages_to_show = round($pages_to_show/2);
    	if (!is_single()) {
    		if(!is_category()) {
    			preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
    		} else {
    			preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
    		}
    		$fromwhere = $matches[1];
    		$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    		$max_page = ceil($numposts /$posts_per_page);
    		if(empty($paged)) {
    			$paged = 1;
    		}
    		if($max_page > 1 || $always_show) {
    			echo "<div class=\"pagination\"><ul><li><a href=\"#\" class=\"prevnext pages\">صفحه $page از $max_page</a></li>";
    			if ($paged >= ($pages_to_show-1)) {
    				echo '<a href="'.get_pagenum_link().'">&laquo; First</a> ... ';
    			}
    			previous_posts_link($prelabel);
    			for($i = $paged - $half_pages_to_show; $i  <= $paged + $half_pages_to_show; $i++) {
    				if ($i >= 1 && $i <= $max_page) {
    					if($i == $paged) {
    						echo "<li><a href=\"#\" class=\"currentpage\">$i</a></li>";
    					} else {
    						echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
    					}
    				}
    			}
    			echo "<li>";
    			next_posts_link($nxtlabel, $max_page);
    			echo "</li>";
    			if (($paged+$half_pages_to_show) < ($max_page)) {
    				echo ' ... <a href="'.get_pagenum_link($max_page).'">آخر &raquo;</a>';
    			}
    			echo "</ul></div>";
    		}
    	}
    }
    
    ?>

    و در فایل ایندکسم هم این کدها قرار داره :

    <?php } if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
        <div class="mainpost">
            <div class="contentpost">
            <div class="titlepost"><h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div>
            <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php getImage('1'); ?>" width="220" height="220" class="thumb" /></a>
            <?php the_excerpt(); ?>
            <div class="postcomment"><?php comments_popup_link('بدون نظر', '1 نظر', '% نظر'); ?></div>
            <div class="postmore"><a href="<?php the_permalink() ?>">ادامه مطلب</a></div>
            <div class="calcal">
            <div style="float:right">
    		کالری: <?php echo get_post_meta($post->ID, 'cal',true); ?>kcal<br>
    	</div>
    	</div>
            <div class="clear"></div>
            </div>
         </div>

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

درباره‌ی این موضوع



برچسب‌ها

هیچ برچسبی نیست.