Trying to add some code to only Archive pages in WordPress

I’m trying to add a text widget for only the Archive pages. The first block of code below is what is default for the theme.

if (Bunyad::posts()->meta('featured_slider') == 'rev-slider' && function_exists('putRevSlider')) {

    echo '<div class="main-featured"><div class="wrap cf">'
        . do_shortcode('[rev_slider ' . esc_attr(Bunyad::posts()->meta('slider_rev')) .']')
        . '</div></div>';

    return;
}

In addition to the code above, I added this second block directly underneath it. The only difference is that I added && is_archive() on the first line to target all Archive pages and also the three lines of code starting at line 5.

Read More
if (Bunyad::posts()->meta('featured_slider') == 'rev-slider' && function_exists('putRevSlider') && is_archive() {

    echo '<div class="main-featured"><div class="wrap cf">'

        if (!dynamic_sidebar('categories')) :
            _e('', 'bunyad');
        endif;

        . do_shortcode('[rev_slider ' . esc_attr(Bunyad::posts()->meta('slider_rev')) .']')
        . '</div></div>';

    return;
}

The result is a blank page so obviously something is wrong here. Is there some kind of way to condense both of these blocks into something more elegant?

Related posts

1 comment

  1. It is probably giving a white page due to a syntax error. The if block is in the middle of an echo. Try something like:

    if (Bunyad::posts()->meta('featured_slider') == 'rev-slider' && function_exists('putRevSlider') && is_archive()) {
    
        echo '<div class="main-featured"><div class="wrap cf">';
    
        if (!dynamic_sidebar('categories')) :
            _e('', 'bunyad');
        endif;
    
        echo do_shortcode('[rev_slider ' . esc_attr(Bunyad::posts()->meta('slider_rev')) .']') . '</div></div>';
    
        return;
    }
    

Comments are closed.