0

Hi I am using following short code to generate a list

[ul style="5"]
[li]Surgical Internship: Yale University – New Haven, Connecticut, 2001 [/li]
[li]Orthopaedic Residency: Yale University – New Haven, Connecticut, 2005[/li]
[li]Spine Fellowship: SpineCare, San Francisco Spine Institute – San Francisco,   California, 2006[/li]
[/ul]

I want its HTML generated like as follow:

<ul class="cg_style">
<li>Surgical Internship: Yale University – New Haven, Connecticut, 2001 </li>
<li]Orthopaedic Residency: Yale University – New Haven, Connecticut, 2005</li>
<li]Spine Fellowship: SpineCare, San Francisco Spine Institute – San Francisco,    California, 2006</li>
</ul>

I want to created a shortcode API in my themes function.php i have used following code but its not working like i need.

function coregnie_list_ul( $atts, $content = null ) {

//var_dump($atts);

return '<ul '.$atts->style .' >'.do_shortcode($content).'</ul>';
}
add_shortcode('ul', 'coregnie_list_ul');

function coregnie_list_li( $atts, $content = null ) {
 return '<li>'.do_shortcode($content).'</li>';
}
add_shortcode('li', 'coregnie_list_li');

1 Answer 1

1

I finally make it ready after some more research.

function coregnie_list_ul( $atts, $content = null ) {

extract(shortcode_atts(array(
  'style' => 'cg_list',
), $atts));

return '<ul class=cg_list_'.$style.' >'.do_shortcode($content).'</ul>';
}
add_shortcode('ul', 'coregnie_list_ul');

function coregnie_list_li( $atts, $content = null ) {
return '<li>'.do_shortcode($content).'</li>';
}
add_shortcode('li', 'coregnie_list_li');
1
  • I style like .cg_list_5 > li { list-style-type: square !important; color:#686868; font-family: "Lucida Sans",Arial,sans-serif; font-size:14px; }
    – BANNA
    Commented Feb 11, 2015 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.