• Hi, WordPress Experts I need an urgent help in the following topic:
    I have added the post content and some custom fields. Say I have a post with title ‘John Doe’ and its description as well. I have made some custom fields for his address, phone number, website etc. Now suppose I want to show his name, description and website in a page and for that I am using the single.php file. But I want to give a link, say ‘more’ in that single.php file which will open a new page/file with the address and phone number of John Doe on it.

    If I click the ‘more’ link from another post detail page say ‘Doe John’ then the next page will show address and phone number of Doe John on it.

    I think, I am able to make you clear. So is it possible and if yes, how can I achieve this. It’s something urgent.

    Advanced thanks for you help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    You could add a query string to the more link. For example, you have made a custom Page template and published a Page (detail-page) with this custom Page template. Now you can link to this Page from your single.php (example.com/detail-page). Add a query string with the post ID (example.com/detail-page?detail-post=23). In your custom page template you could do something like this [untested]:

    if(isset($_GET['detail-post']) && $_GET['detail-post']){
      if($telephone = get_post_meta($_GET['detail-post'], 'telephone', true)) {
      echo 'telephone: '. telephone;
      }
      if($address = get_post_meta($_GET['detail-post'], 'address', true)) {
      echo 'address: '. $address;
      }
    } else {
    echo 'there are no details';
    }

    Thread Starter anjan.dev.phukan

    (@anjandevphukan)

    Hi, keesiemeijer, thank you so much for your reply. I really appreciate it. It’s nearly what I wanted. But I forgot to mention that we have to keep SEO in mind too. Like say I have a post detail link:

    http://www.example.com/person/john-doe/

    Then we need the detail page something like:
    http://www.example.com/person/john-doe-detail/

    There shouldn’t be any query string value. Is it possible?

    Moderator keesiemeijer

    (@keesiemeijer)

    Is this a custom post type or is “jon-doe” a child page of the “person” Page?

    Thread Starter anjan.dev.phukan

    (@anjandevphukan)

    Hi, keesiemeijer! ‘john-doe’ is a post and ‘person’ is the category name.
    Please visit this page:
    http://staging.bestofbentonville.com/business-directories/bentonville-doctors/alaxender-desouza/

    At the bottom of the page you will see 4 links under ‘Location and Service offered’. Actually I want to link those service pages from these 4 services. Hope this will help you to understand my requirement.

    Thanks for your help.

    Moderator keesiemeijer

    (@keesiemeijer)

    I think in this case “alaxender-desouza” is a (child) category in stead of a post?
    http://staging.bestofbentonville.com/business-directories/bentonville-doctors/alaxender-desouza/

    can you please put the body class in your theme, so we know what template file we’re looking at.

    Thread Starter anjan.dev.phukan

    (@anjandevphukan)

    Hello, I have put the body class. Please check. I can’t make ‘alaxender-desouza’ a category instead of post as there are lots of custom fields.

    Thanks.

    Moderator keesiemeijer

    (@keesiemeijer)

    Ah, I see. You probably have to add your own rewrite rules to WordPress to have it rewrite to /postname-detail. I assume your permalink structure is /%category%/%postname%/.

    download a rewrite class from here: http://www.refactord.com/adding-rewrite-rules-to-wordpress
    Put it in your functions.php (without the opening <?php tag) and add this under it:

    $options = array(
      'rules' => array(
                 '(.+?)/([^/]+)\-(detail)(/[0-9]+)?/?$' => 'index.php?category_name=$matches[1]&name=$matches[2]&detail=$matches[3]&page=$matches[4]'),
      'query_vars' => array('detail')
    );  
    
    $add_rewrite_rules = new Refactord_add_rewrite_rules($options);

    resave your permalink structure under Appearance > Permalinks.

    Now check in your browser if you put “-detail” after a single post title in the address bar if you still get the post.

    If it works you can do something like this in single.php:

    $detailpage = get_query_var('detail');
    if($detailpage == 'detail' ) {
    	echo "show details here";
    } else {
    echo "show normal single page here";
    }
    Thread Starter anjan.dev.phukan

    (@anjandevphukan)

    I think it will work for me. I will try this and let you know. Thank you so much for your help.

    Seems useful.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Additional detail from a post on other page than single.php’ is closed to new replies.