Site logo

Archived topic

Previous-Next button glitches

9 replies · Started by Stan on July 27, 2019

Viewing posts 1–10 of 10

Apologies if this is basic, but I have a weird mistake on the Previous and Next buttons on each post on my website. I have an image, but can't attach it here. Basically, each post at the bottom has this code:

1, 'include' => $prevPost->ID ); $prevPost = get_posts($args); foreach ($prevPost as $post) { setup_postdata($post); ?>

And the a Previous button in red box inside a larger grey box and then this code:

1, 'include' => $nextPost->ID ); $nextPost = get_posts($args); foreach ($nextPost as $post) { setup_postdata($post); ?>

And then a Next button in a red box inside a larger grey box.

Any help in getting rid of this is much appreciated. I would prefer normal Previous and Next buttons.

Thanks.

Hi there,

Did you use a site in our Site Library?

If so, which one?

Let me know :)

Yes I used Dispatch

If you go to "Appearance > Elements" and open the "Post Navigation" element, is the "Execute PHP" checkbox checked?

If it is, can you replace the hook content with this?:

<div id="post-nav">
	<?php 
	global $post;
	$prevPost = get_previous_post(false);
	$post_type = get_post_type();
	
	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(); ?>">
					<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.1),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');">
						<div class="post-nav"><?php _e( 'Previous', 'generatepress' ); ?></div>
						<h3 class="post-nav-title"><?php the_title(); ?></h3>
					</div>
				</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(); ?>">
					<div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.6),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');">
						<h3 class="post-nav-title"><?php the_title(); ?></h3>
						<div class="post-nav"><?php _e( 'Next', 'generatepress' ); ?></div>					
					</div>
				</a>
			<?php
			wp_reset_postdata();
		} //end foreach
	} // end if
?>
</div>

Thanks for the response. The 'Execute PHP' line does not have a check option, and instead shows this: 'Unable to execute PHP as DISALLOW_FILE_EDIT is defined'.

Hi, so based on the above instructions in the article, I placed the 'define( 'GENERATE_HOOKS_DISALLOW_PHP', true );' line after the 'Disallow_File_Edit' line in the wp-config.php file using File Manager in Bluehost and saved it.

There is still no 'Execute PHP' checkbox. It still shows‘Unable to execute PHP as DISALLOW_FILE_EDIT is defined’.

Is there something I'm missing?

Sorry, that's an old article geared towards the old Hook system.

The reason you're seeing that message is because File Editing is disabled on your site: https://wordpress.org/support/article/editing-wp-config-php/#disable-the-plugin-and-theme-editor

Usually, this is disabled because you don't want people to be able to execute PHP in your Dashboard.

If you want to keep file editing turned off, but allow PHP execution in Elements, you can do this: https://docs.generatepress.com/article/generate_hooks_execute_php/

Hope this helps :)

Thanks, Tom! That worked!

You're welcome :)

This archived topic is closed to new replies.