I'm working on a wordpress, and have used this http://wp.tutsplus.com/tutorials/quick-tip-display-excerpts-of-child-pages-with-a-shortcode/ to make a short tag to list child pages on parent page.
However, I need to add a pagination into this, to list only 9 recent child pages on this page where I have short tag.
Any idea how to do it? Or some other idea to replace this with something that can support pagination to list child pages.
You need to adjust the $args to have a limit using posts_per_page.
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => 9
);
To get pagination working, I recommend Simple Pagination. Once installed, call this where you would like it to appear like so:
<?php if(function_exists('wp_simple_pagination')) {
wp_simple_pagination();
} ?>
Pagination doesn't work for Pages in Wordpress. Pages are not to be meant by paginated.
Related
I'm trying to implement jetpack's infinite scroll. my website has ?currency_switch=EUR and ?orderby=width-desc these kinds of custom URL parameters, which are successfully implemented without any ajax and for search I am using relevanssi.
I am using this code in my functions.php
function mytheme_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'multiple-products',
'type' => 'scroll',
'posts_per_page' => get_option( 'posts_per_page' )
) );
}
add_action( 'init', 'mytheme_infinite_scroll_init' );
It works (only at the shop page) but doesn't work with the custom url parameters as mentioned above and breaks for search.I didn't tweak any code for pagination(didn't alter any $paged stc).
How to handle it for custom query params? How to deal with relevanssi as it states that it doesn't support the jet pack plugin's infinite scroll feature, is there a way to make relevanssi results infinite scrollable via jet pack.
I tried my custom implementation , as a start tried making a simple ajax call but i am ending up with weird issues like this A simple Ajax call in wordpress doesn't give the expecetd output
Thanks
Sorry for the boring answer, but there's no way to make Relevanssi work with the Jetpack Infinite Scroll feature. You just need to disable it on search pages, as described in Relevanssi knowledge base.
I am using cakephp 2.1 and I defined pagination links in 'latest' view. Its showing controller and action names in url like
/pages/latest/page:2.
But I want only action name in url like
/latest/2.
Please suggest me how to do that?.. The work will be more appreciable..
You could define custom routes.
Routing in CakePHP also encompasses the idea of reverse routing, where an array of parameters can be reversed into a string url. By using reverse routing, you can easily re-factor your applications url structure without having to update all your code.
http://book.cakephp.org/2.0/en/development/routing.html
e.g.
Router::connect(
'/latest/:number',
array('controller' => 'pages', 'action' => 'view'),
array('pass' => array('number'))
);
I am having a problem getting the precise URL needed when using pagination in CakePHP 2.1.3 which needs to be the same as my custom route. Here is an example of what I have:
URL: /courses/section-name/cat-name/subcat-name
My route:
Router::connect('/courses/:section/:cat/:subcat/*', array(
'controller' => 'courses', 'action' => 'courseCategory'), array(
'pass' => array('section', 'cat', 'subcat'),
'section' => '[a-zA-Z0-9_-]+',
'cat' => '[a-zA-Z0-9_-]+',
'subcat' => '[a-zA-Z0-9_-]+'
));
Everything works fine in terms of normal navigation using this format and when visiting a page I get paginated results okay with all my links etc. I have set my Paginator Helper 'options' as follows:
$this->Paginator->options(array('url'=>$this->passedArgs));
This however produces a URL like eg: /courses/courseCategory/section-name/cat-name/subcat-name/page:2 which does not work.
If I manually remove the action name 'courseCategory' from the URL eg: /courses/section-name/cat-name/subcat-name/page:2 etc, then everything works fine and I go to the relevant page of results, so I guess I am close? However, after many hours of searching, reading the docs/API and trying different things I just cannot get my URL links to appear without the controller's action and it's now driving me mad!
So, I guess the question is either where am I going wrong or does anybody have an alternative solution to this?
Any help would be greatly appreciated & happy to provide more info if needed.
Thanks :)
I am using the 'Special Recent Posts' plug-in in WordPress. It is being used to show header images and excerpts for articles, which you then click through to the full article.
You can set parameters on that plug-in to tell how many recent articles you would like show. Basically what I want to do is show the first five articles on the main page and then have the overflow go to new pages (like an 'older posts' type thing where there would be five posts per page).
Can anyone help me get pointed in the right direction? Every time I Google this question it doesn't quite understand...Thanks.
EDIT:
I saw the first answer and while it is moving in the right direction, it doesn't automatically generate the new pages like I would like. I want to have the overflow of special recent posts generate a new 'previous' page automatically. I understand that I could manually do this but the blog I am working on will be getting updated every day so it would be very time consuming to constantly create new pages as I go along. Can somebody point me in the right direction?
EDIT:
Here is the full code I have on my index.php:
<?php get_header(); ?>
<?php c2c_the_category_image($image_extensions='png gif jpg', $image_dir='/wp-content/images/', $use_name_if_no_image=true, $start_from='begin', $limit=999); ?>
<?php echo do_shortcode("[srp srp_number_post_option='34' srp_thumbnail_option='yes' srp_widget_title_hide_option='yes' srp_post_date_option='no' srp_wdg_excerpt_length='50' srp_wdg_excerpt_length_mode='fullexcerpt']"); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The plugin has a parameter for this, from the documentation:
//Global Post Offset (to skip an arbitrary number of posts from the beginning)
srp_post_global_offset_option => numeric
So, on the second page, to skip 5 posts and then show the next 5, you would want something like this:
[srp srp_number_post_option='5' srp_post_global_offset_option='5']
Documentation: http://wordpress.org/extend/plugins/special-recent-posts/installation/
EDIT: To answer your question about generating new pages, technically you would not. You would have one page that would show different posts, acting like it was a different page. You would probably need use a query string (URL parameter). But, you can't put direct PHP into a wordpress post, so you need to either modify a PHP file, or get a WordPress plugin like Shortcode Exec PHP, so you can take the page number parameter from the URL and put it into the shortcode for special recent posts.
Example based on your index.php code:
$offset = ($_GET['page'] * 5) - 5;
echo do_shortcode("[srp srp_number_post_option='34' srp_thumbnail_option='yes'
srp_widget_title_hide_option='yes' srp_post_date_option='no'
srp_wdg_excerpt_length='50' srp_wdg_excerpt_length_mode='fullexcerpt'
srp_post_global_offset_option='".$offset."']");
Make your first page use
index.php?page=1
And your "Next Page" link:
$next = $_GET['page'] + 1;
echo 'Next Page';
I never worked before the special recent post plugin. So i would like to give WordPress query post solution.
First, to get recent five post in home page (index.php) use below query parameter.
$query = new WP_Query( 'posts_per_page=5');
Second, to list older post in other page use below query parameter.
$query = new WP_Query( array( 'posts_per_page' => 5, 'offset' => 5 ) );
Above query will get posts from 6 and 5 post per page.To add pagination, add paging parameter.Refer WP_Query
Pagination is now available in the new Special Recent Posts PRO Edition version 3.0.0
I'm struggling to paginate using mongoid. I'm able to call paginate on my collection object like
#results = #collections.paginate :page => 1, :per_page => 10
but how it needs to be referred in view?
In my view I have rendered the collection in partial as
<%= render :collection => #collections, :partial => collect.xml %>
<%= will_paginate #results %>
In the above line I get the error undefined method total_pages for array.
But there is no error if I remove the will_paginate call in view and all the collections are shown in the view without pagination. Pls help.
I think I'm going wrong in calling the pagination helper in view. I have searched for quite a long time and did not find an example that included the pagination call in view for mongoid.
Forgive me if it is a dumb question. I'm new to mongoid.
This method call
#results = #collections.paginate :page => 1, :per_page => 10
will populate #results with an array of 10 items from #collections. You don't need to do use will_paginate at all, just use the #results object as is.
If you get problems with the view giving more than 10 results, debug the controller and the view to ensure there isn't something in between messing with your #results array.
EDIT:
Aha, so the problem is in displaying pagination links on the view. Yes, for that you would need the view to know things like the current page and the total number of pages available, so that you can compute how many links are necessary.
In return, your links would need to let the controller know what page is being requested, which you can achieve with GET request parameters. Helpers are probably the best way to keep the view clean.