WordPress.org

Ready to get started?Download WordPress

Forums

Custom fields and tag display on single.php (2 posts)

  1. exiledesigns
    Member
    Posted 6 years ago #

    Hello,

    I've successfully displayed several custom fields & customized tags on my main loop (on index.php).

    However, when using the same code to display them in my single.php page, nothing shows !

    Any hint, help, welcome - thanks you!

    My custom field contains an image URL.
    <img src="<?php bloginfo('url'); ?><?php $key="thumb"; echo get_post_meta($post->ID, $key, true); ?>" alt="<?php the_title(); ?>" />

    My tags are customized with CSS classes (using their ID).

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    	if ($tag->term_id == 3) { echo '<li class="webdesign">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 6) { echo '<li class="css">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 5) { echo '<li class="ecommerce">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 7) { echo '<li class="photo">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 8) { echo '<li class="strategy">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 9) { echo '<li class="cd">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 10) { echo '<li class="dev">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 11) { echo '<li class="forum">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 12) { echo '<li class="illustration">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 13) { echo '<li class="branding">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 14) { echo '<li class="copywriting">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 15) { echo '<li class="cms">' . $tag->name . '</li>'; }
    	if ($tag->term_id == 16) { echo '<li class="accessibility">' . $tag->name . '</li>'; }
    }
    }
    ?>
  2. exiledesigns
    Member
    Posted 6 years ago #

    A little update ~ I have several loops on my page.
    I tried removing one loop (cf. code below) and I noticed the tags & custom fields were displaying OK.

    Most probably, the problem comes from this loop (located inside the single.php template).

    I'm pretty new at those customizations, so I still do not master the loop and have no idea why this loop works on index.php and not on single.php.

    <?php /* Loops the latest post from category 18 (latest news) */ ?>
    <?php query_posts('cat=18&showposts=1'); ?>
      <?php while (have_posts()) : the_post(); ?>
        <div class="header"><h3><?php the_title(); ?></h3> <span class="date">| <?php the_time('F jS, Y') ?></span></div>
        <?php the_content(); ?>
      <?php endwhile;?>

Topic Closed

This topic has been closed to new replies.

About this Topic