Grow your CSS skills. Land your dream job.

Custom Field or…

  • # September 6, 2011 at 8:55 pm

    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?

    # September 6, 2011 at 9:25 pm

    You could definitely do it via a custom field.

    # September 6, 2011 at 9:29 pm

    So, the question is: what do I put in the custom field.

    # September 6, 2011 at 10:05 pm

    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.

    # September 6, 2011 at 10:31 pm

    ok. I will give it a try.

    # September 6, 2011 at 10:38 pm

    When I do the custom field, do I use a href=”http://www.debreardonsart.com/” or just http://www.debreardonsart.com for instance?

    # September 6, 2011 at 11:01 pm

    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?

    # September 6, 2011 at 11:10 pm

    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 '

    '.$title.'

    ';
    }

    Then:

    Once that’s done, open your index.php file and replace the standard code for printing titles…

    " rel="bookmark" title="Permanent Link to < ?php the_title(); ?>">< ?php the_title(); ?>

    … 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.

    # September 6, 2011 at 11:43 pm

    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.

    # September 7, 2011 at 1:23 am

    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/

    # September 7, 2011 at 1:48 am

    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!

    # September 7, 2011 at 1:57 am

    Thanks! Here is the home.php

    < ?php get_header(); ?>


      < ?php if(have_posts()) : ?>< ?php while(have_posts()) : the_post(); ?>


    • < ?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 ); ?>



      < ?php } else {?>

      < ?php } ?>


      < ?php print_post_title() ?>
      < ?php the_excerpt(); ?>


    • < ?php ?>
      < ?php endwhile; ?>
      < ?php else : ?>


      < ?php endif; ?>


    < ?php if(have_posts()) : ?>< ?php while(have_posts()) : the_post(); ?>
    < ?php endwhile; ?>
    < ?php else : ?>

    < ?php _e("Sorry, but you are looking for something that isn’t here."); ?>


    < ?php endif; ?>


    < ?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    < ?php get_footer(); ?>
    # September 7, 2011 at 12:43 pm

    Perfect. So I would change this:

    to this:

    Then create a custom field called ‘url’ and put in the website.

    # September 7, 2011 at 1:28 pm

    Thanks for your help. I will try and get back to you.

    # September 7, 2011 at 1:35 pm

    Perfect! Thanks!

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".