Support » Plugin: WordPress Popular Posts » [Plugin: WordPress Popular Posts] Changing output based on daily, weekly, and monthly

  • Resolved jaggreene

    (@jaggreene)


    HI,

    I am using the php code template tags for wpp.

    I need a slight change in the output for the daily output vs the weekly output vs the monthly output.

    I have each of those outputs showing up in a different div that display as different tabs with jquery ui tabs.

    <div id="daily"><?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=daily&limit=3&pages=0&thumbnail_selection=usergenerated&thumbnail_height=139&thumbnail_width=182&wpp_start=<ol>&wpp_end=</ol>&do_pattern=1&pattern_form={title}{posttime}"); ?></div>'
    <div id="weekly"><?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=weekly&limit=3&pages=0&thumbnail_selection=usergenerated&thumbnail_height=139&thumbnail_width=182&wpp_start=
    <ol>&wpp_end=</ol>&do_pattern=1&pattern_form={title}{posttime}"); ?></div>'
    <div id="monthly"><?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=monthly&limit=3&pages=0&thumbnail_selection=usergenerated&thumbnail_height=139&thumbnail_width=182&wpp_start=<ol>&wpp_end=</ol>&do_pattern=1&pattern_form={title}{posttime}"); ?></div>'

    I have modified the $data variable in wpp to include the custom values I want as shown below.

    $data = array(
    						'title' => '<a>ID).'" title="'. $title_attr .'" onMouseOver="setpage(\'thumb1', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',
    						'summary' => $post_content,
    						'stats' => $stats,
    						'img' => $thumb,
    						'id' => $wppost->ID,
    						'posttime' =>  '<span class="wpp-post-time"> (\''.get_field('video_time', $wppost->ID).'\')</span>'

    This $data output works fine for daily div. But for weekly div, I need the line
    “setpage(\’thumb1′, \” to be “setpage(\’thumb2′, \” and for monthly div I need it to be “setpage(\’thumb3′, \”.

    This is to allow for the thumbnail of the post to show up in the proper div when someone mouseovers the post.

    So I figure I have two options.

    One is to create two new $data variables called $weeklydata and $monthlydata which would have new values assigned in the array.

    I tried setting them but not sure where all they would need to go to work.

    Secondly, I thought of changing the line

    "setpage(\'thumb1', \  to
    
    "setpage(\'thumb' .$thumbnumber.'\',

    Basically I need for the first three iterations of $data (since I have three posts per div) to have $thumbnumber=1, then the next three iterations $thumbnumber=2 and then last three $thumbnumber=3.

    Someone helped me create code to do this below, but with this code it just sets the $thumbnumber to 3 for all nine iterations.

    So i tried including the whole $data array in the for statement below, but it didn’t make a difference.

    for($i = 1; $i <= 9; $i++)
    {
            $thumbnumber = ceil($i/3);
            $thumbnumber = ($thumbnumber > 3) ? 3 : $thumbnumber;
    
    }

    I know this is complicated, but help would be appreciated, I am stuck on this one.

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there,

    Using the code you posted, I believe this is what you need:

    $t = ($instance['range'] == "daily") ? 'thumb1' : ($instance['range'] == "weekly") ? 'thumb2' : 'thumb3';
    
    $data = array(
        'title' => '<a>ID).'" title="'. $title_attr .'" onMouseOver="setpage(\'$t', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',
        'summary' => $post_content,
        'stats' => $stats,
        'img' => $thumb,
        'id' => $wppost->ID,
        'posttime' =>  '<span class="wpp-post-time"> (\''.get_field('video_time', $wppost->ID).'\')</span>'
    );

    By the way, you have a syntax error here:

    'title' => '<a>ID).'" title="'. $title_attr .'" onMouseOver="setpage(\'thumb1', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',

    Thread Starter jaggreene

    (@jaggreene)

    Hi,

    Thanks for the code. It works except for daily range.

    I copied the code, but when I had it as just

    onMouseOver="setpage(\'$t',

    It gave me a output like

    setpage('$t<span class=

    So I changed

    onMouseOver="setpage(\'$t',

    to

    onMouseOver="setpage(\''.$t.'\',

    but for the daily instance it comes out as thumb2.

    Here is my full code

    $t = ($instance['range'] == "daily") ? 'thumb1' : ($instance['range'] == "weekly") ? 'thumb2' : 'thumb3';
    
    					$data = array( 'title' => '<a href="'.get_permalink($wppost->ID).'" title="'. $title_attr .'" onMouseOver="setpage(\''.$t.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',
                                                     'summary' => $post_content,
                                                     'stats' => $stats,
                                                     'img' => $thumb,
                                                     'id' => $wppost->ID,
                                                     'posttime' =>  '<span class="wpp-post-time"> (\''.get_field('video_time', $wppost->ID).'\')</span>',
                                                     'jcode' => 'setpage(\''.$t.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')'
                                             );
    Plugin Author Hector Cabrera

    (@hcabrera)

    Try changing:

    $t = ($instance['range'] == "daily") ? 'thumb1' : ($instance['range'] == "weekly") ? 'thumb2' : 'thumb3';

    …for:

    if ($instance['range'] == "daily") {
    	$t = "thumb1";
    } else if ($instance['range'] == "weekly") {
    	$t = "thumb2";
    } else {
    	$t = "thumb3";
    }
    Thread Starter jaggreene

    (@jaggreene)

    Thanks!

    That worked well!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WordPress Popular Posts] Changing output based on daily, weekly, and monthly’ is closed to new replies.