Site icon Sal et Humus

Plugin WordPress “Featured Articles Lite”: come mostrare l’”autore” degli articoli nelle slide

Se qualcuno volesse sapere come mostrare l’autore di un post in una slide, insieme al titolo, alla data e al contenuto, penso di aver capito come fare, quindi ecco come ho fatto.

Per prima cosa, aggiungete un’opzione nelle impostazioni dello slider.
In edit.php, dopo il codice:

<input type="checkbox" class="FA_optional" name="show_date" id="show_date" value="1" checked="checked" disabled="disabled" />
<label for="show_date" class="FA_optional disabled" title="">

aggiungete questo:

<input type="checkbox" class="FA_optional" name="show_post_author" id="show_post_author" value="1" checked="checked" disabled="disabled" />
<label for="show_post_author" class="FA_optional disabled" title="">

Poi, nella cartella del vostro tema fa-lite (io sto modificando classic), modificate questa funzione:

function fa_classic_optional_fields( $fields ){
$fields['classic_thumb_animate'] = 0; // 0 is disabled, 1 is enabled
return $fields;
}

aggiungendo questa riga:

function fa_classic_optional_fields( $fields ){
$fields['classic_thumb_animate'] = 0; // 0 is disabled, 1 is enabled
$fields['show_post_author'] = 1;
return $fields;
}

Poi in common.php, nella funzione ‘FA_slider_options’, nell’array ‘_fa_lite_aspect’, aggiungete “‘show_post_author’ => true” così:

'_fa_lite_aspect'=>array(
'section_display' =>1, // display title of slider
'section_title' =>'Featured articles', // default slider title
'slider_width' =>'100%', // slider width
'slider_height' =>300, // slider height
'thumbnail_display' =>true, // display article image
'th_size' =>'thumbnail', // article image size
'thumbnail_click' =>false, // article image is clickable
'title_click' =>false, // title is clickable
'title_custom' =>false, // custom defined title usage
'use_excerpt' =>false, // excerpt usage
'use_custom_text' =>false, // use custom text set on posts/pages
'strip_shortcodes' =>true, // remove shortcodes from post/page/custom slide content
'desc_truncate' =>500, // truncate descriptions with image
'desc_truncate_noimg' =>800, // truncate descriptions without image
'end_truncate' =>'...', // end truncated text with this
'read_more' =>'Read more', // read more link text
'allowed_tags' =>'<a>', // allowed tags in truncated descriptions
'allow_all_tags' =>false, // allow all HTML tags
'bottom_nav' =>true, // display bottom navigation
'sideways_nav' =>true, // display sideways navigation
'show_title' =>true, // show or hide titles
'show_text' =>true,
'show_read_more' =>true,
'show_date' =>true,
'show_post_author' =>true
),

Poi aggiungete una funzione in common.php:

/**
* Outputs the post author
*
* @param string $before - html to put before text
* @param string $after - html to put after text
* @param bool $echo - echo (true) or return(false) the html
* @return string - formatted date
*/
function the_fa_author( $before = '', $after = '', $echo = true ){
global $post, $FA_slider_options;
if( !$post || !$FA_slider_options['_fa_lite_aspect']['show_post_author'] ) return;
$author_id=$post->post_author;
$curuser = get_userdata($author_id);
$the_author = $curuser->display_name; // or $curuser->nicename
if( $echo ){
echo $before.$the_author.$after;
}else{
return $before.$the_author.$after;
}
}

E infine modificate di conseguenza il file display.php del tema fa-lite, nel punto in cui volete che compaia il nome dell’autore, con una riga come questa:

the_fa_author('by <span class="FA_post_author">','</span>');

Potete anche aggiungere un po’ di stile CSS al file stylesheet.css del tema fa-lite, usando la classe ‘FA_post_author’, magari così:

.FA_overall_container_classic .FA_featured_articles .FA_article span.FA_post_author{
font-size:14px;
font-weight: bold;
color:#DDDBA9;
}

Se c’è un modo migliore per farlo, fatemelo sapere. Soprattutto considerando che verrà tutto sovrascritto con qualsiasi aggiornamento del plugin…

Exit mobile version