• Resolved andrew-s3

    (@andrew-s3)


    For some reason I’m receiving an error when using the following code – saying that one of my lines has an error in the syntax – please see below.

    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    echo (isset($title) ? '
    
        <section id="title" class="crimson" '.if ($background !== '') {.'style="url('.$background.')"'.}.'>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>
    
    	' : '');

    the line(s) that are having issues are –

    <section id="title" class="crimson" '.if ($background !== '') {.'style="url('.$background.')"'.}.'>

    &

    ' : '');

    I’ve moved around apostrophe’s and periods and can’t seem to figure out what the issue is.

Viewing 13 replies - 1 through 13 (of 13 total)
  • This code is hard to read, try with this code:

    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="url('.$background.')"';
        $to_echo .= '>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>';
        echo $to_echo;
    }

    if it doesn’t work please share all the error, not only it’s type.

    Thread Starter andrew-s3

    (@andrew-s3)

    I tried the above code and was still receiving a syntax error at the end of the code.

    I need the $to_echo to happen before the <div class=”container”> – basically states if I have entered an image into the custom field for $background display the STYLE code – otherwise; don’t.

    here’s the original code in its entirety before entering in the above conditions:

    <?php
    
    // Breadcrumbs
    require_once(get_template_directory(). '/lib/breadcrumbs.php');
    
    global $post;
    
    if( is_single() ) {
    
        $title = zee_option('zee_blog_title');
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_category() ) {
    
        $title = __("Category", ZEETEXTDOMAIN) . " : " . single_cat_title("", false);
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_archive() ) {
        if (is_day()) {
            $title = __("Daily Archives", ZEETEXTDOMAIN) . " : " . get_the_date();
    
        } elseif (is_month()) {
            $title = __("Monthly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("F Y");
    
        } elseif (is_year()) {
            $title = __("Yearly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("Y");
    
        } else {
            $title = __("Blog Archives", ZEETEXTDOMAIN);
    
        }
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_tag() ) {
        $title = $return .= __("Tag", ZEETEXTDOMAIN) . " : " . single_tag_title("", false);
    } elseif ( is_author() ) {
        $title = __("Author: ", ZEETEXTDOMAIN);
    } elseif ( is_search() ) {
        $title = __("Search results for", ZEETEXTDOMAIN) . " : " . get_search_query();
    } elseif ( is_tax( 'portfolios' ) ) {
        $title = __("Portfolio", ZEETEXTDOMAIN);
    } elseif ( is_home() and !is_front_page() ) {
    
        $page = get_queried_object();
    
        if( is_null( $page ) ){
            $title = zee_option('zee_blog_title');
            $sub_title = zee_option('zee_blog_subtitle');
        } else {
    
         $ID = $page->ID;
         $title = $page->post_title;
         $sub_title = get_post_meta($ID, 'page_subtitle', true);
     }
    
    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    echo (isset($title) ? '
    
        <section id="title" class="crimson">
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>
    
    	' : '');

    Thanks for your help in advance

    Thread Starter andrew-s3

    (@andrew-s3)

    the error being returned is the default dreamweaver return of – ‘There is a syntax error on line 90. Code hinting may not work until you fix this error.’

    [Moderator Note: No bumping, thank you.]

    I don’t use dreamweaver, dreamweaver errors won’t help me understand the issue, upload the code in a website and check php and server errors.

    Thread Starter andrew-s3

    (@andrew-s3)

    the server error returned is –

    PHP Parse error: syntax error, unexpected $end in E:\Users\cPanel\webbetas\public_html\carne\wp-content\themes\flat-theme\sub-title.php on line 90

    and line 90 is the end of the php file.

    <?php
    
    // Breadcrumbs
    require_once(get_template_directory(). '/lib/breadcrumbs.php');
    
    global $post;
    
    if( is_single() ) {
    
        $title = zee_option('zee_blog_title');
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_category() ) {
    
        $title = __("Category", ZEETEXTDOMAIN) . " : " . single_cat_title("", false);
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_archive() ) {
        if (is_day()) {
            $title = __("Daily Archives", ZEETEXTDOMAIN) . " : " . get_the_date();
    
        } elseif (is_month()) {
            $title = __("Monthly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("F Y");
    
        } elseif (is_year()) {
            $title = __("Yearly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("Y");
    
        } else {
            $title = __("Blog Archives", ZEETEXTDOMAIN);
    
        }
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_tag() ) {
        $title = $return .= __("Tag", ZEETEXTDOMAIN) . " : " . single_tag_title("", false);
    } elseif ( is_author() ) {
        $title = __("Author: ", ZEETEXTDOMAIN);
    } elseif ( is_search() ) {
        $title = __("Search results for", ZEETEXTDOMAIN) . " : " . get_search_query();
    } elseif ( is_tax( 'portfolios' ) ) {
        $title = __("Portfolio", ZEETEXTDOMAIN);
    } elseif ( is_home() and !is_front_page() ) {
    
        $page = get_queried_object();
    
        if( is_null( $page ) ){
            $title = zee_option('zee_blog_title');
            $sub_title = zee_option('zee_blog_subtitle');
        } else {
    
         $ID = $page->ID;
         $title = $page->post_title;
         $sub_title = get_post_meta($ID, 'page_subtitle', true);
     }
    
    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="url('.$background.')"';
        $to_echo .= '>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>';
        echo $to_echo;
    }
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Where does this ‘if’ statement end:

    if ($background !== '') {

    ??

    Thread Starter andrew-s3

    (@andrew-s3)

    Andrew – Thanks for pointing that out – it seems to have fixed the syntax error.

    Though the problem now is that if nobody enters a value for $background – then the whole title no longer appears.

    would I just add an ELSE statement in there for the following minus the $background style?

    if so – what would that look like?

    here’s an example of the HTML minus the $background property added to the <section> tag.

    <section id="title" class="crimson">
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>
    Thread Starter andrew-s3

    (@andrew-s3)

    UPDATE –

    I changed the file to the following in order to have the else statement to still display my page title – yet it’s giving me a syntax error again at the end of the document on the server-side.

    <?php
    
    // Breadcrumbs
    require_once(get_template_directory(). '/lib/breadcrumbs.php');
    
    global $post;
    
    if( is_single() ) {
    
        $title = zee_option('zee_blog_title');
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_category() ) {
    
        $title = __("Category", ZEETEXTDOMAIN) . " : " . single_cat_title("", false);
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_archive() ) {
        if (is_day()) {
            $title = __("Daily Archives", ZEETEXTDOMAIN) . " : " . get_the_date();
    
        } elseif (is_month()) {
            $title = __("Monthly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("F Y");
    
        } elseif (is_year()) {
            $title = __("Yearly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("Y");
    
        } else {
            $title = __("Blog Archives", ZEETEXTDOMAIN);
    
        }
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_tag() ) {
        $title = $return .= __("Tag", ZEETEXTDOMAIN) . " : " . single_tag_title("", false);
    } elseif ( is_author() ) {
        $title = __("Author: ", ZEETEXTDOMAIN);
    } elseif ( is_search() ) {
        $title = __("Search results for", ZEETEXTDOMAIN) . " : " . get_search_query();
    } elseif ( is_tax( 'portfolios' ) ) {
        $title = __("Portfolio", ZEETEXTDOMAIN);
    } elseif ( is_home() and !is_front_page() ) {
    
        $page = get_queried_object();
    
        if( is_null( $page ) ){
            $title = zee_option('zee_blog_title');
            $sub_title = zee_option('zee_blog_subtitle');
        } else {
    
         $ID = $page->ID;
         $title = $page->post_title;
         $sub_title = get_post_meta($ID, 'page_subtitle', true);
     }
    
    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="background:url('.$background.') top center repeat-x"';
        $to_echo .= '>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>';
        echo $to_echo;
    } else { ?>
    
        <section id="title" class="crimson">
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1><?php echo $title ?></h1>
        <p><?php echo $sub_title ?></p>
        </div>
        <div class="col-sm-6"><?php zee_breadcrumb() ?></div>
        </div>
        </div>
        </section>
    <? } }

    The error reads –
    PHP Parse error: syntax error, unexpected $end in E:\Users\cPanel\webbetas\public_html\carne\wp-content\themes\flat-theme\sub-title.php on line 102

    Thanks again for your help in advance.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Instead of this:

    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="background:url('.$background.') top center repeat-x"';
        ...
    } else {
    ...
    }}

    Shouldn’t it be this:

    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="background:url('.$background.') top center repeat-x"';
        }
        ...
    } else {
    ...
    }

    Thread Starter andrew-s3

    (@andrew-s3)

    I’ve tested your suggestion

    <?php
    
    // Breadcrumbs
    require_once(get_template_directory(). '/lib/breadcrumbs.php');
    
    global $post;
    
    if( is_single() ) {
    
        $title = zee_option('zee_blog_title');
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_category() ) {
    
        $title = __("Category", ZEETEXTDOMAIN) . " : " . single_cat_title("", false);
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_archive() ) {
        if (is_day()) {
            $title = __("Daily Archives", ZEETEXTDOMAIN) . " : " . get_the_date();
    
        } elseif (is_month()) {
            $title = __("Monthly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("F Y");
    
        } elseif (is_year()) {
            $title = __("Yearly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("Y");
    
        } else {
            $title = __("Blog Archives", ZEETEXTDOMAIN);
    
        }
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_tag() ) {
        $title = $return .= __("Tag", ZEETEXTDOMAIN) . " : " . single_tag_title("", false);
    } elseif ( is_author() ) {
        $title = __("Author: ", ZEETEXTDOMAIN);
    } elseif ( is_search() ) {
        $title = __("Search results for", ZEETEXTDOMAIN) . " : " . get_search_query();
    } elseif ( is_tax( 'portfolios' ) ) {
        $title = __("Portfolio", ZEETEXTDOMAIN);
    } elseif ( is_home() and !is_front_page() ) {
    
        $page = get_queried_object();
    
        if( is_null( $page ) ){
            $title = zee_option('zee_blog_title');
            $sub_title = zee_option('zee_blog_subtitle');
        } else {
    
         $ID = $page->ID;
         $title = $page->post_title;
         $sub_title = get_post_meta($ID, 'page_subtitle', true);
     }
    
    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '') {
            $to_echo .= 'style="background:url('.$background.') top center repeat-x"';}
        $to_echo .= '>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>';
        echo $to_echo;
    } else { ?>
    
        <section id="title" class="crimson">
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1><?php echo $title ?></h1>
        <p><?php echo $sub_title ?></p>
        </div>
        <div class="col-sm-6"><?php zee_breadcrumb() ?></div>
        </div>
        </div>
        </section>
    <? }

    Still says I have an error on line 102

    Thread Starter andrew-s3

    (@andrew-s3)

    i’ve tried different renditions of the supplied “solutions” and have yet to solve the syntax error on line 102 that continues to display.

    i’ve decided to stick with the half-solved code that requires the user to HAVE to enter something in the custom field or no title displays – i’ll just make the custom field required.

    if anyone figures out how to make it still display the title w/o the custom field as i’ve been attempting above feel free to comment.

    thanks again for all your help guys

    Can you try this code?

    <?php
    
    // Breadcrumbs
    require_once(get_template_directory(). '/lib/breadcrumbs.php');
    
    global $post;
    
    if( is_single() ) {
    
        $title = zee_option('zee_blog_title');
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_category() ) {
    
        $title = __("Category", ZEETEXTDOMAIN) . " : " . single_cat_title("", false);
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_archive() ) {
        if (is_day()) {
            $title = __("Daily Archives", ZEETEXTDOMAIN) . " : " . get_the_date();
    
        } elseif (is_month()) {
            $title = __("Monthly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("F Y");
    
        } elseif (is_year()) {
            $title = __("Yearly Archives", ZEETEXTDOMAIN) . " : " . get_the_date("Y");
    
        } else {
            $title = __("Blog Archives", ZEETEXTDOMAIN);
    
        }
    
        $sub_title = zee_option('zee_blog_subtitle');
    
    } elseif ( is_tag() ) {
        $title = $return .= __("Tag", ZEETEXTDOMAIN) . " : " . single_tag_title("", false);
    } elseif ( is_author() ) {
        $title = __("Author: ", ZEETEXTDOMAIN);
    } elseif ( is_search() ) {
        $title = __("Search results for", ZEETEXTDOMAIN) . " : " . get_search_query();
    } elseif ( is_tax( 'portfolios' ) ) {
        $title = __("Portfolio", ZEETEXTDOMAIN);
    } elseif ( is_home() and !is_front_page() ) {
    
        $page = get_queried_object();
    
        if( is_null( $page ) ){
            $title = zee_option('zee_blog_title');
            $sub_title = zee_option('zee_blog_subtitle');
        } else {
    
         $ID = $page->ID;
         $title = $page->post_title;
         $sub_title = get_post_meta($ID, 'page_subtitle', true);
     }
    
    } elseif ( (is_page()) && (!is_front_page()) ) {
        $page = get_queried_object();
    
        $ID = $page->ID;
    
        $title = $page->post_title;
        $sub_title = get_post_meta($ID, 'page_subtitle', true);
    	$background = types_render_field("title-background", array("output" => "raw")); 
    
    } elseif( is_front_page() ){
    
        unset($title);
    }
    
    if (isset($title)) {
        $to_echo = '<section id="title" class="crimson" ';
        if ($background !== '')
            $to_echo .= 'style="background:url('.$background.') top center repeat-x"';
        $to_echo .= '>
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1>'.$title.'</h1>
        <p>'.$sub_title.'</p>
        </div>
        <div class="col-sm-6">'.zee_breadcrumb().'</div>
        </div>
        </div>
        </section>';
        echo $to_echo;
    } else { ?>
    
        <section id="title" class="crimson">
        <div class="container">
        <div class="row">
        <div class="col-sm-6">
        <h1><?php echo $title ?></h1>
        <p><?php echo $sub_title ?></p>
        </div>
        <div class="col-sm-6"><?php zee_breadcrumb() ?></div>
        </div>
        </div>
        </section>
    <?php } ?>

    I’ve changed the final php tag from <? to <?php (it should work with yours also but let’s make sure this is not the one causing the issue, also please provide the exact error you are getting even if it’s the same syntax error.

    Thread Starter andrew-s3

    (@andrew-s3)

    You sir are THE MAN! Thank You!

    That seemed to do the trick – amazing how it’s always something that small that causes a problem with my php…

    Thank you very much jnhghy & Andrew for your help!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Background Query not Working’ is closed to new replies.