Trick : Show different single pages, for different products, using custom fields (1 post)

  1. taghaboy
    Posted 6 years ago #

    For people who work with Costume fields more than categories, this code will solve your time easy way :
    Her in this example i set a field :
    with 3 keys :
    Apart, Villa, Cottage.

    And then, create your 3 single page for each key,

    after, open the single.php remove all the code, and copy past this code, and save:

    <?php $value = get_post_meta($post->ID, 'home_type', true);
    	if($value == 'apart') {
    		include (TEMPLATEPATH . '/single-apart.php');
    	} elseif($value == 'villa') {
    		include (TEMPLATEPATH . '/single-villa.php');
    	} elseif($value == 'cottage') {
    		include (TEMPLATEPATH . '/single-cottage.php');
    	} else {
    		include (TEMPLATEPATH . '/single-default.php');

    In every post you publish, select one of the keys (costume field you had created), and then publish your work,

    the code will check in the post you explore if it contain some of the keys, if not it will show the single-default.php

    Hop it will help some one.

    Good luck

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 6 years ago by taghaboy
  • This topic is not a support question
  • WordPress version: 3.0