我只是需要一些关于WordPress快捷码函数的帮助。我想创建一个基于link\\u类别的链接列表,其中包含一个短代码。在向函数中添加limit参数之前,我一直使用该快捷码。那么基本上有人能帮我纠正这个问题吗?下面可以看到从我的函数中复制的代码。php文件。请注意,我不是php专家,但我可以像champ一样编辑/破坏现有代码。所讨论的站点是http://linuxlibrary.org
我感谢你的帮助!
add_shortcode(\'lynx\', \'lynx_shortcode_handler\');
function lynx_shortcode_handler($atts)
{
// extract parameters
$parms = shortcode_atts(array(
\'cat_name\' => \'Learn More\',
\'limit\' => \'5\',
\'use_description\' => \'false\',
\'use_image\' => \'false\',
\'before_line\' => \'<li>\',
\'after_line\' => \'</li>
\',
\'before_content\' => \'<ul>
\',
\'after_content\' => \'</ul>
\',
\'target\' => \'\',
\'xfn\' => \'\',
), $atts);
$cat_name = $parms[\'cat_name\'];
$use_description = strtolower($parms[\'use_description\']);
$limit = $parms[\'limit\'];
$use_image = strtolower($parms[\'use_image\']);
$before_line = $parms[\'before_line\'];
$after_line = $parms[\'after_line\'];
$before_content = $parms[\'before_content\'];
$after_content = $parms[\'after_content\'];
$target = $parms[\'target\'];
$xfn = $parms[\'xfn\'];
// process t/f options
$b_use_description = false;
if (($use_description == \'yes\') || ($use_description == \'y\') ||
($use_description == \'true\') || ($use_description == \'1\'))
{$b_use_description = true;}
$b_use_image = false;
if (($use_image == \'yes\') || ($use_image == \'y\') ||
($use_image == \'true\') || ($use_image == \'1\'))
{$b_use_image = true;}
// exit
return lynx($cat_name, $b_use_description,
$b_use_image, $before_line,
$after_line, $before_content,
$after_content, $target, $xfn);
}
}
function lynx(
$cat_name=\'Learn More\',
$limit=\'5\',
$use_description=\'1\',
$use_image=\'1\',
$before_line=\'<li>\',
$after_line=\'</li>
\',
$before_content=\'<ul>
\',
$after_content=\'</ul>
\',
$target=\'\',
$xfn=\'\')
{
// get the data
$args = array(\'limit\' => $limit,
\'orderby\' => \'rating\',
\'order\' => \'DESC\',
\'category_name\' => $cat_name);
$bookmarks = get_bookmarks($args);
// process the data
$output = $before_content;
foreach ($bookmarks as $bmk)
{
$bmk_link = $bmk->link_url;
$bmk_name = $bmk->link_name;
$bmk_description = $bmk->link_description;
$bmk_image = $bmk->link_image; // works best with icons (like favicon.ico)
$href = \'<a rel="\' . $xfn . \'" href="\' . $bmk_link . \'" target="\' . $target . \'">\' . $bmk_name . \'</a>\';
$output .= $before_line;
if ($use_image == \'1\')
{
// assumes 16x16 icons and aligns margin accordingly
// MSIE has issues with some favicon.ico files
$output .= \'<img src="\' . $bmk_image . \'" width="16" height="16" style="margin-bottom:-2px;" /> \';
}
$output .= $href;
if ($use_description == \'1\')
{
$output .= \' \' . $bmk_description;
}
$output .= $after_line;
}
// exit
$output = $output . $after_content;
return $output;
}