• Resolved ralpharama

    (@ralpharama)


    Hi there,

    I installed the plugin and set it up connecting to GA fine, but I’m using a theme that isn’t widget aware:
    “The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change.”
    This means the widget link on the settings page for the plugin doesn’t work (broken link to https://www.mywebsite.com/wp/wp-admin/%7B!!%20admin_url(‘widgets.php’)%20!!%7D)

    So I followed the instructions to use the function in a template directly:
    “How can I use the plugin functionality outside the sidebar? The plugin offers 2 functions that can be used either in the theme or by another plugin.”
    https://www.presslabs.com/docs/code/toplytics/how-to-use-toplytics/

    Using this code:

    <?php
    	$toplytics_args = array(
    		'period' => 'month',  // default=month (today/week/month)
    		'numberposts' => 7,   // default=5 (min=1/max=250)
    		'showviews' => true   // default=false (true/false)
    	);
    	if ( function_exists( 'toplytics_results' ) )
    		toplytics_results( $toplytics_args );
    ?>

    But this fails as the ‘function_exists’ is false.

    Is there something I’m doing wrong? The theme is also a Roots/Bedrock/Sage variety, not sure if that’s relevant?

    Thanks for any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Presslabs

    (@presslabs)

    Hello,

    We’ll look into this and come back to you when we have more information.

    Best regards,

    Plugin Author Presslabs

    (@presslabs)

    Hello,

    Thank you for your patience.

    Upon further looking, the documentation is a bit old.

    The only solution that I found is to use this in PHP inside your theme
    echo do_shortcode( '[toplytics period="week" numberposts="5" showviews="true"]' );

    Also, if you want to style it differently, you can see more information here: https://github.com/presslabs/toplytics/blob/master/src/resources/views/frontend/widget.template.php

    Let me know if this works for you.

    Kind regards,

    • This reply was modified 3 years, 1 month ago by Presslabs.
    Thread Starter ralpharama

    (@ralpharama)

    Sorry for delay in this reply, I got this working. Not sure why it wasn’t, I just moved its position in the template. I think it’s to do with the odd way this WP project is configured. All good now, thanks for taking the time to investigate.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can’t use toplytics_results function in theme’ is closed to new replies.