WordPress.org

Ready to get started?Download WordPress

Forums

Flexible Posts Widget
[resolved] Adding HTML within widget title (10 posts)

  1. duncmorley
    Member
    Posted 1 year ago #

    Hi there

    I would really like to put HTML in the widget title box so that I can link the title to my taxonomy page. Could someone show me how I can go about doing this? I have tried removing strip tags etc with not much success.

    Many thanks

    http://wordpress.org/extend/plugins/flexible-posts-widget/

  2. DaveE
    Member
    Plugin Author

    Posted 1 year ago #

    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!

  3. duncmorley
    Member
    Posted 1 year ago #

    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.

  4. DaveE
    Member
    Plugin Author

    Posted 1 year ago #

    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

  5. duncmorley
    Member
    Posted 1 year ago #

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

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

    with zero success.

  6. duncmorley
    Member
    Posted 1 year ago #

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

  7. DaveE
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  8. duncmorley
    Member
    Posted 1 year ago #

    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

  9. DaveE
    Member
    Plugin Author

    Posted 1 year ago #

    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

  10. duncmorley
    Member
    Posted 1 year ago #

    That is absolutely wicked, thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic