0

我正在尝试使用此问题(和答案)中的代码来制作嵌套的年/月/帖子标题存档菜单:嵌套的年/月/帖子标题存档

不幸的是,代码不起作用(显示年份和月份,但帖子标题下没有显示任何内容)。知道我可能做错了什么吗?

<div class="blog-list-archive">

<?php
/**/
$years = $wpdb->get_col( "SELECT DISTINCT YEAR(post_date)
FROM $wpdb->posts WHERE post_status = 'publish'
AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) :
?>
<li><a href="JavaScript:void()"><?php echo $year; ?></a>

    <ul class="archive-sub-menu">
        <?    $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
        FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
        AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
        foreach($months as $month) :
        ?>
            <li><a href="<?php echo get_month_link($year, $month); ?>"><?php echo date( 'F', mktime(0, 0, 0, $month) );?></a>

                <ul class="archive-sub-menu">

                    <?  global $wpdb; $sposts = $wpdb->get_col( "SELECT ID 
                        FROM $wpdb->posts WHERE MONTH(post_date) = '$month'
                        AND YEAR(post_date) =  '$year' AND post_status = 'publish'
                        AND 'post_type' = 'post' ORDER BY post_date DESC" );
                        foreach( $sposts as $spost ) {
                    ?>
                        <li><a href="<?php echo get_permalink( $spost ); ?>"><?php echo get_the_title( $spost ); ?></a></li>

                        <?php } endforeach; ?>
                </ul>

            </li>

        <?php endforeach;?>

    </ul>

</li>

<?php endforeach; ?>

4

1 回答 1

1

这个循环:

foreach( $sposts as $spost ) {
?>
    <li><a href="<?php echo get_permalink( $spost ); ?>"><?php echo get_the_title( $spost ); ?></a></li>

<?php } endforeach; ?>

对我来说看起来很奇怪。如果您使用花括号,则不需要endforeach. 如果您想使用endforeach一致性,请使用冒号而不是大括号,就像您对其他循环所做的那样。

于 2013-02-28T22:04:16.163 回答