简体   繁体   中英

Wordpress issue with get_title - displaying title of carousel slide?

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 (ie "About Us" it's actually displaying the title of the first slide from the carousel on the page (ie "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]') ?>

:) 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM