Home>Support>Display content of page before archive loop

Display content of page before archive loop

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

I’m trying to customize the archive template for tags. I use tags to associate articles and posts with different subjects. However, I have a page category called “encyclopedia” which gives a summary explanation of the subject. I have the encyclopedia subpages available through a menu.

What I want is to display the encyclopedia page when a tag is clicked, before the post loop with all the relevant pages.

Essentially I want to modify the archive template to check if an encyclopedia page of the same name exists, “/tag/subject101/” -> “/encyclopedia/subject101/”. If the page exists, display that content, and keep the post loop after. If the page does not exist, proceed with the loop as usual.

I’ve looked a the forums for days and still haven’t found any examples. I’d appreciate any pointers!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 6 years, 1 month ago Andrew Misplon
    Hi, I Work Here

    Hi Joshua

    Thanks for reaching out.

    I wish we could dive into this here. To remain viable our free support scope is limited to basic usage and troubleshooting questions.

    You’ll need to use a child theme. Here is a useful page on WordPress conditionals: https://codex.wordpress.org/Conditional_Tags#A_Tag_Page. You’d most likely add your conditional to archive.php copied from the parent to the child.

    For more in-depth help, you might consider a SiteOrigin Premium license. Premium allows us to offer more in-depth advice on customization tasks of this nature. You could also consider codeable.io if you ever wanted to hire a developer to assist.

  2. 6 years, 1 month ago Joshua Stewart

    I figured it out! Added the following code to archive.php.

        <?php
        if (is_tag()) {
            $tag = get_queried_object();
            $tagslug = $tag->slug;
            $page_path = '/encyclopedia/'.$tagslug;
            if( ! $encyc = get_page_by_path( $page_path, OBJECT, 'page' ) ){
                echo 'No encyclopedia entry exists for '.$tagslug.'. Contact the editor to request one.';
            } else{
              echo '<div class="encyclopedia-preview">';
                    $post = get_post($encyc); 
        $title = apply_filters('the_title', get_post_field('post_title', $post)); 
        $content = apply_filters('the_content', $post->post_content); 
              $excerpt = get_the_excerpt($post);
              $link_title = "Encyclopedia, under: $title";
              $line_of_code = "<h1><a href= $page_path>$title</a></h1>";
        echo $line_of_code;
        echo $excerpt;
              echo "</div>";
            }  
        echo '<div class = "tag-header">Tagged pages:</div>';
        echo "<div> </div>";
        }
        ?>
  3. 6 years, 1 month ago Andrew Misplon
    Hi, I Work Here

    Awesome! Really glad to hear you’ve been making progress. Thanks for sharing your work here :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More