• First of all, this plugin is great! I used to have 5 random posts hard-coded onto my sidebar. But this coding now produces 5 identical posts. I really like that the post dates can be added. But I couldn’t quite figure out what CSS to change to put the date inline with the title.

    I would like to display the titles only and put their post dates after each anchor tag, like this: title of random post, date

    Knowing only enough about PHP to get myself in trouble, I tried the following in my theme’s functions.php. I don’t know why I was surprised that it threw a blank page. Clearly, I have added incorrect coding.

    /*...............
    vi random posts add date after anchor tag for post title
    ...............*/
    
    add_filter('virp_get_random_posts', 'virp_add_date-to-titlespec');
    
    function virp_add_date-to-titlespec($virp-add_date) {
    $html .= '<a class="virp-title" href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( '%s', 'virp' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a>, ' . esc_attr(get_the_date(l, j F Y));
    
    return $virp-add_date;
    }

    Thank you for any help you can offer

    E Morris, etherwork [dot] net [slash] blog « purposely unlinked in attempt to keep spammers at bay

    Here is the coding (gleaned from the codex) that was on my sidebar and no longer works:

    <!-- start random post links -->
    <h2><?php _e('5 randomly chosen posts:'); ?></h2>
    <ul>
    <?php
    $args = array( 'posts_per_page' => 5, 'orderby' => 'rand', 'category__not_in' => array(9, 10, 11) );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    <li><a href="<?php the_permalink(); ?>"  title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    <!-- end random post links -->

    https://wordpress.org/plugins/vi-random-posts-widget/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Team Startbit

    (@vivacityinfotechjaipur)

    Hello llizard
    Greetings!!

    Thank you for using our plugin.

    I have looked into your issue as I can understand you want to show date with title in one line. So there is not need to write any code in functions.php file, Simply add the below jquery in your footer.php file and CSS in your stylesheet. Hope this will resolve your issue.

    <– CODE –>

    <script type=”text/javascript” >
    jQuery(document).ready(function(){
    jQuery(“#virp-widget-2 .fa-calendar”).css(“display”,”none”); // Replace #virp-widget-2 id with your id widget
    });
    </script>

    <style>
    .virp-li{display:flex}
    </style>

    See screenshot : http://awesomescreenshot.com/0825livx68

    Please let me know if you encounter any more issue.

    Don’t forgot to rate our plugin.

    Thanks & Regards
    Team Vivacity

    Thread Starter ejm

    (@llizard)

    Thank you for your response, Team Vivacity.

    Because I only know enough about php coding to put myself in hot water, I am using a child theme of TwentyTwelve and would rather not introduce any more files than necessary. Hence, I do not have a footer.php file.

    Also, I’m not sure I’m wild about the idea of using javascript to make this cosmetic change. (What happens if javascript is disabled?) Is there a way to change my css file only?

    jQuery("#virp-widget-2 .fa-calendar").css("display","none"); // Replace #virp-widget-2 id with your id widget

    Where do I find my id widget?

    E Morris, now updated to 4.4.2, etherwork [dot] net [slash] blog « purposely unlinked in attempt to keep spammers at bay

    Plugin Author Team Startbit

    (@vivacityinfotechjaipur)

    Hello llizard
    Greetings!!

    Ok, So you can directly use css instead of javascript.

    use this css : #virp-widget-2 .fa-calendar{display:none;}

    Please let me know if you encounter any more issue.

    Don’t forgot to rate our plugin.

    Thanks & Regards
    Team Vivacity

    Thread Starter ejm

    (@llizard)

    Thank you for your reply.

    Unfortunately that didn’t quite work – all that happened was that the calendar character before the date disappeared and the date was still on the next line instead of being inline. But your answer did point me in the direction of a solution that comes closer to my goal. Here is what I have put into my theme’s CSS to get the date to be inline with the post title to produce title of random post , date:

    .virp-clear {clear:none; display:inline !important;}
    .virp-meta {display:inline;}
    #virp-widget-2 .fa-calendar:before{content:",";}

    However, I don’t see how to remove the space that appears after the title and before the comma that is now there. Is there a way to insert the comma after the title? ie: which “.fa-” is the one that controls the title?

    And finally, is there a way to display the date as “j F Y”?

    Plugin Author Team Startbit

    (@vivacityinfotechjaipur)

    Hello llizard
    Greetings!!

    For displaying inline title and date you have to need add this css: #virp-widget-2 .virp-li{display:flex !important;}

    If you want to show date as “j F Y” format then you have to change code. Please follow instruction :
    1) Open plugin file virp.php and add this line
    <option value="j F Y" <?php selected( $instance['format'], 'j F Y' ); ?>><?php _e( 'j F Y', 'virp' ) ?></option>;
    before line 186. It will give functionality to add date in ‘J F Y’ format, then you can easily select this format from back-end widget.

    If you want to remove white space before date then open includes->functions.php and remove   from line 165. It will resolve issue of white space between date.

    Please let me know If you have any problem.

    Don’t forgot to rate our plugin.

    Thanks & Regards
    Team Vivacity

    Thread Starter ejm

    (@llizard)

    Thank you for your reply.

    The only problem I foresee with these solutions is that my fixes will be erased if/when the plugin has to be updated.

    How do I go about putting these changes into my theme’s function file?

    This following is my best guess at the coding for my theme’s function file, but it is no doubt wrong.

    /*...............
    virp date stamp
    ...............*/
    
    add_filter('virp_get_default_args', 'virp_change_datestamp');
    
    function virp_change_datestamp() {
            'format' => 'j F Y',
            }
    return $virp_change_datestamp;
    }
    
    add_filter('args', 'virp_fix_args');
    
    function virp_fix_args('date') {
     $date = $virp_fix_args['format'];
     $html .= '<span class="virp-meta"><i class="fa fa-calendar"></i>&nbsp;' . esc_html( get_the_date( $date ) ) . '</span>';
    
    return $virp_fix_args;
    }

    I’m a little reluctant to be risk breaking my wordpress by inserting poor function file coding.

    Please advise. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘add date to go after title’ is closed to new replies.