Support » Plugin: Recently » Display Views Option greyed out

  • Resolved fragmented.ME

    (@indigotherapies)


    Hi there

    In widget settings there is an option to display views but mine is greyed out. I’m trying to use the plugin to display popular posts is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fragmented.ME

    (@indigotherapies)

    Fixed this issue.

    But wondering if I can use any of your logins to lis upcoming posts. Would love to be able to do this as I love the layout of them .

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi @indigotherapies,

    Recently can probably do this with some code tinkering but I’m a bit busy to test. Will come back later once I get some spare time to play around with this.

    Thread Starter fragmented.ME

    (@indigotherapies)

    Thank you I’ll look forward to it.

    Regards
    Denise

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Alright, so it’s doable but needs a few tweaks.

    First, you’ll want to hook into recently_pre_get_posts to have Recently fetch future posts. This is how it’s done:

    /**
     * Have Recently return future posts
     * for widget instance ID 'recently-2'
     *
     * @param  array   $args       The args passed to WP_Query.
     * @param  string  $widget_id  The ID of the current widget instance.
     * @return array
     */
    function recently_get_random_posts( $args, $widget_id ){
        if ( 'recently-2' == $widget_id ) {
            $args['post_status'] = 'future';
            $args['orderby'] = 'date';
            $args['order'] = 'ASC';
        }
        return $args;
    }
    add_filter( 'recently_pre_get_posts', 'recently_get_random_posts', 10, 2 );

    Notice how the code checks which widget is being rendered. If it’s the one with ID recently-2 then it’ll set the variables we need to have this particular widget list future posts instead of recently published ones (I figured you may want to use another Recently widget to list recent posts and so this allows you to do just that.)

    You can get the ID of the widget you want to use to list future posts either by adding the widget to your sidebar, then check the source code of your homepage (or wherever your sidebar is) to find the ID of the widget. Or you could just install the Get Widget ID plugin and see the ID right on the Widgets screen.

    Make sure to use the right ID for all this to work 😛

    Note though that Recently will render your future posts just like it would regular, published posts: with links. Since your future posts haven’t been published yet WordPress will use “ugly” URLs instead (eg. https://www.example.com/?p=3464.) If a visitor clicks on said ugly links they’ll be able to see the post, something I’m guessing you don’t want to happen 😛

    If you’re using the built-in themes (eg. Cards), you’ll want to replace any instances you find of the following Content Tags:

    • {title}
    • {thumb}

    … with their no-link counterparts:

    • {text_title}
    • {thumb_img}

    Yes, the design will change slightly as you’re replacing elements here but visitors won’t be able to read future posts ahead of time 😛

    It is possible to re-style the theme after these changes, however you’ll need at least some HTML/CSS knowledge to do so (or find/hire someone who knows.)

    If you have any questions don’t hesitate to ask.

    • This reply was modified 1 year, 8 months ago by Héctor Cabrera. Reason: Fixed link
    • This reply was modified 1 year, 8 months ago by Héctor Cabrera. Reason: Reworded for clarity
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display Views Option greyed out’ is closed to new replies.