• Resolved TheHungryGeek

    (@thehungrygeek)


    I’m trying to hack a plugin to insert the category name of the post above the post title in a plugin/widget that displays three posts in a single row on the front page.

    The hack I tried is as follows, but while it worked on localhost it did not work on my live installation – this is the hack I tried to be added at functions.php:

    $count = 1;
    
    function custom_cat_before_featured_page_title($tc_fp_title_block , $featured_page_title = '' ){
    $o = get_option('tc_pro_fpu');
    
    global $count;
    
    if($count == 1){
    $value = 'one';
    }
    if($count == 2){
    $value = 'two';
    }
    if($count == 3){
    $value = 'three';
    }
    $value = $count;
    
    @$id = $o["tc_featured_page_{$value}"];
    @$categories = get_the_category_list( ", ", "", $id );
    $cat = '';
    if(!empty($categories)){
    $cat = ' <div class="customizr-fpc-category">' . $categories . '</div>';
    }
    
    $count++;
    return $cat.$tc_fp_title_block;
    }
    add_filter( 'fpc_title_block', 'custom_cat_before_featured_page_title' );

    The files related to the plugin/widget in the theme are as follows:

    https://pastebin.com/X210VebN
    https://pastebin.com/Q7ugkAJr

    I appreciate all help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Besides server configuration, the usual reason for code working on your local installation but not on a production server is differences in PHP versions.

    You’ve initialized $count outside of the function. Be sure to declare it global both outside and inside the function. I’m not sure if that’s really the issue, but it’s the only thing I see that may be affected by PHP version.

    Assuming the $o array keys are of the form tc_featured_page_one and not tc_featured_page_1, I don’t understand the line $value = $count;. Why set $value to numeric words to only later set it to an integer? Type casting an integer into a string could be another difference in PHP version behavior, but I’m only guessing.

    Thread Starter TheHungryGeek

    (@thehungrygeek)

    Hi bcworkz, removing $value = $count did the trick!

    Thanks for your help ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to insert category name above post title in a featured pages plugin?’ is closed to new replies.