├── lang
├── byscripts_ajax_posts_loader-fr_FR.mo
└── byscripts_ajax_posts_loader-fr_FR.po
├── README.md
├── templates
└── settings.php
├── js
└── byscripts_ajax_posts_loader.js
└── byscripts_ajax_posts_loader.php
/lang/byscripts_ajax_posts_loader-fr_FR.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ByScripts/wordpress-ajax-posts-loader/HEAD/lang/byscripts_ajax_posts_loader-fr_FR.mo
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Wordpress Ajax Posts Loader
2 | ===========================
3 |
4 | Description
5 | -----------
6 |
7 | This [Wordpress](http://wordpress.org) plugin allows you to load the next page of posts with AJAX.
8 |
9 | It's based on Wordpress "posts per page" settings.
10 |
11 | If your blog displays 5 posts per page, each click on "Load more posts" will load 5 more posts.
12 |
13 | Configuration
14 | -------------
15 |
16 | You will need to configure the plugin to suit your website structure.
17 |
18 | * **Content CSS selector**: It's the CSS selector of the element at the bottom of which the "Load more posts" link will be added. (Default: `#content`)
19 |
20 | * **Pagination CSS selector**: It's the CSS selector of the pagination element which will be removed when the plugin is loaded. (Default: `.pagination`)
21 |
22 | * **Remove link after last result**: When checked, the "Load more posts" link will be removed after retrieving the last results. Else its label is replaced with "No more posts to load" (Default: `false`)
23 |
24 | Installation
25 | ------------
26 |
27 | 1. Upload the plugin in `/wp-content/plugins directory`.
28 | 2. Activate it through the 'Plugin' menu in Wordpress admin.
29 | 3. Go to `Settings > Ajax Posts Loader` to configure the plugin.
30 | 4. Open you CSS file and add styles to `#byscripts_ajax_posts_loader` element.
31 |
32 | Changelog
33 | ---------
34 |
35 | #### v0.5
36 |
37 | - Fix the plugin to works correctly with qTranslate
38 |
39 | #### v0.4
40 |
41 | - Add some description in admin page
42 | - Complete French translation
43 |
44 | #### v0.3
45 |
46 | - Better page link management. Should be compatible with any URL format.
47 |
48 | #### v0.2
49 |
50 | - Add option to remove link after the last results
51 |
52 | #### v0.1
53 |
54 | - First version
55 |
56 | License
57 | -------
58 |
59 | This plugin is released under the [MIT License](http://opensource.org/licenses/MIT).
--------------------------------------------------------------------------------
/templates/settings.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
identifier), 'ByScripts Ajax Posts Loader') ?>
4 |
5 |
36 |
--------------------------------------------------------------------------------
/js/byscripts_ajax_posts_loader.js:
--------------------------------------------------------------------------------
1 | jQuery(document).ready(function($) {
2 |
3 | var page_number_next = parseInt(byscripts_ajax_posts_loader.page_number_next), // The number of the next page to load (/page/x/).
4 | page_number_max = parseInt(byscripts_ajax_posts_loader.page_number_max), // The maximum number of pages the current query can return.
5 | page_link_model = byscripts_ajax_posts_loader.page_link_model, // The link of the next page of posts.
6 | $content = $(byscripts_ajax_posts_loader.content_css_selector), // The content Element posts are inserted to
7 | $pagination = $(byscripts_ajax_posts_loader.pagination_css_selector), // The wordpress default pagination
8 | $loaderTrigger;
9 |
10 | /**
11 | * Replace the traditional navigation with our own,
12 | * but only if there is at least one page of new posts to load.
13 | */
14 | if(page_number_next <= page_number_max) {
15 | // Insert the "More Posts" link.
16 | $content.append('{loadmore}
'.replace('{loadmore}', byscripts_ajax_posts_loader.load_more_str));
17 | $loaderTrigger = $('#byscripts_ajax_posts_loader_trigger');
18 |
19 | // Remove the traditional navigation.
20 | $pagination.remove();
21 | }
22 |
23 |
24 | /**
25 | * Load new posts when the link is clicked.
26 | */
27 | $loaderTrigger.click(function() {
28 | var next_link = page_link_model.replace(/\d+(\/)?$/, page_number_next + '$1');
29 |
30 | // Are there more posts to load?
31 | if(page_number_next <= page_number_max) {
32 |
33 | // Show that we're working.
34 | $(this).text(byscripts_ajax_posts_loader.loading_str);
35 |
36 | // Load more posts
37 | $.ajax({
38 | type : 'POST',
39 | url : next_link
40 | }).done(function(data) {
41 | page_number_next++;
42 |
43 | $loaderTrigger.before($(data).find(byscripts_ajax_posts_loader.content_css_selector).remove(byscripts_ajax_posts_loader.pagination_css_selector).html());
44 | $(byscripts_ajax_posts_loader.pagination_css_selector).remove();
45 |
46 | if(page_number_next <= page_number_max) {
47 | $loaderTrigger.text(byscripts_ajax_posts_loader.load_more_str);
48 | } else if(byscripts_ajax_posts_loader.remove_link_after_last_result) {
49 | $loaderTrigger.remove();
50 | } else {
51 | $loaderTrigger.text(byscripts_ajax_posts_loader.no_more_str);
52 | }
53 | }).fail(function() {
54 | $loaderTrigger.text(byscripts_ajax_posts_loader.error_str);
55 | });
56 | }
57 |
58 | return false;
59 | });
60 | });
61 |
--------------------------------------------------------------------------------
/lang/byscripts_ajax_posts_loader-fr_FR.po:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr ""
3 | "Project-Id-Version: ByScripts Wordpress Ajax Posts Loader\n"
4 | "POT-Creation-Date: 2013-11-02 18:22+0100\n"
5 | "PO-Revision-Date: 2013-11-02 18:22+0100\n"
6 | "Last-Translator: Thierry Goettelmann \n"
7 | "Language-Team: ByScripts \n"
8 | "Language: French\n"
9 | "MIME-Version: 1.0\n"
10 | "Content-Type: text/plain; charset=UTF-8\n"
11 | "Content-Transfer-Encoding: 8bit\n"
12 | "X-Generator: Poedit 1.5.4\n"
13 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n"
14 | "X-Poedit-Basepath: .\n"
15 | "X-Poedit-SourceCharset: UTF-8\n"
16 | "X-Poedit-SearchPath-0: ..\n"
17 |
18 | #: ../byscripts_ajax_posts_loader.php:79
19 | msgid "Load more news"
20 | msgstr "Charger plus d'actualités"
21 |
22 | #: ../byscripts_ajax_posts_loader.php:80
23 | msgid "Loading..."
24 | msgstr "Chargement..."
25 |
26 | #: ../byscripts_ajax_posts_loader.php:81
27 | msgid "No more news to load"
28 | msgstr "Il n'y a plus d'actualités à charger"
29 |
30 | #: ../byscripts_ajax_posts_loader.php:93
31 | msgid "Load the next page of posts with AJAX."
32 | msgstr "Charge la prochaine page d'articles via AJAX"
33 |
34 | #: ../byscripts_ajax_posts_loader.php:122
35 | msgid "You do not have sufficient permissions to access this page."
36 | msgstr "Vous n'avez pas la permission d'accéder à cette page."
37 |
38 | #: ../byscripts_ajax_posts_loader.php:129
39 | msgid "Settings"
40 | msgstr "Paramètres"
41 |
42 | #: ../templates/settings.php:3
43 | #, php-format
44 | msgid "%s Settings"
45 | msgstr "Paramètres de %s"
46 |
47 | #: ../templates/settings.php:11
48 | msgid "Content CSS selector"
49 | msgstr "Sélecteur CSS du contenu"
50 |
51 | #: ../templates/settings.php:14
52 | msgid ""
53 | "This is the HTML element where your posts are loaded.
If your list of "
54 | "post is in <div id=\"main\"></div>, set this parameter to #main"
55 | msgstr ""
56 | "C'est l'élément HTML où vos articles sont chargés.
Si votre liste "
57 | "d'articles se trouve dans <div id=\"main\"></div>, placez ce "
58 | "paramètre à #main"
59 |
60 | #: ../templates/settings.php:18
61 | msgid "Pagination CSS selector"
62 | msgstr "Sélecteur CSS de la pagination"
63 |
64 | #: ../templates/settings.php:21
65 | msgid ""
66 | "This is the HTML element which contains the site navigation/pagination."
67 | "
If your page selector is in <div class=\"my-pagination\"></"
68 | "div>, set this parameter to .my-pagination"
69 | msgstr ""
70 | "C'est l'élément HTML qui contient la navigation/pagination du site.
Si "
71 | "votre sélecteur de page est dans <div class=\"ma-pagination\"></"
72 | "div>, placez ce paramètre à .ma-pagination"
73 |
74 | #: ../templates/settings.php:28
75 | msgid "Remove link after last result"
76 | msgstr "Supprimer le lien après le dernier résultat"
77 |
78 | #: ../templates/settings.php:29
79 | msgid ""
80 | "Whether to remove or not the \"Load more posts\" link if there is no more "
81 | "results to load."
82 | msgstr ""
83 | "Supprimer ou non le lien \"Charger plus d'actualités\" s'il ne reste plus de "
84 | "résultats à charger."
85 |
86 | #~ msgid "ByScripts Ajax Load More Posts Settings"
87 | #~ msgstr "Paramètres de ByScripts Ajax Load More Posts "
88 |
--------------------------------------------------------------------------------
/byscripts_ajax_posts_loader.php:
--------------------------------------------------------------------------------
1 | identifier,
59 | plugin_dir_url(__FILE__) . 'js/' . $this->identifier . '.js',
60 | array('jquery'),
61 | '1.0',
62 | true
63 | );
64 |
65 | // Max number of pages
66 | $page_number_max = $wp_query->max_num_pages;
67 |
68 | // Next page to load
69 | $page_number_next = (get_query_var('paged') > 1) ? get_query_var('paged') + 1 : 2;
70 |
71 | // Add some parameters for the JS.
72 | wp_localize_script(
73 | $this->identifier,
74 | $this->identifier,
75 | array(
76 | 'page_number_next' => $page_number_next,
77 | 'page_number_max' => $page_number_max,
78 | 'page_link_model' => get_pagenum_link(9999999999),
79 | 'load_more_str' => __('Load more news', $this->identifier),
80 | 'loading_str' => __('Loading...', $this->identifier),
81 | 'error_str' => __('An error occured. Could not load more posts.', $this->identifier),
82 | 'no_more_str' => __('No more news to load', $this->identifier),
83 | 'content_css_selector' => get_option($this->prefix('content_css_selector'), '#content'),
84 | 'pagination_css_selector' => get_option($this->prefix('pagination_css_selector'), '.pagination'),
85 | 'remove_link_after_last_result' => get_option($this->prefix('remove_link_after_last_result'), false)
86 | )
87 | );
88 | }
89 |
90 | public function loadTextDomain() {
91 | load_plugin_textdomain($this->identifier, false, dirname(plugin_basename(__FILE__)) . '/lang/');
92 |
93 | // Small hack to make the string visible in PoEdit (I18n)
94 | __('Load the next page of posts with AJAX.', $this->identifier);
95 | }
96 |
97 | /**
98 | * Prefixes a string with an unique identifier
99 | *
100 | * @var string $str
101 | * @return string
102 | */
103 | private function prefix($string) {
104 | return $this->identifier . '_' . $string;
105 | }
106 |
107 | public function adminInit() {
108 | $this->registerSettings();
109 | }
110 |
111 | public function registerSettings() {
112 | register_setting($this->prefix('settings'), $this->prefix('content_css_selector'));
113 | register_setting($this->prefix('settings'), $this->prefix('pagination_css_selector'));
114 | register_setting($this->prefix('settings'), $this->prefix('remove_link_after_last_result'));
115 | }
116 |
117 | public function adminMenu() {
118 | add_options_page('ByScripts Ajax Posts Loader', 'Ajax Posts Loader', 'manage_options', $this->identifier, array($this, 'settingsPage') );
119 | }
120 |
121 | public function settingsPage() {
122 | if(!current_user_can('manage_options')) {
123 | wp_die(__('You do not have sufficient permissions to access this page.', $this->identifier));
124 | }
125 |
126 | include dirname(__FILE__) . '/templates/settings.php';
127 | }
128 |
129 | public function settingsLink($links) {
130 | $link = sprintf('%s', $this->identifier, __('Settings', $this->identifier));
131 | array_unshift($links, $link);
132 | return $links;
133 | }
134 | }
135 |
136 | new ByScriptsAjaxPostsLoader();
137 |
--------------------------------------------------------------------------------