PHP加载与源代码不同的结构

时间:2014-03-05 作者:will

我试图将条件语句编码到模板文件中,但遇到了一点问题。

这是文件中的代码

     else
            {
                echo(\'<div class="thumbList"><a href="\' . the_permalink() . \'"><div class="prod-thumb">\' . the_post_thumbnail( \'product-thumb\', array( \'class\' => \'product-thumb\' ) ) . \'</div> 
    <div class="prod-info">
        <span class="prod-ttl"><h4>\' . the_title() . \'</h4></span>
        <table class="prod-table">
            <tr class="odd"><td class="desc-title"><strong>Design No.:</strong></td><td><span>\' .  get_post_meta($post->ID, \'prod_id\', true) . \'</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Product Status:</strong></td><td><span>\' . get_post_meta($post->ID, \'prod_status\', true) . \'</span></td></tr>
            <tr class="even"><td class="desc-title"><strong>Style:</strong></td><td><span>\' . get_post_meta($post->ID, \'prod_style\', true) . \'</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Size:</strong></td><td><span>\' . wpautop(get_post_meta($post->ID, \'prod_sizes\', true)) . \'</span></td></tr>\' . ($post->prod_price && $post->prod_sale == ""?(\'<tr class="even"><td class="desc-title">Original Price:</td><td><span>\' . get_post_meta($post->ID, \'prod_price\', true) . \'</span></td></tr>\'):($post->prod_sale != ""?(\'<tr class="even"><td class="desc-title"><div style="font-weight:bold;color:#FF2929;">Sale Price:</div></td><td><span>\' . get_post_meta($post->ID, \'prod_sale\', true) . \'</span></td></tr><tr class="even"><td class="desc-title"><div style="text-decoration:line-through;color:#8C8C8C;">Original Price:</div></td><td><span><div style="text-decoration:line-through;color:#8C8C8C;">\' . get_post_meta($post->ID, \'prod_price\', true) . \'</div></span></td></tr>\') : \'<p></p>\')) . \'</table>
        <br/><br/>\' . ($post->post_content?(\'<div class="resp320Hid" style="color:#b8b042;"><div class="entry">\' . the_content() . \'</div></div>\'):\'\') . \'<div class="resp320Hid"><p><span>Click here to view more Details</span></p></div></div>\' . ($post->post_content?(\'<div class="resp320Show" style="clear:both;"><div class="entry">\' . the_content() . \'</div></div>\'):\'\') . \'<div class="resp320Show"><p><span>Click here to view more Details</span></p></div></a></div>\'
);}
这就是它应该输出的

    <div class="thumbList">                 
<a href="http://dev.imagecarpets.com/products/new-arrival/gabbeh-rug-12767/">           
    <div class="prod-thumb">                
        <img width="250" height="388" src="http://dev.imagecarpets.com/wp-content/uploads/2013/12/Gabbeh_12767__4.01x6.06-250x388.jpg" class="attachment-product-thumb wp-post-image" alt="Gabbeh_12767__4.01x6.06" />      </div>  
    <div class="prod-info">
        <span class="prod-ttl"><h4>Gabbeh Rug-12767</h4></span>
        <table class="prod-table">
            <tr class="odd"><td class="desc-title"><strong>Design No.:</strong></td><td><span>12767</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Product Status:</strong></td><td><span>In Stock</span></td></tr>
            <tr class="even"><td class="desc-title"><strong>Style:</strong></td><td><span>Allover</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Size:</strong></td><td><span><p>4.1 x 6.6</p>
单击此处查看更多详细信息

单击此处查看更多详细信息

</a>    

但是,由于某种原因,当页面加载到浏览器中时,它是这样的:

    http://dev.imagecarpets.com/products/contemporary-rug/moroccan-rug-140105/<img width="450" height="534" src="http://dev.imagecarpets.com/wp-content/uploads/2014/02/Morracan_140105_8.05X10.00DRK-1-450x534.jpg" class="product-thumb wp-post-image" alt="Morracan_140105_8.05X10.00DRK (1)" />Moroccan Rug-140105<div class="thumbList"><a href=""><div class="prod-thumb"></div>  
    <div class="prod-info">
        <span class="prod-ttl"><h4></h4></span>
        <table class="prod-table">
            <tr class="odd"><td class="desc-title"><strong>Design No.:</strong></td><td><span>140105</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Product Status:</strong></td><td><span>In Stock</span></td></tr>
            <tr class="even"><td class="desc-title"><strong>Style:</strong></td><td><span>Allover</span></td></tr>
            <tr class="odd"><td class="desc-title"><strong>Size:</strong></td><td><span><p>8.5 x 10</p>

单击此处查看更多详细信息

单击此处查看更多详细信息

缩略图图像和永久链接按照预期在thumblist类之外加载,链接不会变成链接。它只是打印未格式化的路径。我可能做了什么蠢事,但我想不出来。有人能帮忙吗

1 个回复
SO网友:Milo

您正在echo语句中使用模板标记,它们本身会回显一个值。您需要使用return 他们的价值。

the_permalink() 应该是get_permalink, the_post_thumbnail 应该是get_the_post_thumbnail, the_title 应该是the_title( \'\', \'\', false ), the_content 应该是get_the_content().

结束

相关推荐

Cannot override hooks.php

我为网络黑猩猩的“反应主题”构建了一个儿童主题。我想换一个钩子。所以我想我需要钩子。我的孩子主题中的php文件。所以我从父母那里复制了它。我制定了相同的层次结构(我想这是正确的方法)。wp-content/[my_child_theme]/core/includes/hooks.php 将文件复制到主题根目录没有帮助。我还试图重新创建这个关键钩子。我把代码放在子函数中。php文件,但它也不起作用,因为挂钩发生在主题内容之后(只是我的asumtion)。所以问题很简单:如何覆盖父主题的挂钩。php