• I have coded a wordpress theme from scratch. My navbar is a transparent navbar that is wrapped in the same div as my hero. Each page has a different hero image that is set by a different hero div class. However I can’t do this using header.php when converting to a wordpress theme.

    How would a create a transparent navbar that would work with header.php across different pages with different hero classes?

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • Why can you not put the hero logic / class in header.php with the nav?

    Thread Starter anon2694

    (@anon2694)

    If the navbar is wrapped in the same div wrapper as the hero, and each page has a different hero that is set by the class of the hero div wrapper, then all pages will have the same hero because the hero wrapper class will be hard coded in header.php

    https://stackoverflow.com/questions/66214975/transparent-nav-in-header-php

    So if the page template can work out the hero class, then so can the header template.

    in header.php something like

    if (is_singular()) {
          $post = get_post();
          $hero_class =  some logic to get the class

    You could also insert the code by firing wp_head hook of creating your own acton or filter hooks in the header

    Thread Starter anon2694

    (@anon2694)

    I’m gonna have to read up a bit more about this. This is the first site I’ve ever built. Thanks for your help.

    So how are you pull out the appropriate class – it that stored in post meta or somewhere?

    Thread Starter anon2694

    (@anon2694)

    I first built the site as a static site using just html, js and css, so each page has its own independent html where I’ve just added the appropiate wrapper classes.

    I’ve been learning wordpress the past couple of days as I’ve tried to convert the site into a wordpress theme. So my wordpress knowledge is limited at the moment.

    Ok Enjoy the journey.

    A bit to learn.

    https://developer.ww.wp.xz.cn/themes/basics/

    Thread Starter anon2694

    (@anon2694)

    Thanks. I’ve managed to get everything working properly apart from my issue with the transparent navbar. I’ve enqueued all my css and js files, enabled various theme options in function.php, created navigation locations, also I’ve got the blog archive.php and single.php working properly with my blog.

    I just need to work out now how to identify which page template is being used and add the class dynamically to my html in header.php I think.

    if (is_singular()) {
          $post = get_post();
          $template = get_post_meta( $post->ID, '_wp_page_template', true );
          switch ( $template ) {
              case 'myone-page.php':
                 $class = 'myone';
                 break;
              case 'mytwo-page.php':
                 $class = 'mytwo';
                 break;
              default:
                 $class='';
          }
    Thread Starter anon2694

    (@anon2694)

    Legend! Thanks very much for your help

    or

    if (is_singular()) {
          $template = get_page_template_slug();
          switch ( $template ) {
              case 'myone-page.php':
                 $class = 'myone';
                 break;
              case 'mytwo-page.php':
                 $class = 'mytwo';
                 break;
              default:
                 $class='';
          }

    you might be better off if it is just pages with https://developer.ww.wp.xz.cn/reference/functions/is_page/

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘transparent nav with header.php’ is closed to new replies.