• Resolved jchris

    (@jchris)


    I have 3 different pages I post to, index, page1, page2.
    When I click on the more-link I lose my “current page”info that I use for styling my tabs.
    I style in the css by comparing body ID with tablink names.

    If I could pass the id of the page I leave I could use it to set the body ID tag on the resulting single.php and that would solve my problem.

    I have searched without finding an answer so I would really appreciate any help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • In single.php, $post->ID will normally be the current post ID when used in a post loop.

    Thread Starter jchris

    (@jchris)

    MichaelH

    Thanks. But I would prefer the page id since that would take care of all categories I publish on each bake. The cleanest method for me would be to take the page id from, say index.phd, and put it in the <body id=”xxx”> in the single.php. Then all would work without any changes in styles or code.
    Can you advice me on that?

    Thread Starter jchris

    (@jchris)

    Sorry – “bake”??? Should be “page”.

    I have 3 different pages I post to, index, page1, page2.

    You don’t really post to pages. You can create a Template that in turn is designed to display posts or Pages.

    So not sure what you mean by page id.

    Thread Starter jchris

    (@jchris)

    Thanks for your help.

    I have found the solution with the help of Derek Herman.
    I will try to explain both problem and solution briefly here:

    I have 3 pages. On each of them I publish in several categories in different positions.
    Each page i visually represented by a tab. I style the current tab by matching the menu links to the <body id> of the page shown.

    When the posts have a more-link I want to keep the same tab as current. The more-link uses the file single.php.

    The solution is to test for the posts category and echo a suitable tag within the body-tag.

    To qoute Derek:
    if (in_category(13) || in_category(15)) { echo ’something’; }

    I put this php code within the body-tag and the result is exactly what I wanted.

    <body id="<?php if (in_category(13) || in_category(14) || in_category(15) || in_category(16) || in_category(17)) { echo ('inspiration'); }
    
    elseif (in_category(9) || in_category(10) || in_category(11)) { echo ('programinfo'); }
    
    	else {echo ('news');} ?>">

    My mistake: I didn’t realize that I was already within the post (and the loop). I also assumed that I only can test for category within the loop. Hence I went looking for a possibility to pass a “parent_page_id” to the body-tag in single.php.

    I hope this can be of help to someone.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pass id from template to single.php’ is closed to new replies.