【问题标题】:Combining wordpress admin page content with custom template?将 wordpress 管理页面内容与自定义模板相结合?
【发布时间】:2026-01-24 20:05:02
【问题描述】:

有没有办法将 wordpress 页面的主要文本区域中的内容与其自定义模板中的内容结合起来?

在这种情况下,我有一个自定义模板,可以显示单个类别中的所有帖子,但我还希望有一个部分显示 wordpress 管理页面区域中写入的内容。

这就是我设置自定义模板以显示相关帖子的方式:

<?php query_posts('category_name=baby-coupons'); ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>                  

    <h2><a href="<?php the_permalink() ;?>"><?php the_title() ;?></a> <span class="post-date">- <?php the_time('F j, Y'); ?></span></h2>

    <div class="row">

        <div class="one-third">

            <?php 
            if ( has_post_thumbnail() ) { 
              the_post_thumbnail();
            } 
            ?>

        </div>

        <div class="two-third last">

            <?php the_excerpt() ;?>

        </div> 

    </div><!--/row-->    

    <hr>    

    <?php endwhile; ?>

在此之上,我想让 wordpress 页面管理区域内容显示,用户通常会写入 textarea 以显示在页面上,这可能吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    这是我想出的:

    <?php get_posts(); ?>
    
    <?php while ( have_posts() ) : the_post(); ?>  
        <?php the_content() ;?>
    <?php endwhile; ?>
    
    <?php query_posts('category_name=baby-coupons'); ?>          
    
        <?php /* Start the Loop */ ?>
        <?php while ( have_posts() ) : the_post(); ?>                  
    
        <h2><a href="<?php the_permalink() ;?>"><?php the_title() ;?></a> <span class="post-date">- <?php the_time('F j, Y'); ?></span></h2>
    
        <div class="row">
    
            <div class="one-third">
    
                <?php 
                if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                  the_post_thumbnail();
                } 
                ?>
    
            </div>
    
            <div class="two-third last">
    
                <?php the_excerpt() ;?>
    
            </div> 
    
        </div><!--/row-->    
    
        <hr>    
    
        <?php endwhile; ?>
    

    这可以接受吗?它正在工作,但我不确定它有多优雅!

    【讨论】: