Forums

More fun with sub sub pages (35 posts)

  1. alexleonard
    Member
    Posted 3 years ago #

    Just noticed that eval_sidebar function could do with it's own fallback, in case the global isn't set by one of the pages - for example, on my 404 template I don't really need to worry about calling the eval_page function. So I've adjusted the eval_sidebar function to be:

    function eval_sidebar() {
      global $eus_page;
      if ($eus_page == NULL)  {$eus_page = "Default"; } // If no global set, then set the page type as default
      return $eus_page;
    }

    Again, don't know if this is the best way to do this, but just in case I miss a template it's good to know it will fallback.

  2. alexleonard
    Member
    Posted 3 years ago #

    Hmm, I had hoped that WordPress' new template page - image.php - would behave similarly to single.php in this situation, but unfortunately not.

    I applied the same function, eval_post, to the image.php but it's just falling back to the default sidebar.

    I'm going to have to do some reading up to find out how you can find out what category an image belongs in - hopefully the image.php page will somehow be attached to the post or page id that you originally placed the gallery on.

    If anyone has any suggestions, please let me know. If I work anything out I'll report back here.

  3. alexleonard
    Member
    Posted 3 years ago #

    Hurrah for reusable functions!

    With a little bit of tweaking I've got this functioning on another site that's under development.

    http://url.ie/jvp

  4. alexleonard
    Member
    Posted 3 years ago #

    And the original site in question is now live! Although if anyone has an idea how to relate a post attachment to it's post that would be great!

    http://url.ie/l1p

  5. alexleonard
    Member
    Posted 3 years ago #

    I've been playing around with this some more for another site and needed something a little simpler which wouldn't require predefined class names - instead something just taking the class name from the post slug.

    Of course I could just do:

    <body class="<?php echo $post->post_name; ?>

    and this, I believe would place the post slug as a class attribute in the body element.

    However I needed something that would do that, but in the case of a "page" which was a child, I wanted to always return the page-parent as the class.

    So I've modded the function to read as follows:

    function eval_page($pageid) {
            global $pageClass;  //global, because it's just that useful.
            $pageClass = "default";  // Set the page type as default
            while ($pageid) {
                $page = get_post($pageid);
                $pageid = $page->post_parent;
                $pageClass = $page->post_name;
            }
            $pageClass = "page-" . $pageClass;
            return $pageClass;
        }

    This can be used in your header.php section as follows:

    <body class="<?php echo eval_page($post->ID); ?>">

    Having this extra class in the body element just allows for some extra CSS styling on specific pages.

    Hope it's useful to someone.

Topic Closed

This topic has been closed to new replies.

About this Topic