Wordpress Ordering(布尔?)

时间:2013-11-06 09:57:11

标签: php wordpress boolean

您好我想在wordpress中订购自定义字段。我有它显示单个项目。但无法弄清楚我是如何让它按顺序显示的。我创建了一个名为project_order的字段,它可以在另一个页面上正常工作。

但是我不习惯这种带有顺序的php。这是一个由其他人设计的项目,所以我正在努力学习如何构建它。

<?php
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;

//link to view all projects for product
echo '<p><a href="'.get_permalink($sector[$post->post_name]).'" class="bigbutt">View all projects</a></p>';
?>
</div>

<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');


//display latest project
if ($rows) {

    echo '<div class="row">';

    if ($rows[0]['project_pageturner']) {
        echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
    } else if ($rows[0]['project_pdf']) {
        echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
    } else {
        echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
    }
    echo '<div class="span2">';
        if ($rows[0]['project_thumbnail']) {
            echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
        } else {
            echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
        }
    echo '</div>';
    echo '<div class="span3">';
    echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
    echo '<p>View project &raquo;</p>';
    echo '</div>';
    echo '</a>';

    echo '</div><!--row-->';

} else {
    echo '<p>No projects to display currently.</p>';
}
?>

我猜它会与之有关。

$rows = get_field('projects', $sector [$post->post_name]);

1 个答案:

答案 0 :(得分:1)

尝试以下代码,可能会解决您的问题。

<?php
wp_reset_query();
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;

//link to view all projects for product
echo '<p><a href="'.get_permalink($sector[$post->post_name]).'" class="bigbutt">View all projects</a></p>';
?>
</div>

<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');


//display latest project
if ($rows) {

    echo '<div class="row">';

    if ($rows[0]['project_pageturner']) {
        echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
    } else if ($rows[0]['project_pdf']) {
        echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
    } else {
        echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
    }
    echo '<div class="span2">';
        if ($rows[0]['project_thumbnail']) {
            echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
        } else {
            echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
        }
    echo '</div>';
    echo '<div class="span3">';
    echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
    echo '<p>View project &raquo;</p>';
    echo '</div>';
    echo '</a>';

    echo '</div><!--row-->';

} else {
    echo '<p>No projects to display currently.</p>';
}
wp_reset_query();
?>

感谢。