WordPress.org

Ready to get started?Download WordPress

Forums

Add code to sidebar when using widgets? (9 posts)

  1. thehealthyskeptic
    Member
    Posted 6 years ago #

    I'm using widgets with the Tarski theme. However, I just installed the Popularity Contest plugin and would like to configure it so that the most popular posts are displayed in the sidebar. The author of the plugin suggests putting this code in the sidebar.php file:

  2. <h2>Most Popular Posts</h2>
      <?php akpc_most_popular(); ?>
  3. But I don't know if that will work since I'm using widgets. Is there a way to do it actually using a widget? Or another way?

  • TrishaM
    Member
    Posted 6 years ago #

    look carefully at your sidebar.php file

    There is a line that says:
    ` <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>'

    And it will end with this line somewhere below:

    .<?php endif; ?>

    In between those two lines is where your widgets go. So either above or below it you can add that code you have. If you want it to be within those, you'll have to find a popular posts widget........

  • thehealthyskeptic
    Member
    Posted 6 years ago #

    Thanks for your reply, TrishaM. Actually, this is the full contents of my sidebar.php file:

    <div id="sidebar" class="secondary">
    
    	<?php th_sidebar(); // The magical sidebar hook ?>
    
    	<?php $wp_the_query->current_post--; setup_postdata($wp_query->next_post()); // Reset post data for comments ?>
    
    </div>

    I do not see the line of code that you mention above anywhere in the file.

    I believe this is because the Tarski theme has a hook for the sidebar. In the "Tarski Options" configuration panel in Admin>Settings, there is a menu where I can choose to enable Widgets, the Tarski sidebar, or my own sidebar.php file. Perhaps this explains why the code you mention is missing?

  • boober
    Member
    Posted 6 years ago #

    if youre using widgets anyways, just get the php code widget.

  • Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Yes, much simpler:
    http://wordpress.org/extend/plugins/php-code-widget/

    Install it, activate the plugin, use a PHP widget to put the code into.

  • boober
    Member
    Posted 6 years ago #

    its the first plugin i add to every wordpress site i make! thanks Otto!

  • thehealthyskeptic
    Member
    Posted 6 years ago #

    Thank you so much. This plugin is fantastic!

  • TrishaM
    Member
    Posted 6 years ago #

    VERY cool plugin! And to think I've been doing things the hard way :)

  • MySmithtown.net
    Member
    Posted 5 years ago #

    Works perfectly!

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags