簡體   English   中英

鏈接新的php頁面wordpress

[英]Link new php page wordpress

我試圖在index.php主題中使用引導選項卡,以在主頁主題中顯示不同的內容。 我已經在index.php中實現了選項卡,並在“流行”選項卡中創建了鏈接為“ popular-post.php”的新頁面。

但是,當我單擊鏈接以顯示受歡迎的內容時,我得到了

致命錯誤:調用未定義函數get_header()

這是我的index.php的代碼

    <?php get_header(); ?>
    <div class="row" id="content">
        <div class="col-sm-8 col-md-8 col-lg-8" id="primary">
        <ul class="nav nav-tabs">
  <li class="active"><a href="#">Home</a></li>
  <li><a href="<?php bloginfo('template_directory'); ?>/popular-post.php">Popular</a></li>
  <li><a href="#">Recientes</a></li>
</ul>



        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php
                /* Include the Post-Format-specific template for the content.
                * If you want to overload this in a child theme then include a file
                * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                */
                get_template_part( 'content', get_post_format() );
            ?>

        <?php endwhile;?> 
            <?php /* Pagnavi plugin support */ wp_pagenavi(); ?>

        <?php else: ?>  

            <?php get_template_part( 'no-results', 'index' ); ?>

        <?php endif; ?>
        </div>
        <div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
        <?php get_sidebar(); ?> 
        </div>
    </div><!--/content-->

        <?php get_footer(); ?>

這是Popular-post.php的代碼

<?php
/*
Template Name: Popular Posts
*/
?>
<?php get_header(); ?>
    <div class="row" id="content">
        <div class="col-sm-8 col-md-8 col-lg-8" id="primary">
        <ul class="nav nav-tabs">
  <li><a href="<?php bloginfo('template_directory'); ?>">Home</a></li>
  <li class="active"><a href="#">Popular</a></li>
  <li><a href="#">Recientes</a></li>
</ul>

<ul class="popular_posts">
        <?php $pc = new WP_Query('orderby=comment_count&#038;posts_per_page=10'); 

        while ($pc->have_posts()) : $pc->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            <p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
        <?php endwhile; ?>
    </ul>

        </div>
        <div class="col-sm-4 col-md-4 col-lg-4" id="secondary">
        <?php get_sidebar(); ?> 
        </div>
    </div><!--/content-->

        <?php get_footer(); ?>

提前致謝

您不能直接鏈接到主題文件,例如: <a href="<?php bloginfo('template_directory'); ?>/popular-post.php">Popular</a>
這是無效的URL: http://example.com/wp-content/themes/YOUR-THEME/any-theme-file.php : http://example.com/wp-content/themes/YOUR-THEME/any-theme-file.php

創建一個新頁面“ Popular Posts”,選擇模板(您的文件已經有一個Page Template頭。記下頁面ID(在URL中)。鏈接如下:

<a href="<?php echo get_permalink( THE-ID-OF-YOUR-PAGE ); ?>">Popular</a>

這將產生一個有效的URL: http://example.com/popular-posts/ : http://example.com/popular-posts/ ,這是您的內容(頁面)的一部分,使用定義的頁面模板文件。

要通過標題獲取頁面ID,請使用get_page_by_title

$the_page = get_page_by_title('popular-posts');
echo '<a href="' . get_permalink($the_page->ID) . '">Popular</a>';

閱讀有關模板層次結構的內容也將有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM