treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Custom Field or...

  • OK, here's what I'd like to do: I'd like it if a visitor to http://www.faberunashop.com/ had the ability to click on one of the homepage images and be directed to another site, the site of the featured vendor, versus going into a post. Is that done in the custom field or is that a CSS adjustment?
  • You could definitely do it via a custom field.
  • So, the question is: what do I put in the custom field.
  • Depends on how your home page is set up. Presumably you would simply put in the URL you are wanting to redirect to. Then, in your home.php or front-page.php template you will replace the_permalink with your custom field.
  • ok. I will give it a try.
  • When I do the custom field, do I use a href="http://www.debreardonsart.com/" or just http://www.debreardonsart.com for instance?
  • So, I altered the functions.php & the index.php so that if you click on the post title you get to an external link. How do I do it to the rollover image?
  • Here's the code I used:

    function print_post_title() {
    global $post;
    $thePostID = $post->ID;
    $post_id = get_post($thePostID);
    $title = $post_id->post_title;
    $perm = get_permalink($post_id);
    $post_keys = array(); $post_val = array();
    $post_keys = get_post_custom_keys($thePostID);

    if (!empty($post_keys)) {
    foreach ($post_keys as $pkey) {
    if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') {
    $post_val = get_post_custom_values($pkey);
    }
    }
    if (empty($post_val)) {
    $link = $perm;
    } else {
    $link = $post_val[0];
    }
    } else {
    $link = $perm;
    }
    echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
    }

    Then:

    Once that’s done, open your index.php file and replace the standard code for printing titles…
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

    … with a call to our newly created print_post_title() function:
    <?php print_post_title() ?>

    Now, whenever you feel like pointing one of your posts’ titles somewhere other than your own blog, just scroll down in your post editor and create or select a custom key called url1 or title_url or url_title and put the external URL in the value box.
  • I'm not really sure what theme you are using or what's happening here.

    All I would have done was created a custom field, and then changed where ever it's calling the_permalink with it.
  • I'm a little dense so I don't really know how to do that. The theme is this one: http://wpshower.com/themes/imbalance/
  • Ah - okay. So if you post the code for whatever is creating your home page (whether it be index.php, home.php or front-page.php) I'll be able to help you from there!
  • Thanks! Here is the home.php
    <?php get_header(); ?> 

    <ul class="mcol">
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <li class="article" id="post-<?php the_ID(); ?>">

    <?php
    if ( has_post_thumbnail() ) { ?>
    <?php
    $imgsrcparam = array(
    'alt' => trim(strip_tags( $post->post_excerpt )),
    'title' => trim(strip_tags( $post->post_title )),
    );
    $thumbID = get_the_post_thumbnail( $post->ID, 'background', $imgsrcparam ); ?>
    <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>


    <?php } else {?>
    <div class="preview"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></a></div>
    <?php } ?>

    <div class="article-over">
    <?php print_post_title() ?>
    <?php the_excerpt(); ?>
    <div class="postmetadata">
    Posted: <?php the_time(__('F jS, Y', 'kubrick')) ?>&nbsp;&#721;&nbsp;
    <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments'), '', __('Comments Closed') ); ?><br />
    <?php printf(__('Filled under: %s'), get_the_category_list(', ')); ?>
    </div>
    </div>
    </li> <?php ?>
    <?php endwhile; ?>
    <?php else : ?>


    <?php endif; ?>
    </ul>

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <h1 id="error"><?php _e("Sorry, but you are looking for something that isn&#8217;t here."); ?></h1>
    <?php endif; ?>


    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    <?php get_footer(); ?>
  • Perfect. So I would change this:
    <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>

    to this:
    <div class="preview"><a href="<?php echo get_post_meta($post->ID, 'url', true); ?>"><?php echo "$thumbID"; ?></a></div>

    Then create a custom field called 'url' and put in the website.
  • Thanks for your help. I will try and get back to you.
  • Perfect! Thanks!