Site logo

Archived topic

Change the style for the Previous/Next section

26 replies · Started by Elia on May 15, 2019

Viewing posts 1–15 of 27

Thanks David,

But please make this as 2 separate codes, so we would easily distinguish them

So few steps:

1. Customizer > Layout > Blog - and disable the post nav.
2. Create a new Hook Element:

https://docs.generatepress.com/article/hooks-element-overview/

2.1 Add this for the content:

<div id="custom-post-nav" class="post-nav-grid">
	<?php global $post;
    
    $post = get_queried_object();
    $post_type = get_post_type();
   
    $prevPost = get_previous_post();
        if($prevPost) {
            $args = array(
                'posts_per_page' => 1,
                'include' => $prevPost->ID,
                'post_type' => $post_type
            );
            $prevPost = get_posts($args);
            foreach ($prevPost as $post) {
                setup_postdata($post);
    ?>
        <a class="post-previous" href="<?php the_permalink(); ?>">
            <span class="nav-icon">❮</span><span class="post-nav-label">Previous Article</span>
            <h5 class="post-nav-title"><?php the_title(); ?></h5>
        </a>
    <?php
                wp_reset_postdata();
            } //end foreach
        } // end if
         
        $nextPost = get_next_post(false);
        if($nextPost) {
            $args = array(
                'posts_per_page' => 1,
                'include' => $nextPost->ID,
                'post_type' => $post_type
            );
            $nextPost = get_posts($args);
            foreach ($nextPost as $post) {
                setup_postdata($post);
    ?>
        <a class="post-next" href="<?php the_permalink(); ?>">
            <span class="post-nav-label">Next Article</span><span class="nav-icon">❯</span>	        
            <h5 class="post-nav-title"><?php the_title(); ?></h5>				
        </a>
    <?php
                wp_reset_postdata(false);
            } //end foreach
        } // end if
    ?>
</div>

2.2 Select the after_content hook
2.3 Check execute PHP
2.4 Set your Display Rules for Posts > All Posts

3. Add this CSS:

.post-nav-grid {
    display: grid;
    grid-template-columns: 50% 50%;
    padding: 5px 0;
}

.post-next {
    text-align: right;
}

.post-nav-grid .nav-icon {
    font-size: 0.75em;
    border-radius: 2em;
    padding: 0.25em 0.6em;
    width: 2em !important;
    color: #ffffff;
    background-color: #000000;
    margin: 0 0.5em;
}

.post-nav-title {
    margin: 0 0.75em;
    line-height: 1.1em
}

That code needs to be added to a Hook, it won't work in the Code Snippets plugin without adding some more code that adds it to the relevant hook. The Theme Hooks are the simplest and best way to place them.

Thanks David,

I did exactly as you said, but nothing happens. I mean there is no navigation now. I put the link to the article in the first message, so you could see it in the live website

Can you confirm that you set the Display Rules for the Hook Element?

That looks correct. I assume all the other settings are correct, as the above instructions, and the Hook has been published? If so do you have any plugin / server caches?

So the hook is working as i can see the empty container on the single post.
Do you still have that post category filter added to your site ( re: the other topic )? If so can you disable that

No, David, the filter is not active..

David, I have to put back navigation links because we have a lot of traffic now, we could try again in couple of days. It's strange that it's not working. Maybe we can try it on the staging website, but not sure if it's ready

There must be something interfering with the normal post nav requests. Yes maybe best we take a closer look on a staging site. Let us know

This archived topic is closed to new replies.