dongwuzun4630 2017-05-18 13:31
浏览 69
已采纳

带有get_title的Wordpress问题 - 显示轮播幻灯片的标题?

My page.php page looks like this:

<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header() ?>
<div class="content">

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

<?php
// TO SHOW THE PAGE CONTENTS

    while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
        <div class="entry-content-page">
            <?php the_content(); ?> <!-- Page Content -->
        </div><!-- .entry-content-page -->

    <?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>



</div>
<?php get_footer() ?>

What's actually happening though, is that rather than displaying the title of the page (i.e "About Us" it's actually displaying the title of the first slide from the carousel on the page (i.e "Slide One")

http://www.scottdaviesdesign.co.uk/donationboxes is the URL if it's easier for you all.

I've tried a few other ways of displaying the title, ie, by ID etc but none are working, they all just come up with "Slide One".

Any ideas?

Here's the header code as well. I'm using "Super Hero Slider" for the carousel:

                <!doctype html>
                <html <?php language_attributes(); ?> class="no-js">
                    <head>
                        <meta charset="<?php bloginfo('charset'); ?>">
                        <title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' :'; } ?> <?php bloginfo('name'); ?></title>
                        <link href="https://fonts.googleapis.com/css?family=Hind|Montserrat|Ek+Mukta:400,700" rel="stylesheet"> 
                        <link href="//www.google-analytics.com" rel="dns-prefetch">
                        <link href="<?php echo get_template_directory_uri(); ?>/img/icons/favicon.ico" rel="shortcut icon">
                        <link href="<?php echo get_template_directory_uri(); ?>/img/icons/touch.png" rel="apple-touch-icon-precomposed">

                        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                        <meta name="viewport" content="width=device-width, initial-scale=1.0">
                        <meta name="description" content="<?php bloginfo('description'); ?>">

                        <?php wp_head(); ?>
                        <script>
                        // conditionizr.com
                        // configure environment tests
                        conditionizr.config({
                            assets: '<?php echo get_template_directory_uri(); ?>',
                            tests: {}
                        });
                        </script>

                    </head>
                    <body <?php body_class(); ?>>

                                            <div id="donation-boxes-header">
                                      <div class="alignleft"><a href="#"><img src="http://scottdaviesdesign.co.uk/donationboxes/wp-content/uploads/2017/05/donation-boxes-logo.png" alt="donation boxes logo"></a></div>
                                      <div class="alignright"><p><?php wp_nav_menu( array( 'container_class' => 'main-nav', 'theme_location' => 'primary' ) ); ?></p></div>
                                    </div>
                                    <div style="clear: both;"></div>

                                    <?php echo do_shortcode('[super_hero_slider slider=25]') ?>
  • 写回答

1条回答 默认 最新

  • donglin9717 2017-05-18 20:32
    关注

    :) Here's the answer...

    The slider most likely is registered as a custom post type. This means that it has it's own loop within Wordpress. So if the plugin hasn't been coded well, when you do the_title() after the slider, it will call the_title() of that particular slide custom post type, and not the page that contains the slider.

    If you don't break out of the loop, it'll just continue calling parts from that slider post type. This is bad coding on their behalf.

    Simply add this after your slider shortcode in header.php:

    <?php wp_reset_postdata(); ?>
    

    That will end the slider loop, and continue with the page loop. :)

    Additionally, if this works for you I'd raise a support ticket with the plugin author and ask them to fix it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答