在父页面上显示自定义域

时间:2014-02-19 作者:ltjfansite

我有很多子页面,每个子页面都有一些自定义字段。

我使用2个插件,成员级别使用eMember,自定义字段使用类型。

我试图在父页面上显示自定义字段信息。我的代码运行良好。但后来我又尝试再次拉入相同的数据,但只显示勾选了某个复选框的数据。我也能做到这一点。

但我的问题是,当我尝试同时运行这两个脚本时。我只得到要显示的第一个脚本结果。

我的代码是http://pastebin.com/vgeZwPxM

<!-- 
/////
START USER LOGGED IN
///// 
-->
<?php if(wp_emember_is_member_logged_in()) { ?>
    <!-- 
    /////
    START USER LOGGED IN - LEVEL PAID
    ///// 
    -->
    <?php if(wp_emember_is_member_logged_in(2)) { ?>
    <h3 class="grey">Top 3 In <?php wp_title(\'\'); ?></h3>
    <?php

        // Get the page\'s children
        $top3 = get_pages(\'child_of=\'.$post->ID.\'&sort_column=menu_order&parent=\'.$post->ID);

        if (!empty($top3)) { //check if there are any children pages.

        //If there are....
            global $post;
            foreach($top3 as $post) {

                $url = get_permalink($child->ID);
                $title = get_the_title($child->ID);
                $topThreeInArea =  types_render_field("top-3-in-area", array("raw"=>"true","separator"=>";"));
                $address =  types_render_field("address", array("raw"=>"true","separator"=>";")); 

                if ( !empty( $topThreeInArea ) ) {

                echo "<div class=\'col_3\'>";
                    echo "<h3><a href=\'".$url."\'>".$title."</a></h3>";

                        //If Address 
                        if ( !empty( $address ) ) {
                            echo "<p><i class=\'icon-pin\'></i>";
                            echo "<span>".$address."</span></p>";
                        }
 echo "<span>".$facilities."</span></p>";
                        }

                    echo "<a href=\'".$url."\' class=\'button green\'>Visit Website</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "</div>";
                }            
            }
        } 

    ?> 

    <div class=\'clear\'></div>

    <?php } ?>

    <!-- 
    /////
    END USER LOGGED IN - LEVEL PAID
    ///// 
    -->




<div id="county-nav" class="listNav"></div>
<ul class="county " id="county">
    <?php

    // Get the page\'s children
    $children = get_pages(\'child_of=\'.$post->ID.\'&sort_column=menu_order&parent=\'.$post->ID);

    if (!empty($children)) { //check if there are any children pages.

    //If there are....
        global $post;
        foreach($children as $post) {

            $url = get_permalink($child->ID);
            $title = get_the_title($child->ID);
            $address =  types_render_field("address", array("raw"=>"true","separator"=>";"));

            echo "<li class=\'\'>";
                echo "<h3><a href=\'".$url."\'>".$title."</a></h3>";
                echo "<div class=\'col_2\'>";
                    //If Address 
                    if ( !empty( $address ) ) {
                        echo "<p><i class=\'icon-pin\'></i>";
                        echo "<span>".$address."</span></p>";
                    }
                echo "</div>";
                echo "<div class=\'clear\'></div>";
                echo "<a href=\'".$url."\' class=\'button green\'>Visit Website</a>&nbsp;&nbsp;&nbsp;&nbsp;";
            echo "</li>";

        }
    }

?> 


</ul>
<?php } ?>
<!-- 
/////
END USER LOGGED IN 
///// 
-->
干杯词

1 个回复
SO网友:Sebastian Schmid

我也有同样的问题,找到了三种解决方法。很难说服类型从不同的帖子中读取数据,而不是从循环中当前的帖子中读取数据。。。

这是第一个解决方案,只需使用query_posts() 并通过types_render_field() 像往常一样。如果在实际循环之前执行此操作,请记住在之后重置查询;但我想你知道这一点。http://codex.wordpress.org/Function_Reference/wp_reset_query在主循环内部,我想这可能是一件几乎不可能完成的事情。

第二个解决方案是iirc,使用setup_postdata($post) 在您的foreach循环中。这有点神奇types_render_field() 进入你想要的岗位。同样,这会干扰所有功能,如the_ID()the_content() 这样你就可以把旧的global $post 到tmp变量,并通过setup_postdata($tmp).

作为最后的手段(有时是最简单的手段),您可以使用get_post_meta(). 要查找字段名,最好直接查看wp_postmeta 桌子我在数据库中找到了几个字段命名约定的指南,但经过一些尝试和错误之后,我总是开始Adminer 查看数据库。

所以,明智地选择:)

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register