Get previous/next post from (specific) category

I have posts with two categories, for example, 1st post is in category "product" and "shoes", 2nd is in category "product" and "shirts", 3rd is in category "product" and "sport clothes"... So, posts have one mutual category ("product" in this example), and one more specific category. I tried to get previous/next post with: $next_post = get_next_post( true ); $previous_post = get_previous_post( true ); But then, for example on 2nd post I have 1st and 3rd post as previous/next posts, because …
Category: Web

Next and Previous loop

I am making a wordpress site but i need little help, What I have is a function with Next and Previous buttons to list projects, but when i go to the last project the Next button is gone. What I want to do is, when I go to the last project I hit "Next" and direct me to the first project something like loop slide Here is my code: <?php if (has_term( 'type-1', 'projecttype' ) ) { ?> <div class="holder"> …
Category: Web

Next Previous siblings child pages

I tried this piece of code : https://wordpress.stackexchange.com/a/54474/80921 because I couldn't figure out how to get the next and the previous post. But this code won't work now and I'm not able to comment. The error I get is "Undefined offset: -1" when looking for the ID. Here is the full code found on the related page. Thanks for any help ! $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc"); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, …
Category: Web

get_adjacent_post() returning weird results

I am using get_adjacent_post() function to display links to a previous and next post. It is a custom post which also has a custom taxonomy. This is the code I am using: $prev = get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if($prev){ $url = get_permalink($prev->ID); echo '<a href="' . $url . '">Previous</a>'; } if($next) { $url = get_permalink($next->ID); echo '<a href="' . $url . '">Next</a>'; } As far as I understand, the parameters in the get_adjecent_post() function should consider …
Category: Web

get_previous_post not working as expected

I have used get_previous_post to get the previous post of my custom post type. When I try that by doing $prevPost = get_previous_post(); var_dump($prevPost); I get a post object containing my previous post. So I then tried to set it up so that I could get the post data $prevPost = get_previous_post(true); if($prevPost) { $args = array( 'posts_per_page' => 1, 'include' => $prevPost->ID ); $prevPost = get_posts($args); foreach ($prevPost as $post) { setup_postdata($post); ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a> …
Category: Web

Get Next / Prev 3 Posts in Relation to Current Post

I have 7 posts, like this: 1 2 3 4 - this is the current post 5 6 7 As noted, number four is the current post being displayed. I need to create a query that will allow me to display the previous 3 posts (by publication date) and also the three posts after. This can be done with two separate queries. I've been able to display the immediately previous or next post, just not the ones further down / …
Category: Web

Add a "Next Post" & "Previous Post" styled button manually to a post

Can anyone walk me through the exact steps? I want to create two buttons that sit next to each other at the bottom of a post for the NEXT and PREVIOUS posts...I want to be able to insert this manually (html), and using a style/class to do it. I'm assuming I have to do something in the functions.php file first? Then create a custom CSS button? Then add the code in the bottom of my post?
Category: Web

Decrement term in for each

So I am catching custom posts in wordpress by for eaching my custom terms. To get a post from the next term in the loop I use $terms[++$key]->name and it all works fine. However when I want to do the opposite: $terms[--$key]->name somehow it stays within the same term (even though there is a previous term). Any ideas? In this code the intention is to get the post title of the last post of the previous term. $args = array …
Category: Web

Get previous posts list

I'll give up. Have searched and searched and tried and tried... Can't find any solution to list previous posts. On a single post: I want to show a list of the 10 previous posts, the 10 before the current post. So, not just a two prev and next links. Not the most recent posts that is. A list of the the 10 previous posts before the current post you are visiting. I'm trying to make a query and comparing post_date …
Category: Web

Wordpress The Next Posts

So for previous and next posts I used this from wordpress codex <div class="navigation"> <p> <?php posts_nav_link('∞','Go Forward In Time','Go Back in Time'); ?> </p> </div> I want to change that.. in the wp-admin, I used on settings -> reading -> Blog pages show at most = 5 so I wanted to have a button to click on and load like 5 more posts, every time you click on the button and you are on the bottom of the page …
Category: Web

Display NEXT and PREVIOUS pagination?

I need help on the pagination. I try to put the NEXT and PREVIOUS pagination that show the post in a same category, but I am not sure what happen that showing nothing. If you can help, much thanks! <div class="row"> <div class="page"> <?php $previous_post = get_previous_post('%link', 'Next post in category', TRUE); if ( $previous_post ) : ?> <!-- [ PREVIOUS ITEM ]--> <div class="col-xs-6"> <?php if ( has_post_thumbnail( $previous_post->ID ) ) : ?> <?php echo get_the_post_thumbnail( $previous_post->ID, 'gallery-navigation' ); …
Category: Web

Get previously visited page ID

I would like to get the ID (or permalink) of the page the visitor visited just before visiting the current page - in other words the ID of the last page in the browser history. Can this be done? Any idea how to do it?
Category: Web

How can I change the prev / next buttons text to Dutch?

If you look to this page everything is alright except the previous and next buttons text are in English. Does anyone know how I can make them display in Dutch? I already tried to change them but no luck. NB: I'm using Contango theme. The function looks like this : /** Contango Link Pages */ function contango_link_pages() { $contango_options = contango_get_settings(); if( $contango_options['contango_post_style'] != 'excerpt' ) { return wp_link_pages( array( 'before' => '<div class="page-link"><span class="assistive-text">'. __( 'Pages:', 'contango' ) .'</span>', …
Category: Web

Previous and older set of posts links

I can't seem to display previous and older set of posts links. This is the page I am working on. I need a link to older and newer posts at the bottom of page. The template code is like this: <?php /* Template Name: artikkelit */ ?> <?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php $the_query = new WP_Query( 'showposts=5' ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <h3><a href="<?php the_permalink() ?>"><?php the_title(); …
Category: Web

Display different css or Information based on previous page

I've run into a bit of a tricky problem that I'm probably over thinking. I need to be able to display different css depending on what campaign page the user has come from. To better illustrate: Campaign 1 \ Campaign 2 ----> Information or css ----> page Campaign 3 / I hope this is understandable.
Category: Web

Category foreach Paging

I'm using the following code to display categories on my homepage, what I'd like to do is add the ability for paging with previous and next links, I haven't been able to figure out how to do this with a foreach can anyone point me in the right direction? Original Code: <?php $cat = get_cat_ID("Photos"); $categories = get_categories("child_of=$cat"); ?> <?php if (is_array($categories) && count($categories) > 0) : ?> <?php foreach ($categories as $category) { ?> <?php query_posts("cat=$category->cat_ID&orderby=rand&posts_per_page=1"); ?> <?php while …
Category: Web

Loop - how to get previous/next post for first/last post?

I have a simple loop for a JS slider, I want to display previous and next posts titles on my slide, but I can't get previous post title on the first slide (because apparently first post have no previous posts): $prev_post = $loop->posts[$loop->current_post - 1]; // ALWAYS NULL FOR FIRST POST :( $next_post = $loop->posts[$loop->current_post + 1]; // ALWAYS NULL FOR THE LAST POST echo $next_post->post_title; echo $next_post->post_title; Is there any easy way to fix that?
Category: Web

Getting meta content from get_next_post & get_previous_post

Is it possible to retrieve meta content for the get_next_post() and get_previous_post()? I'm currently using the following method, but not having much luck: <?php $prev_post = get_previous_post(); ?> <?php $prev_post->post_title(); ?> /* Returns content */ <?php echo get_post_meta( $prev_post->ID, 'meta_box1', true); ?> /* Doesn't return content */ Should I be forming the call differently?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.