CakePHP 2 Pagination woes - pagination

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 :)

Related

Applying infinite scroll upon wooocmmerece site isn't working as expected

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.

CakePHP 2.1 custom url for pagination links

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'))
);

Watir won't select / find the link element

I've came to this problem for quite a few times now.
It appears that Watir won't find the anchor (link) element, when I want to find it by the following syntax:
#browser.link(:text => 'View page directly').click
If I try checking link presence it will say that it doesn't exist, although the link is there.
Here is the link to original source code that causes this behavior:
https://dl.dropbox.com/u/3290107/watir-test.xhtml
Why is this happening and how to fix it?
Thanks for help
This looks like a bug to me. You should report it here: https://github.com/watir/watir-webdriver/issues
browser.a(:text => "View page directly").present?
# => false
browser.as[-2].text
# => "View page directly"
browser.as[-2].present?
# => true

Pagination With Special Recent Posts Plugin (WordPress)

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

Strange pagination 404 issue with custom post type

I have a really strange problem trying to paginate custom posts types in their archives page, I created a custom post type called property and set an archive page called properties to show them all.
So inside my archive-property.php file added a form (GET method) with a dropdown box so users are able to set how many posts they want to display per page, it looks like this:
<select name="prop_number" id="prop_number">
<option value="12">12</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
So before everything I do:
if (isset($_GET)) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'property',
'paged' => $paged,
'posts_per_page' => 12 // Default number of properties per page
);
// Custom number properties per page
if (isset($_GET['prop_number']) && !empty($_GET['prop_number'])) {
$query_args['posts_per_page'] = $_GET['prop_number'];
}
}
query_posts($query_args);
// Do loop and other stuff
It works fine but when I use next_posts_link() to get to the second page I get a page not found 404 error, however if I go to my WP admin area and set the "Blog pages show at most" option to the same number I want per page in my select box (for example I manually set 25 on "Blog pages show at most" and select 25 in my prop_number select box) it does work fine.
I even tried using the WP-PageNavi plugin and it does render the correct amount of numbers depending on how many properties I want to show but I have the same problem 404 pages on any page I try to go unless I manually set the page in the backend.
If I didn't need the option to choose how many properties I want to show I'd just set the number manually but since users can choose between 3 options I can't set this to a fixed number in the backend.
Could anyone tell me what's wrong? Thanks in advance!
I'm not sure if you ever resolved your issue, but for the sake of anyone finding this question you may want to try flushing your permalink structure.
From http://codex.wordpress.org/Rewrite_API/flush_rules:
//Ensure the $wp_rewrite global is loaded
global $wp_rewrite;
//Call flush_rules() as a method of the $wp_rewrite object
$wp_rewrite->flush_rules();
Put that in your functions.php file, refresh your page, and see if that fixes your problem. It has for me in the past when I've had pagination 404 issues.
NOTE: once you have flushed your permalinks, remember to erase those two lines (see above) as you do not need or want that running every time a page is requested - it only needs to be done once. (This entire action may or may not be the same as going to the Permalinks page in your admin console.)

Resources