Support » Plugins and Hacks » Flexible Posts Widget » [Resolved] Adding HTML within widget title

[Resolved] Adding HTML within widget title

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author DaveE


    Hi duncmorley,

    This would best be done within a custom HTML template. Flexible Posts Widget supports creating your own templates for displaying the posts widget. Instructions for getting started with the custom templates are here: http://wordpress.org/extend/plugins/flexible-posts-widget/installation/.

    Once you’ve got your own template running, you’ll want to concentrate on editing line 13, where the code is: echo $before_title . $title . $after_title;. You should be able to wrap the title in a link by adding your link HTML around the $title inside of the before & after variables.

    Hopefully that helps!

    Thanks. My issue is that I have 3 instances of the same widget on each page (in the footer). Each widget is showing all the posts for a different term. I just wanted to link the title to the term page so can’t hard code in 1 link.

    Plugin Author DaveE


    Yes, you’d need to setup the custom HTML template so that it will dynamically create the link based on the term chosen by the widget instance. You can get the chosen term in your template by using the variable $term in the template (it’s already setup by the widget beforehand).

    This codex doc should help: http://codex.wordpress.org/Function_Reference/get_term_link

    I really can’t work out how to do this. I’m using

    <?php echo get_term_link($term->slug); ?>

    with zero success.

    Is it possible to show an example of how to implement this? Many thanks.

    Plugin Author DaveE


    Yup, there’s an example of how to use the term link function right on the Codex link I provided before: http://codex.wordpress.org/Function_Reference/get_term_link#Examples.

    You’ll have to forgive me as taxonomies and terms etc are still a bit confusing for me (which is why I’m using your plugin to show them). I have this code but it is echoing all 3 terms and not just the one I have selected for the widget. I know that is because I’m using a foreach loop. Any chance of showing the correct way of doing it?

    <?php $terms = get_terms('tax_services_cat');
    foreach ($terms as $term) {
    	echo '<a href="'.get_term_link($term->slug, 'tax_services_cat').'"><h4 class="widgettitle">'.$term->name.'</h4></a>';
    } ?>

    Many thanks

    Plugin Author DaveE


    Here’s a bit of code that should accomplish what you’re asking for. You’ll need to replace lines 12 & 13 of your FPW custom template:

    if ( !empty($title) )
    	echo $before_title . $title . $after_title;

    with the code from this Pastbin example: http://pastebin.com/kcRbCn90

    That is absolutely wicked, thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Adding HTML within widget title’ is closed to new replies.
Skip to toolbar