WordPress.org

Ready to get started?Download WordPress

Forums

custom fields display similar amounts (2 posts)

  1. omidgs
    Member
    Posted 1 year ago #

    hello every one
    i use this method to display cutum field in my theme
    at the first add this lines to the firs of pages
    <?php $buy = get_post_meta($post->ID, 'buy', true); ?>
    <?php $gheymat = get_post_meta($post->ID, 'gheymat', true); ?>
    and next to disply values i insert this line
    <?php echo $buy; ?>
    <?php echo $gheymat; ?>
    in the single.php all things are good and working fine
    but in index.php and category.php all amounts are similar
    for example if good 1 is 200$ and good 2 is 100$ all goods buy show 100$
    (the newest amount
    )
    whats problem?
    please help

    the page code

    <?php $buy = get_post_meta($post->ID, 'buy', true); ?>
    <?php $gheymat = get_post_meta($post->ID, 'gheymat', true); ?>
    <div class="container">
    
    	 <div class="posttitle">
        <ul class="jDesign_tabs">
    
    	<div class="shop"></div>
            <li><a href="#tab2" title="برای دیدن محصولات فروشگاه کلیک کنید">تازه های فروشگاه</a></li>
    
        </ul>	
    
        </div>
        <div 
    
    class="jDesign_ir">
    
            <div id="tab2" class="jD_content">
              	<?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
    			<div class="shopbg">
                <a href="<?php the_permalink() ?>" rel="bookmark"></a>
            <a href="<?php the_permalink() ?>"><h2 class="stitle"><?php the_title(); ?></h2></a><p class="gh"><?php echo $gheymat; ?></p>
            <a href="<?php the_permalink() ?>" rel="bookmark">
    </a><a href="<?php the_permalink() ?>"><div class="sthumb"><?php the_post_thumbnail( array(150,150) ); ?></div></a>
    					<a class="buya" href="<?php echo $buy; ?>"><div class="buy"></div>خرید پستی</a>
                        <a class="buya" href="<?php the_permalink() ?>" rel="bookmark"><div class="smore"></div>توضیحات
    </a>
                </div>	
    
           <?php endwhile; ?>
    <?php else : ?>
     <?php _e('Not Found'); ?>
    ?php _e('Sorry, no posts matched your criteria.'); ?>
       <?php endif; ?>
    
        <div class="sp2"></div>
         <div class="pages"><?php
     SEO_pager();
    ?>	</div>
            </div>
    
    </div>
    </div>
  2. Prasath Mani
    Member
    Posted 1 year ago #

    Hi,

    Issues is

    $post->ID

    . please use get_post_meta within while loop.

    [ Signature moderated. ]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.