0

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

但是我不习惯这种带有 order by 的 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]);
4

1 回答 1

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();
?>

谢谢。

于 2013-11-06T10:25:00.570 回答