Example for changing markup?
-
Hi,
Great plugin. Could you provide an example of changing the markup of the links output to a basic table instead of an unordered list?
-
Hi Lee,
Are you looking for actual
<table>
markup or just the links to show up in columns?I was looking to change the way it outputs the final markup…instead of ul / li format, i’d like to use table tr td format.
I saw on the developer page you have these lines:
apply_filters( ‘simple_links_markup’,’<ul id=”%s”>’, $this->full_args ); apply_filters(‘simple_links_link_markup’, ‘<li id=”link-%s”>’, $this->link, $this);
I’m just not sure how to implement those along with a filter like this:
add_filter( 'simple_links_link_output', 'adjust_simple_links_output',99, 6 ); function adjust_simple_links_output( $output, $data, $link, $image, $args, $obj ){ $obj->args['remove_line_break'] = true; $image = $obj->getImage(); $output = sprintf('<a href="%s" target="%s" title="%s" %s>%s%s</a>', $obj->getData('web_address'), $obj->getData('target'), strip_tags( $obj->getData('description') ), empty( $obj->meta_data['link_target_nofollow'][0] ) ? '': 'rel="nofollow"', $image, $link->post_title, date( get_option('date_format'), strtotime( $link->post_date ) ) ); return $output; }
Are those apply_filter lines for changing the markup like that? Is what I’m trying to do possible within the plugin?
Could you show an example of this?
I’m just trying to output the links in a table with the title, date and category in columns in a table, with each link item being its own row.
Something like this:
apply_filters( ‘simple_links_markup’,’<table id=”%s”>’, $this->full_args ); apply_filters(‘simple_links_link_markup’, ‘<tr id=”link-%s”>’, $this->link, $this);
I got this working temporarily by modifying the markup in the plugin script to be tables instead of uls. At least until I can figure it out. Any help or examples on doing this the right way would be greatly appreciated.
Hi Lee,
The first filter you will want to use is “simple_links_markup”. Something like this
add_filter( 'simple_links_markup', function(){ return '<table class="simple-links-list%s" %s>'; });
Then something like this:
add_filter( 'simple_links_link_markup', function(){ return '<tr class="%s" id="link-%s">'; });
Finally to alter the link output:
add_filter( 'simple_links_link_output', function($link_output, $meta_data, $link, $image, $args, $class ){ $category = wp_get_post_terms( $link->ID, 'simple_link_category'); //Main link output $link_output = sprintf('<td><a href="%s" target="%s" title="%s" %s>%s</a></td><td>%s</td><td>%s</td>', $class->getData('web_address'), $class->getData('target'), htmlentities(strip_tags( $class->getData('description') ), ENT_QUOTES, 'UTF-8'), empty( $meta_data['link_target_nofollow'][0] ) ? '': 'rel="nofollow"', $link->post_title, htmlentities(strip_tags( $class->getData('description') ), ENT_QUOTES, 'UTF-8'), $category[0]->name ); },1, 6);
This should get you close!
Awesome, thanks Mat! I appreciate your help! I will let you know how it works.
OK, this is a nice example to see… I’m looking for a way to skip the <a href if there is no web address supplied. (I’m repurposing the simple links as a publications database.. and sometimes there isn’t a link supplied to the actual paper, so it defaults to a plain citation. of course, if I don’t specify a web address, it puts in a href=”” so it links to the same page which is a little confusing.
So I would do something like (in the theme? or in functions.php?)
add_filter( 'simple_links_link_output', function($link_output, $meta_data, $link, $image, $args, $class ){ $category = wp_get_post_terms( $link->ID, 'simple_link_category'); //Main link output if (empty($class->getData('web_address'))) { $link_output=$link->post_title } else { $link_output= $output = sprintf('<a href="%s" [etc] } return $link_output; },1, 6);
??
Also, any hints on how to possibly add something to the shortcode such that I could say something like
[simple-links category=”<author name>” date=”2013″ description=”true”]
And it would list everything for that year?
- The topic ‘Example for changing markup?’ is closed to new replies.