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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?