最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shortcode - Wordpress Short code for List style

programmeradmin2浏览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');

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');
Share Improve this question asked Feb 11, 2015 at 4:35 BANNABANNA 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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');
发布评论

评论列表(0)

  1. 暂无评论