我正在试图找出WordPress中短代码的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作为纯文本出来,以便我可以复制它
答案 0 :(得分:0)
<?php
header('Content-type: text/plain');
print file_get_contents("somepage.php");
?>