راهنمایی در مورد omdb api

MahdiY

راهبر انجمن
ساختار کد شما با تابع جدید بدین صورت است

کد:
<?php function get_imdb($ID){	$url = file_get_contents("http://www.omdbapi.com/?i=".$ID."");	return json_decode($url,true);}$ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];}
 
آخرین ویرایش توسط مدیر:

amin704

کاربر عضو
ساختار کد شما با تابع جدید بدین صورت است

<?php function get_imdb($ID){ $url = file_get_contents("http://www.omdbapi.com/?i=".$ID.""); return json_decode($url,true);}$ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];}
اگه اشتباه نکنم منظورتون اینه که به این شکل مستقیما در خود single و index لود کنم؟اگگه اینطوری باشه زیاد به کار نمیاد چون چنتا زمینه دلخواه دارم که باید مابین اطلاعات imdb قرار بگیرن،. روش قبلی که گفتید خیلی کاربردی تره منتها در مورد نمایش متن ها در صورت عدم وجود اطلاعات هم، راهنمایی کنید 

ممنون

 
آخرین ویرایش توسط مدیر:

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
کد زیر رو باید تو فانکشن بزارید :

function get_imdb($ID){ $url = file_get_contents("http://www.omdbapi.com/?i=".$ID.""); return json_decode($url,true);}و بعدش فراخونی کنین .

 

amin704

کاربر عضو
ساختار کد شما با تابع جدید بدین صورت است

<?php function get_imdb($ID){ $url = file_get_contents("http://www.omdbapi.com/?i=".$ID.""); return json_decode($url,true);}$ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];}

به این شکل فراخوانی کردم اما با هر فراخوانی تمام اطلاعات لود میشن!!

کد:
<?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbVotes"]) && !empty($info["imdbVotes"])) echo $info["imdbVotes"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Metascore"]) && !empty($info["Metascore"])) echo $info["Metascore"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Rated"]) && !empty($info["Rated"])) echo $info["Rated"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Released"]) && !empty($info["Released"])) echo $info["Released"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Country"]) && !empty($info["Country"])) echo $info["Country"];} ?>
 

amin704

کاربر عضو
اقا کد هارو به این صورت گذاشتم اما ارور میده و با قسمت 

<?php endwhile; ?> <?php else: ?> <?php endif; ?>مشکل داره

کد:
	<?php get_header () ; ?>		<ul class="slider">	<?php$args = array(    'post_type' => 'post',    'posts_per_page' => 7,    'orderby' => 'meta_value_num',    'meta_key' => 'views',    'order' => 'DESC',);$my_query = new WP_Query( $args );while ($my_query->have_posts()):$my_query->the_post();$do_not_duplicate = $post->ID; ?><?php $views = get_post_meta($post->ID, 'views', true); ?>  <li class="mv">  <figure><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?phpif ( has_post_thumbnail() ){$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );$thumbnailsrc= $src[0];$params = array( 'width' => 119 ,'height' => 160, 'crop' => true );?><img src="<?php echo bfi_thumb( $thumbnailsrc , $params ) ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="119" height="160" /><?php } else { ?><img src="<?php bloginfo('template_directory'); ?>/images/df-tumbnail.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="119" height="160" /><?php }?></a><figcaption class="mv-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></figcaption>  <div class="mv-cat"><?php$category = get_the_category();if ($category) {  echo '<a href="' . get_category_link( $category[0]->term_id ) . '" title="' . sprintf( __( "" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ';}?></div> </li>	</figure><?php endwhile; ?>	<div class="clear"></div>	 </ul>		<?php get_sidebar(); ?><script type="text/javascript">	function Init()	{	theDiv = document.getElementById('content');	links = theDiv.getElementsByTagName('a');	for (var i=0, len=links.length; i < len; i++) {	links[i].setAttribute('target', '_blank');	}	}	window.onload = Init;</script>	<script>$(document).ready(function() {$(".imdb-info span").each(function() {$(this).text(addComma($(this).text()));});});function addComma( str ) {var objRegex = new RegExp( '(-?[0-9]+)([0-9]{3})' );while( objRegex.test( str ) ) {  str = str.replace( objRegex, '$1,$2' );}return str;}</script>	<div id="content">	<?php if(have_posts()): ?><?php while(have_posts()):the_post(); ?>		<div class="post">	<div class="post-title">	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); 			?></a></h2>	</div>	<div class="content"><div class="postmetadt">	<ul>		<li class="author"><?php the_author() ?></li>        	<li class="date"><?php the_time(__('F j Y','record')) ?></li>			<li class="rate"><?php if(function_exists('the_ratings')) { the_ratings(); } ?></li>	</ul></div><div class="mt-info"><figure class="mt-poster"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if ( has_post_thumbnail() ){$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );$thumbnailsrc= $src[0];$params = array( 'width' => 200 ,'height' => 320, 'crop' => true ); ?><img src="<?php echo bfi_thumb( $thumbnailsrc , $params ) ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="200" height="320" /><?php } else { ?><img src="<?php bloginfo('template_directory'); ?>/images/df-tumbnail.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="200" height="320" /><?php }?></a></figure><ul class="imdb-info"><li><?php if ( get_field('imdb_link') ) {echo '<a href=' . get_field('imdb_link') . ' " target="_blank">IMDB</a>';}?></li><?php if( the_terms( get_the_ID(), 'movie-quality', 'movie-quality: ', ', ', ' ' ) ) { ?><li><?php _e('quality', 'record'); ?><?php the_terms( get_the_ID(), 'movie-qauality', 'movie-qauality: ', ', ', ' ' ); ?><br></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbVotes"]) && !empty($info["imdbVotes"])) echo $info["imdbVotes"];}{ ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Metascore"]) && !empty($info["Metascore"])) echo $info["Metascore"];}{ ?><?php if(get_field('h-Metascore') ) { ?><li><?php _e('Metascore : ', 'record'); ?><?php echo get_field('h-Metascore');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Rated"]) && !empty($info["Rated"])) echo $info["Rated"];}{ ?><?php if(get_field('h-rated') ) { ?><li><?php _e('reted : ', 'record'); ?><?php echo get_field('h-rated');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Released"]) && !empty($info["Released"])) echo $info["Released"];}{ ?><?php if(get_field('h-Released') ) { ?><li><?php _e('Released : ', 'record'); ?><?php echo get_field('h-Released');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Country"]) && !empty($info["Country"])) echo $info["Country"];}{ ?><?php if(get_field('h-Country') ) { ?><li><?php _e('Country : ', 'record'); ?><?php echo get_field('h-Country');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Genre"]) && !empty($info["Genre"])) echo $info["Genre"];}{ ?><?php if(get_field('h-Genre') ) { ?><li><?php _e('Genre : ', 'record'); ?><?php echo get_field('h-Genre');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Writer"]) && !empty($info["Writer"])) echo $info["Writer"];}{ ?><?php if(get_field('h-Writer') ) { ?><li><?php _e('Writer : ', 'record'); ?><?php echo get_field('h-Writer');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Director"]) && !empty($info["Director"])) echo $info["Director"];}{ ?>><?php if(get_field('Director') ) { ?><li><?php _e('Director : ', 'record'); ?><?php echo get_field('Director');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Actors"]) && !empty($info["Actors"])) echo $info["Actors"];}{ ?><?php if(get_field('h-Stars	') ) { ?><li><?php _e('Stars : ', 'record'); ?><?php echo get_field('h-Stars');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Runtime"]) && !empty($info["Runtime"])) echo $info["Runtime"];}{ ?><?php if(get_field('h-Runtime') ) { ?><li><?php _e('Runtime : ', 'record'); ?><?php echo get_field('h-Runtime');?></li><?php } ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["Awards"]) && !empty($info["Awards"])) echo $info["Awards"];}{ ?><?php if(get_field('h-Awards') ) { ?><li><?php _e('Awards : ', 'record'); ?><?php echo get_field('h-Awards');?></li><?php } ?><br><?php if(get_field('plot') ) { ?><li><?php _e('Plot : ', 'record'); ?><?php echo get_field('plot');?></li><br><?php } ?><?php if(get_field('add_info') ) { ?><li><?php echo get_field('add_info');?></li><br><?php } ?></ul><div class="clear"></div></div></div>		</div>	<div class="tags"><h3><?php the_tags( __('Tags: ','record')); ?></h3></div><div class="dl-box"><?php if( get_field('torrent_dl')):?><div class="trnt-head"><h3><?php _e('Torrent Download', 'record'); ?></h3><div class="torrent"><?php echo get_field('torrent_dl');?></div></div><div class="dl-head"><h3><?php _e('Download With Mirror link(s)', 'record'); ?></h3><div class="dl-link"><?php echo get_field('download_link');?></div></div><?php endif;?></div><div class="related"><h6><?php _e('related post', 'record'); ?></h6><?php$tags = wp_get_post_tags($post->ID);if ($tags) {  $first_tag = $tags[0]->term_id;  $args=array(    'tag__in' => array($first_tag),    'post__not_in' => array($post->ID),    'showposts'=>5,    'caller_get_posts'=>1   );    $rel_posts = new WP_Query($args);  if( $rel_posts->have_posts() ) {    while ($rel_posts->have_posts()) : $rel_posts->the_post(); ?>  <div class="rel_posts"><div class="rel_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?phpif ( has_post_thumbnail() ){$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );$thumbnailsrc= $src[0];$params = array( 'width' => 119 ,'height' => 160, 'crop' => true );?><img src="<?php echo bfi_thumb( $thumbnailsrc , $params ) ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="119" height="160" /><?php } else { ?><img src="<?php bloginfo('template_directory'); ?>/images/df-tumbnail.png" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="119" height="160" /><?php }?></a><span class="rel_link"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></span></div></div><?phpendwhile;}}?></div>  <div class="clear"></div>		<div class="comments-template">	<?php comments_template(); ?></div>	</div>	<div class="clear"></div>		<?php get_footer(); ?>
 
آخرین ویرایش توسط مدیر:

amin704

کاربر عضو
فانکشن رو به این شکل عوض کردم

function get_imdb($ID){ $url = file_get_contents("http://www.omdbapi.com/?i=".$ID.""); return json_decode($url,true);}این کدها هم در single گذاشتم:

<?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["imdbVotes"]) && !empty($info["imdbVotes"])) echo $info["imdbVotes"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["Metascore"]) && !empty($info["Metascore"])) echo $info["Metascore"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["Rated"]) && !empty($info["Rated"])) echo $info["Rated"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["Released"]) && !empty($info["Released"])) echo $info["Released"];} ?><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);if(!empty($ID)){ $info = get_imdb($ID); if(isset($info["Country"]) && !empty($info["Country"])) echo $info["Country"];} ?>حالا چطوری متن ها فارسی رو اضافه کنم؟ مثلا "ژانر:" بعد فراخوانی تابع مربوطه؟

 
آخرین ویرایش توسط مدیر:

amin704

کاربر عضو
دوستان مشکل ر. به این شکل حل کرذدم، حالا میخوام  قسمت 

_e('imdb Rating : ', 'record'); رو در داخل divقرار بدم ... چطوری اینکارو کنم؟

کد:
<li><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);_e('imdb Rating : ', 'record');if(!empty($ID)){		$info = get_imdb($ID);		if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];_e(' / 10 ', '');} ?>
 

Mohammad

مدیر انجمن
پرسنل مدیریت
<li><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);

echo '<div class="persianscript">';

_e('imdb Rating : ', 'record');

echo '</div>';

if(!empty($ID)){

    $info = get_imdb($ID);

    if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];

_e(' / 10 ', '');

} ?>


 

amin704

کاربر عضو
<li><?php $ID = get_post_meta($post->ID, 'M-S-ID',true);echo '<div class="persianscript">';_e('imdb Rating : ', 'record');echo '</div>';if(!empty($ID)){        $info = get_imdb($ID);        if(isset($info["imdbRating"]) && !empty($info["imdbRating"])) echo $info["imdbRating"];_e(' / 10 ', '');} ?>
ممنون

 
بالا