【问题标题】:Title on a page with custom template带有自定义模板的页面上的标题
【发布时间】:2019-03-14 11:00:52
【问题描述】:

美好的一天! 我对 Wordpress 5.1.1 有一个奇怪的问题。我有两个带有自定义模板的页面,一个主页和一个博客页面。在其他页面上,我使用标准模板。在标准页面上,我可以看到页面标题,例如关于我们 - 站点名称、联系人 - 站点名称。 但是在这些自定义页面上它是空的!我只能看到站点名称和标题标签是空的。它可以是什么? 另外,我在博客页面上使用自定义 WP_Query。

更新

这是我的自定义博客页面:

    <?php
/**
 * Template Name: Статьи
 */
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 4, 'paged'=> $page ));
$categories = get_categories( array(
    'orderby' => 'name',
    'order'   => 'ASC'
) );
get_header(); 
the_title();
?>

<div id="blog_cards" class="ui grid">
    <div class="sixteen wide column">
            <div id="categories">
                <?php 
                foreach( $categories as $category ) {
                    $category_link = sprintf( 
                        '<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
                        esc_url( get_category_link( $category->term_id ) ),
                        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
                        esc_html( $category->name )
                    );

                    echo $category_link;
                }
                ?>
            </div>
    </div>
    <div class="sixteen wide column">
        <div class="ui two cards">
        <?php
        if ( $wp_query->have_posts() ) :
            while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
            <div id="post-<?php the_ID(); ?>" class="card">
                <div class="image">
                    <?php the_post_thumbnail();?>
                </div>
                <div class="content">
                  <div class="header"><a href="<?php the_permalink();?>" rel="bookmark"><?php the_title();?></a></div>
                  <div class="meta">
                    <a><?php the_time('d.m.Y');?></a>
                  </div>
                  <div class="description">
                    <?php the_content();?>
                  </div>
                </div>
                <div class="extra content">
                <?php 
                $post_cats = get_the_category();
                foreach( $post_cats as $category ) {
                    $category_link = sprintf( 
                        '<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
                        esc_url( get_category_link( $category->term_id ) ),
                        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
                        esc_html( $category->name )
                    );

                    echo $category_link;
                }
                ?>
                </div>
        </div>
        <?php endwhile;?>
        </div>
    </div>
    <div class="sixteen wide column">
        <?php if (function_exists('wp_corenavi')) wp_corenavi(array( 'wp_query' => $wp_query )); ?>
    </div>
    <?php 

    endif; ?>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();

另外,我尝试调用the_title(),它在模板正文中返回页面标题。但是标题标签是空的。 我为 woocomerce 使用标准店面主题。

【问题讨论】:

  • 请贴出您自定义模板的代码
  • 你必须使用 the_title();在模板上显示页面/帖子标题。
  • 请移步get_header();和 the_title();在 $page 之前,如果可能的话,我可以有你的网站链接吗..
  • 非常感谢你,达什!我刚刚把 get_header() 放在了顶部,就是这样!完美运行!
  • 我将其发布为答案,请接受它..

标签: wordpress


【解决方案1】:

请将get_header()移到页面顶部($page 之前)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多