Tag Info

Hot answers tagged

5

Understanding the internals The "sort" order of adjacent (next/prev) posts is not really a sort "order". It's a separate query on each request/page, but it sorts the query by the post_date - or the post parent if you have a hierarchical post as currently displayed object. When you take a look at the internals of next_post_link(), then you see that it's ...


5

Building on Bainternet's answer above, but making it more generic, I wrote this quick plugin. You can probably modify the link building function at the bottom to do what you want more exactly. <?php /* Plugin Name: Search Context Description: Use search context on single post pages when they're reached from a search results page to adjust the prev/next ...


5

try to work with http://codex.wordpress.org/Function_Reference/get_adjacent_post; example: $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID ); $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)->ID );


4

I'm trying to do this right now as well. The filter function seems like the best bet. This is where I'm at now, but I can't seem to get the title of the next or previous post and pass it to the filter. Edit: Figured it out. A bit hackey probably, but it works. add_filter('next_post_link','add_title_to_next_post_link'); function ...


3

Here's a way to do it without modifying the core: add_action('admin_footer','preview_same_window'); function preview_same_window(){ ?> <script type="text/javascript"> jQuery(function($){ jQuery('.preview.button').unbind().removeAttr('target'); setTimeout(function(){ ...


3

As the documentation for next_post_link states, the link parameter is where the actual text of the %link placeholder goes. The format parameter is the whole text, where %link is unpacked from the second link parameter. Solution: next_post_link( '%link', '%title &rarr;' ); Expected output: <a href="...">Title &rarr;</a> Something like ...


3

"Inside the Loop" essentially means that function relies on data from global variables (such as $post) that are set up when Loop runs. Note that this is not necessarily done by main Loop of query_posts(). In your specific code those variables are filled by $custom_posts->the_post() calls and after that wp_reset_query() gets those values back to initial ...


2

Update As I deleted the Repo on GitHub, here's a new answer. add_filter( 'previous_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); add_filter( 'next_post_link', 'wpse13044_adjacent_post_link_tooltip', 10, 2 ); function wpse13044_adjacent_post_link_tooltip( $format, $link ) { $previous = 'previous_post_link' === current_filter(); // Get ...


2

If you take a look at the source, next_post_link is just a wrapper for adjacent_post_link. Unfortunately, this function doesn't take any form of 'echo' parameter, so you'll either need to replicate the code in your own function & return the value, or catch it in an output buffer; ob_start(); next_post_link(); $next_post_link = ob_get_clean();


2

You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month. <?php $page = get_query_var('paged') ? get_query_var('paged') : 1; $subtractor = $page-1; $date = date("Y-m-d H:i:s"); $current_month = date('n', ...


2

Take a look at get_previous_post() and get_next_post() and you'll see they both use the get_adjacent_post() to find the previous or next post. Let's say you want to fetch the ID of the immediately previous post based on the current post's ID. This is what you'd do: get_previous_post_id( $post_id ) { // Get a global post reference since ...


2

This could be acheived by using the get_previous_post() and get_the_post_thumbnail() functions. Then just pass the thumbnail value into the second parameter of previous_post_link(). $prevPost = get_previous_post(); $prevThumbnail = get_the_post_thumbnail( $prevPost->ID ); previous_post_link( '%link', $prevThumbnail );


2

next_post_link & previous_post_link work off the global $wp_query. You could simply overwrite the main query with $wp_query =& $query, or replace your custom query with the standard 'global' functions. <?php query_posts( array( "post_type" => "page", "page_id" => $post->ID ) ) ?> <?php if ( have_posts() ) : ?> <?php ...


1

I cannot think of any one plugin or theme that would handle that exactly; but you could disable the previous/next post links and try rather to display other posts in the sidebar with similar post_types / categories. This plugin has many options to display easily in a widget area: WP Category Posts List ...


1

This is the default in WordPress Twenty Eleven Theme <nav id="nav-single"> <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ...


1

There are the core functions next/previous_post_link() that accept several arguments. The 3rd is the one that triggers in_same_cat. So if you set that one to TRUE, then you'll only get posts that are in filed under the same category.


1

Try without passing the true argument to get_previous_post() function, because that paramters is used to get link of previous post of same category. Possibly you've not registered the category taxonomy while registering that custom post type.


1

&reel=commercials?paged=2 That's the problem at the end of that query string. You can't start a query string twice so that ?paged=2 bit is being read as part of the reel parameter's value. The question mark should be another & eg: ?author=2&reel=commercials&paged=2


1

You need to do a little "hack" to get pagination to work for your custom loop. After you define $loop, do the following: <?php // globalize $wp_query global $wp_query; // copy $wp_query into a temporary variable $temp_wp_query = $wp_query; // nullify $wp_query $wp_query = null; // move $loop into $wp_query $wp_query = $loop; ?> At this point, your ...


1

That is not the way WordPress Works, meaning that once you enter s single post from the search results you lose the search context and WordPress can't tell if you came for the search results, an archive, category page or whatever. The only way i can think of to by pass that is to create your custom search results page where you should add parameters to the ...


1

Just use this, no extra functions required: <div class="previous-post"> <?php previous_post_link(' &laquo;%link ') ?> </div> <div class="next-post"> <?php next_post_link(' %link &raquo; ') ?> </div> Just add this to the single.php, not the index.php. This is the simple way to show in single posts only (this ...


1

Don't use query_posts! As Eugene pointed out, you omitted the paged variable. However, even with that in you can get unexpected behaviour. As illustrated by the various questions we get on query_posts and pagination: query_posts and pagination, still stuck after much research Pagination throws 404 Pagination throws 404 error on custom taxonomy archive ...


1

You have to add paged argument to query_posts call. It should look like this: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 'trips', 'types' => $types, 'posts_per_page' => 5, 'paged' => $paged, ) ); ?> Read more about WP_Query in ...


1

The short answer is that there's not really an easy way to do it. There is a solution, but it's sort of ugly. (see waay below.) A Longer Answer I'm including this here in the hopes that it's helpful to someone. Whenever you happen to be using a built in WordPress function, it's instructive to actually go look at what the function does. This is ...


1

It sends you to the next/prev post by date of been published. I don't know what gives you these next/prev links and where (single.php, category.php, archive.php or any other custom template file). Without knowing more (some code example) all that I can give to you is this: $page_nr = '&paged='; $page_nr = get_query_var( 'paged' ) ? ...


1

use get_adjacent_post(). if nothing is returned for next/prev, get the first/last. Edit- just noticed your custom post type, you'll also have to filter get_previous_post_where and get_next_post_where to pick up your cpt.


1

Haven't checked the plugin you mention... but I use this solution for doing an "author" navigation. I adjusted the functions and this should probably work without the plugin (untested). You need to adjust the ID, and the conditions itself if you want more exclusions. [edit: corrected functions, the queries were missing the menu_order condition] notes: ...


1

First thing to do is check for any plugins that affect search results. The reason is that I had the 'Search Everything' plugin running. While it was meant to search for more results and highlight the search terms, it will change any instance of new WP_Query(); making it useless. This is the callback function to load posts with ajax. The calling function ...


1

A bit old perhaps, and I wasn't really sure on how to make a comment on a reply... In short, after looking for the same solution I've modified Picard102's suggestion just a tiny bit: /** * Filter previous_post_link and next_post_link */ function filter_next_post_link($link) { global $post; $post = get_post($post_id); $next_post = ...


1

Update: OK. If you get to keep changing the question, I get to delete what I had written before and start all over again. To be honest, I'm a bit confused about what you are trying to do. Since this appears to be for a single post (based on the comment at the top of your template), it is unclear to me what your first 2 custom loops are meant to accomplish. ...



Only top voted, non community-wiki answers of a minimum length are eligible