• Resolved Ernest

    (@ersaloz)


    I am just grasping the aptitude of MLA shortcodes to select image sources.

    Half this power with a GUI would be really pumping, by the way. Imagine choosing from categories, labels and custom categories; adjusting logical operators, max number of items, what not; fine tuning additions and exclusions… from within a GUI, and piping the output to any standard gallery. There is nothing of the kind AFAIK.

    But I am going off-topic. The matter is: I was trying to limit the number of items selected, using

    posts_per_page=7 posts_per_archive_page=3

    and I noticed only 3 items were shown in any kind of page, not just archive pages. Further testing using either of the options limited shown items to the given number, no matter which kind of page the post was displayed in.

    Maybe a theme issue? But it is behaving in e.g. related posts. Any clue about where to start looking?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter Ernest

    (@ersaloz)

    Another issue, somewhat related (maybe I rather open another thread?) surfaces in the Assistant listing, ‘MLA Gallery in’ field.

    We configured several galleries with
    tag=sometag order=random posts_per_page=5

    I would expect every media tagged ‘sometag’ to be listed in the ‘MLA Gallery in’ field, maybe with some indicator of eventuality; but obviously the Assistant is actually running the query to obtain the item ids: at every Refresh I get five different so-tagged images listed.

    • This reply was modified 9 years, 7 months ago by Ernest.
    • This reply was modified 9 years, 7 months ago by Ernest.
    • This reply was modified 9 years, 7 months ago by Ernest.
    Plugin Author David Lingren

    (@dglingren)

    It’s good to hear from you again and see the progress you’ve been making.

    Regarding your posts_per_page posts_per_archive_page question, MLA passes these parameters on to the WordPress WP_Query code for database access. I will have to do some testing to see if WP_Query is handling them as you expect. The WordPress documentation says:

    posts_per_archive_page (int) – number of posts to show per page – on archive pages only. Over-rides posts_per_page and showposts on pages where is_archive() or is_search() would be true.

    I will look into it.

    Regarding your order=random posts_per_page=5 question, you are exactly right. The “where-used” logic in MLA simply runs each shortcode it finds and records the results. For paginated [mla_gallery] shortcodes with random order, the results are as you described. I will have a look at this to see if removing the pagination parameters is practical.

    Finally, you wrote “this power with a GUI would be really pumping“. I agree, but given the number of shortcode parameters and their complexity you can imagine the magnitude of the effort involved! The WordPress core team is working on a new “shortcode API” intended to make the work easier, and I am waiting for that to progress before assessing the feasibility of undertaking the work.

    • This reply was modified 9 years, 7 months ago by David Lingren.
    Thread Starter Ernest

    (@ersaloz)

    Thank you!

    I am waiting for that to progress before assessing the feasibility of undertaking the work.

    Let’s wait then. Anyway, I was envisaging a GUI to just the most straight parameters, leaving the complex ones to the text interface.

    Thank you again.

    Plugin Author David Lingren

    (@dglingren)

    I am pleased to report that I was able to resolve both of your issues.

    The logic WP_Query WordPress uses to handle posts_per_archive_page is designed for queries on posts/pages; it does not work well for separate queries within the post/page to find [mla_gallery] items. I modified MLA to use the posts_per_archive_page parameter for galleries displayed when the enclosing post/page is part of a search result or archive page. I believe this is a more reasonable interpretation for most applications.

    I was able to remove pagination parameters from [gallery] and [mla_gallery] shortcodes for the purposes of “where-used” reporting, giving more complete and stable results. I also removed the “orderby” parameters to improve performance, since the order of the items does not affect the results.

    I have uploaded a new MLA Development Version dated 20161016 that contains both of the enhancements. To get the Development Version, follow the instructions in this earlier topic:

    Shortcode not working in (special) widget

    It would be great if you can install the Development Version and let me know if it works for you.

    Thread Starter Ernest

    (@ersaloz)

    Thank you! But, I am sorry to say, this works for me only in part.

    The ‘where used’ reporting works now as a charm.

    But the issue of not setting different limits to the number of displayed images depending on page type is still present.

    While trying to find out what is hindering the fix to work, I isolated the mla_gallery from other galleries, reordered parameters in various ways, used the alternative syntax… all to no avail. If the posts_per_archive_page parameter is present, this limit is used everywhere.

    Let me know if I can provide any additional info.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for taking the time to install and test the Development Version, and for confirming the where-used fix. I regret the trouble you’re still having with posts_per_archive_page.

    I do not think parameter order or alternative syntax will affect the results. Could you post the entire source text of the [mla_gallery] shortcode you are using?

    There may be some confusion over the definition of an “archive page”. On my system I tested the limits by adding an [mla_gallery] to a post and then displaying the month/year archive page that included that post. On that page the posts_per_archive_page was used. When I clicked on the post to display the whole thing the posts_per_page was used.

    When I put the same [mla_gallery] in a WordPress page, the posts_per_page was used.

    Can you tell me more about where the shortcode is placed and how you are viewing it?

    Thread Starter Ernest

    (@ersaloz)

    Yes, of course. I have set an entry on purpose to test this behaviour. The source reads:

    <p>blah blah blah</p>
    <div>[mla_gallery tag=cuadernos-de-viaje-la-litera orderby=rand posts_per_page=5 posts_per_archive_page=3 mla_alt_shortcode=gallery type=rectangular]</div>
    <p>blah blah blah</p>
    <p><!–more–></p>

    You can see it in the front page (set to ‘latest posts’) and in the single post view.

    I cannot leave it permanently without the mla_alt_shortcode stuff, but I did test that variation just in case and the number of thumbnails displayed is the same.

    What puzzles me is that, when the posts_per_archive_page parameter is present, this limit is used everywhere –even in single post display!

    Thank you.

    • This reply was modified 9 years, 7 months ago by Ernest.
    • This reply was modified 9 years, 7 months ago by Ernest.
    Plugin Author David Lingren

    (@dglingren)

    Thank you for the additional information and for the links to your example pages. I can see the behavior you have been describing, but I have no explanation for why it occurs.

    I am travelling and away from my development/test system until next Thursday. I will investigate further when I return and post an update when I have progress to report. Thank you for your patience.

    Thread Starter Ernest

    (@ersaloz)

    I will investigate further when I return

    If you need more details, testing or whatever, just let me know.

    Thank you and have a good journey.

    Plugin Author David Lingren

    (@dglingren)

    The source text of your example shortcode proved to be very useful. I did some testing and discovered that the “tag=cuadernos-de-viaje-la-litera” parameter unconditionally makes the shortcode an “taxonomy archive page” wherever it is used. I have adjusted the logic in the [mla_gallery] shortcode to account for that and I believe I have solved your problem.

    I have uploaded a new MLA Development Version dated 20161027 that contains the fix. It would be great if you can install the Development Version and let me know if it works for you.

    Thread Starter Ernest

    (@ersaloz)

    Thank you!

    It’s me now not having access to my usual system, but anyway I have managed to test the fix, and AFAICS what we get is the inverse behavior, that is, now the gallery we took as test case above, shows 5 images either in front page or in single entry page.

    Again I tried without the mla_alt_shortcode stuff, but the number of displayed thumbnails is always five.

    Do you think there is any hope we can benefit at the same time time of selection by tag and different limits depending on page type? If this is not feasible (I mean, fairly, without bothering you too much), we just let it go.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional results. It looks to me that neither your front page nor your single entry page are considered by WordPress to be an “archive page”. You can test this by adding mla_debug=true (to the screen) or mla_debug=log (to the error log) to your shortcode and then looking for “mla_debug is_archive()” and “mla_debug is_search()” in the debug output.

    On my system I was only able to see the posts_per_archive_page when I put the [mla_gallery] in a post (not a page) and viewed the monthly archive page that included the post.

    WordPress has many, many “conditional functions” including is_search() and is_archive() and (for your application) is_home() and is_front_page(). You can always use the hooks provided by [mla_gallery] to supply a specific posts_per_page value depending on whatever conditions you want. Let me know specifically what you are trying to accomplish and I can give you more specific guidance.

    Thread Starter Ernest

    (@ersaloz)

    The original intent was: for a post gallery, if media selection (either attached, from a taxonomy term, whatever) returns a lot of images, randomly pick a few of them to display at every HTML page serving.

    Then we realized that this ‘few’ concept was not the same for single post HTML pages, where 5 or 7 images would be a good approach, than for HTML pages displaying a list of post excerpts (front page, category listings, search results…), where 3 images would be more convenient.

    My error so far has been to take for granted that the front page, if set to ‘latest posts’, was kind of an archive page. Also when reporting about your fix (Development Version dated 20161027) I was comparing front page with single entry. Actually, if I trigger a category listing e.g. from menus, the same entry excerpt that in front page displays a gallery of 5 items, here shows a gallery with 3 images.

    The debug logs of course confirm that MLA logic is very honestly following the WP way of qualifying a page as ‘archive’.

    So our problem boils down to tell apart single posts from latest posts / category listings / whatever kind of page that displays a list of post excerpts.

    With this clear and your tips, I could delve afresh in the documentation, but I am new to hooks and, frankly, will appreciate any help.

    Thank you for your patience.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for confirming the update to posts_per_archive_page and clarifying your application requirements. I have developed a new example plugin to illustrate the use of [mla_gallery] hooks to apply any kind of “per page” logic you need, using the “front page” condition as an example. The complete example will be included in my next Development Version, but here is a version stripped of documentation for your immediate use:

    
    <?php
    /**
     * Adjusts the [mla_gallery] posts_per_page value based on WordPress conditional functions
     *
     * A custom "posts_per_front_page" parameter  adjusts the number of items generated for posts
     * displayed on the site's front/home page.
     */
    
    /*
    Plugin Name: Posts Per Page Example
    Plugin URI: http://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
    Description: Adjusts the [mla_gallery] posts_per_page value based on WordPress conditional functions
    Author: David Lingren
    Version: 1.00
    Author URI: http://fairtradejudaica.org/our-story/staff/
    
    Copyright 2016 David Lingren
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You can get a copy of the GNU General Public License by writing to the
        Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
    */
    class PostsPerPageExample {
        /**
         * Initialization function, similar to __construct()
         */
        public static function initialize() {
            // The filters are only useful for front-end posts/pages; exit if in the admin section
            if ( is_admin() )
                return;
    
            add_filter( 'mla_gallery_attributes', 'PostsPerPageExample::mla_gallery_attributes', 10, 1 );
        }
    
        /**
         * Process the 'posts_per_front_page' custom parameter
         */
        public static function mla_gallery_attributes( $shortcode_attributes ) {
            if ( empty( $shortcode_attributes['posts_per_front_page'] ) ) {
                return $shortcode_attributes;
            }
            
            if ( is_front_page() ) {
                $shortcode_attributes['posts_per_page'] = $shortcode_attributes['posts_per_front_page'];
            }
            
            return $shortcode_attributes;
        } // mla_gallery_attributes
    } // Class PostsPerPageExample
    
    // Install the filters at an early opportunity
    add_action('init', 'PostsPerPageExample::initialize');
    ?>
    

    You can copy the above code to a file with a “.php” extension and add it to your /wp-content/plugins/ directory. Then, activate it and add the posts_per_front_page=3 parameter to your [mla_allery] shortcodes.

    Let me know how it works for you.

    Thread Starter Ernest

    (@ersaloz)

    It works perfect, of course.

    Only, it has awaken my want for coding. I was refraining from this, but I think it’s hopeless now 😉

    Thank you very much.

Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘dealing with posts_per_page / posts_per_archive_page’ is closed to new replies.