-2
我想弄清楚WordPress中的短代碼的PHP輸出。我需要知道這個簡短的代碼生成的實際的PHP,所以我可以硬編碼到模板中。試圖找出一種方法來輸出爲純文本的PHP
我發現負責該簡碼的功能,但我需要知道,如果有可能呼應PHP作爲純文本,所以我可以再次複製它
add_shortcode("thumbnailgrid", "thumbnailgrid_handler");
add_filter('query_vars', 'tbpage_vars');
function tbpage_vars($qvars)
{
$qvars[] = 'tg_page';
return $qvars;
}
//This is what takes the shortcode and generates the php
function thumbnailgrid_handler($atts) {
wp_enqueue_style('thumbnailgrid', plugins_url('css/thumbnailgrid.css', __FILE__));
$tg = new thumbnailgrid();
$output = $tg->thumbnailgrid_function($atts);
return $output;
}
class thumbnailgrid
{
function thumbnailgrid_function($atts) {
wp_reset_query();
if ($atts)
{
extract(shortcode_atts(array(
'height' => '',
'width' => ''
), $atts));
unset($atts["height"]);
unset($atts["width"]);
$the_query = new WP_Query($atts);
}
else
{
$the_query = new WP_Query('posts_per_page = -1');
}
$ret = '<div class="thumbnailblock"><div class="thumbnailgridcontainer">';
$style = "";
if ($height || $width)
{
$style = ' style="';
if ($height)
$style .= 'height:' .$height . ';';
if ($width)
$style .= 'width:' .$width . ';';
$style .= '"';
}
while ($the_query->have_posts()) :$the_query->the_post();
$titlelength = 20;
$permalink = get_permalink();
$title = get_the_title();
//$thumbnail = get_the_post_thumbnail();
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'thumbnail', true);
if ($image_id)
$thumbnail = '<img src="' .$image_url[0] .'"' .$style . '/>';
else
$thumbnail = '';
$tt = $title;
$im = '<div class="postimage"' .$style .'>
<a href="'. $permalink .'" title="'.$title.'">'. $thumbnail .'</a>
</div><!-- .postimage -->';
$ret .=
'<div class="griditemleft"' .$style .'>'
. $im ;
$ret .= '<div class="postimage-title">
<a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a>
</div>
</div><!-- .griditemleft -->';
endwhile;
wp_reset_postdata();
$ret .= '</div></div>';
return $ret;
}
function bkthumbnailgrid_function($atts) {
if ($atts)
{
extract(shortcode_atts(array(
'height' => '',
'width' => ''
), $atts));
unset($atts["height"]);
unset($atts["width"]);
$the_query = new WP_Query($atts);
}
$style = "";
if ($height || $width)
{
$style = ' style="';
if ($height)
$style .= 'height:' .$height . ';';
if ($width)
$style .= 'width:' .$width . ';';
$style .= '"';
}
$titlelength = 20; // Length of the post titles shown below the thumbnails
$bookmarks = get_bookmarks($atts);
$ret = '';
$titlelength = 20;
foreach ($bookmarks as $bookmark) {
$permalink = $bookmark->link_url;
$title = $bookmark->link_name;
$target = $bookmark->link_target;
$thumbnail = $bookmark->link_image;
if ($target != '')
{
$target = ' target="' .$target .'"';
}
if (strlen($title) > $titlelength)
$tt = mb_substr($title, 0, $titlelength) . ' ...';
else
$tt = $title;
$im = '<div class="postimage"' .$style .'>
<a href="'. $permalink .'" title="'.$title.'"'. $target .'><img src="'. $thumbnail .'"' . $style .'/></a>
</div><!-- .postimage -->';
$ret .=
'<div class="griditemleft"' .$style .'>'
. $im .
'<div class="postimage-title">
<a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a>
</div>
</div><!-- .griditemleft -->';
}
wp_reset_postdata();
return $ret;
}
}
,我需要一種方法來呼應或打印輸出原始的PHP作爲純文本出來,以便我可以複製它
這是很多代碼和這裏的大多數開發人員不希望添加額外的點擊到他們的援助路徑。我建議最小化代碼到最有問題的區域並在問題主體中發帖 –
您是試圖打印出代碼,還是希望打印出的變量設置爲其值? – sharf
只需要代碼即可 – user2185136