• Resolved Kettercat

    (@kettercat)


    Hey guys,

    I’m getting a bit lost with this header code that displays the title of the page.
    I want to use the page title on each page as shown here:
    http://kettercat.com/raz/en/about-us/

    BUT, on pages using the archive-listing.php template, I want to show the subtitle instead of the main title (currently showing “Archives”):
    http://kettercat.com/raz/en/status/for-sale/

    Here’s the relevant header code:

    <?php if ( is_home() ) : ?>
       						   	<h2 class="header-post-title-class"><?php echo spacious_header_title(); ?></h2>
                            <?php else : ?>
                            <?php if ( is_page(archive-listing.php) ) : ?>
    					<?php
    					$object = get_queried_object();
    
    					if ( !isset($object->label) ) {
    						$title = '<h1 class="archive-title">' . $object->name . '</h1>';
    					} else {
    						$title = '<h1 class="archive-title">' . get_bloginfo('name') . ' Assets</h1>';
    					}
    
    					echo $title; ?>
                            <?php else : ?>
                               <h1 class="header-post-title-class"><?php echo spacious_header_title(); ?></h1>
                            <?php endif; ?>
                            <?php endif; ?>

    Here is the archive-listing.php code:

    <?php
    /**
     * The template for displaying Listing Archive pages
     *
     * @link http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WP Listings
     * @since 0.1.0
     */
    
    function archive_listing_loop() {
    
    		global $post;
    
    		$count = 0; // start counter at 0
    
    		// Start the Loop.
    		while ( have_posts() ) : the_post();
    
    			$count++; // add 1 to counter on each loop
    			$first = ($count == 1) ? 'first' : ''; // if counter is 1 add class of first
    
    			$loop = sprintf( '<div class="listing-widget-thumb"><a href="%s" class="listing-image-link">%s</a>', get_permalink(), get_the_post_thumbnail( $post->ID, 'listings' ) );
    
    			if ( '' != wp_listings_get_status() ) {
    				$loop .= sprintf( '<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status() );
    			}
    
    			$loop .= sprintf( '<div class="listing-thumb-meta">' );
    
    			if ( '' != get_post_meta( $post->ID, '_listing_text', true ) ) {
    				$loop .= sprintf( '<span class="listing-text">%s</span>', get_post_meta( $post->ID, '_listing_text', true ) );
    			} elseif ( '' != wp_listings_get_property_types() ) {
    				$loop .= sprintf( '<span class="listing-property-type">%s</span>', wp_listings_get_property_types() );
    			}
    
    			if ( '' != get_post_meta( $post->ID, '_listing_price', true ) ) {
    				$loop .= sprintf( '<span class="listing-price">%s</span>', get_post_meta( $post->ID, '_listing_price', true ) );
    			}
    
    			$loop .= sprintf( '</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->' );
    
    			if ( '' != get_post_meta( $post->ID, '_listing_open_house', true ) ) {
    				$loop .= sprintf( '<span class="listing-open-house">בית פתוח: %s</span>', get_post_meta( $post->ID, '_listing_open_house', true ) );
    			}
    
    			$loop .= sprintf( '<div class="listing-widget-details"><h3 class="listing-title"><a href="%s">%s</a></h3>', get_permalink(), get_the_title() );
    			$loop .= sprintf( '<p class="listing-address"><span class="listing-address">%s</span><br />', wp_listings_get_address() );
    			$loop .= sprintf( '<span class="listing-city-state-zip">%s, %s %s</span></p>', wp_listings_get_city(), wp_listings_get_state(), get_post_meta( $post->ID, '_listing_zip', true ) );
    
    			if ( '' != get_post_meta( $post->ID, '_listing_bedrooms', true ) || '' != get_post_meta( $post->ID, '_listing_bathrooms', true ) || '' != get_post_meta( $post->ID, '_listing_sqft', true )) {
    				$loop .= sprintf( '<ul class="listing-beds-baths-sqft"><li class="beds">%s<span>חדרי שינה</span></li> <li class="baths">%s<span>חדרי רחצה</span></li> <li class="sqft">%s<span>מ"ר</span></li></ul>', get_post_meta( $post->ID, '_listing_bedrooms', true ), get_post_meta( $post->ID, '_listing_bathrooms', true ), get_post_meta( $post->ID, '_listing_sqft', true ) );
    			}
    
    			$loop .= sprintf('</div><!-- .listing-widget-details -->');
    
    			$loop .= sprintf( '<a href="%s" class="button btn-primary more-link">%s</a>', get_permalink(), __( 'הצג נכס', 'wp_listings' ) );
    
    			/** wrap in div with column class, and output **/
    			printf( '<article id="post-%s" class="listing entry one-third %s"><div class="listing-wrap">%s</div><!-- .listing-wrap --></article><!-- article#post-## -->', get_the_id(), $first, apply_filters( 'wp_listings_featured_listings_widget_loop', $loop ) );
    
    			if ( 3 == $count ) { // if counter is 3, reset to 0
    				$count = 0;
    			}
    
    		endwhile;
    		if (function_exists('equity')) {
    			equity_posts_nav();
    		} elseif (function_exists('genesis_init')) {
    			genesis_posts_nav();
    		} else {
    			wp_listings_paging_nav();
    		}
    
    }
    
    if (function_exists('equity')) {
    
    	add_filter( 'equity_pre_get_option_site_layout', '__equity_return_full_width_content' );
    	remove_action( 'equity_entry_header', 'equity_post_info', 12 );
    	remove_action( 'equity_entry_footer', 'equity_post_meta' );
    
    	remove_action( 'equity_loop', 'equity_do_loop' );
    	add_action( 'equity_loop', 'archive_listing_loop' );
    
    	equity();
    
    } elseif (function_exists('genesis_init')) {
    
    	add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
    	remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
    	remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    	remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    	remove_action( 'genesis_after_entry', 'genesis_do_author_box_single' );
    
    	remove_action( 'genesis_loop', 'genesis_do_loop' );
    	add_action( 'genesis_loop', 'archive_listing_loop' );
    
    	genesis();
    
    } else {
    
    get_header(); ?>
    
    	<section id="primary" class="content-area container inner">
    		<div id="content" class="site-content" role="main">
    
    			<?php if ( have_posts() ) : ?>
    
    				<header class="archive-header">
    					<?php
    					$object = get_queried_object();
    
    					if ( !isset($object->label) ) {
    						$title = '<h1 class="archive-title">' . $object->name . '</h1>';
    					} else {
    						$title = '<h1 class="archive-title">' . get_bloginfo('name') . ' נכסים</h1>';
    					}
    
    					echo $title; ?>
    
                        <small><?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?></small>
    				</header><!-- .archive-header -->
    
    			<?php
    
    			archive_listing_loop();
    
    			else :
    				// If no content, include the "No posts found" template.
    				get_template_part( 'content', 'none' );
    
    			endif;
    
    			?>
    
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php
    get_sidebar( 'content' );
    get_sidebar();
    get_footer();
    
    }

    What am I doing wrong? 🙁

    Thanks ♥

Viewing 11 replies - 1 through 11 (of 11 total)
  • First, did you even test your code? The first code block ( header ) would’ve thrown an error is_page(archive-listing.php) would’ve needed to be quoted.

    Now onto the issue, that is the wrong conditional to use. is_page() checks if you’re on a specific page, not a specific page template. SO, let’s say you have an /about-us/ page, to see if you were on that you’d do is_page('about-us')

    You may want to use the is_page_template() [Codex Link] instead, if in-fact you have that archive page as an actual page in your admin.

    If, however, you’re using the template hierarchy to your advantage ( as is evident by the template name ), you’ll be able to use the is_tax() [Codex Link] conditional instead. So something like this: is_tax( 'listing' )

    Thread Starter Kettercat

    (@kettercat)

    Hey Jerry, thanks for your help! I’m a PHP newbie so I’m only starting to get my head round these things…

    I’m afraid I still can’t see any chance – here’s my header.php code now:

    <?php if ( is_home() ) : ?>
       						   	<h2 class="header-post-title-class"><?php echo spacious_header_title(); ?></h2>
                            <?php else : ?>
                            <?php if ( is_tax('listing') ) : ?>
    					<?php
    					$object = get_queried_object();
    
    					if ( !isset($object->label) ) {
    						$title = '<h1 class="archive-title">' . $object->name . '</h1>';
    					} else {
    						$title = '<h1 class="archive-title">' . get_bloginfo('name') . ' Assets</h1>';
    					}
    
    					echo $title; ?>
                            <?php else : ?>
                               <h1 class="header-post-title-class"><?php echo spacious_header_title(); ?></h1>
                            <?php endif; ?>
                            <?php endif; ?>

    Thanks!

    Thread Starter Kettercat

    (@kettercat)

    Bump 🙁

    Good day!

    Wouldn’t your code be going something like;

    <?php if ( is_home() ) { ?>
               <h2 class="header-post-title-class"><?php echo spacious_header_title(); ?></h2>
    <?php } else { ?>
              <?php if (is_tax('listing')) { ?>
                        <?php $object = get_queried_object(); if ( !isset($object->label) ) {
                        $title = '<h1 class="archive-title">' . $object->name . '</h1>';
                        } else {
                        $title = '<h1 class="archive-title">' . get_bloginfo('name') . ' Assets</h1>';
                        };
                        echo $title;
                        ?>
              <?php } else { ?>
              <h1 class="header-post-title-class"><?php echo spacious_header_title(); ?></h1>
              <?php } ?>
    <?php } ?>

    Something like that, sorry not tested this yet. 🙂

    Thread Starter Kettercat

    (@kettercat)

    Hi CureWP! Thanks for the quick response – sadly it’s still showing up like this:
    http://kettercat.com/raz/en/status/for-sale/

    Any idea?
    Thanks anyway!

    I think we are naming ‘listing’ here;

    <?php if (is_tax('listing')) { ?>

    but maybe we are missing ‘archive-listing’ out of it, so maybe

    <?php if (is_tax('archive-listing')) { ?>

    would work? Sorry don’t have this structure in front of me to play with it and debug.

    Thread Starter Kettercat

    (@kettercat)

    Ooooh thanks, still no luck though 🙁 anything else I can show you to help?

    Sorry, we’re all over the place here. What about;

    <?php if (is_tax('for-sale')) { ?>

    using the slug, wish I could see the structure and play with your template you’ve got. Doing my best, sorry for the run arounds.

    Thread Starter Kettercat

    (@kettercat)

    Woooooooooooooohooooooooooooooooo!
    It was actually:

    <?php if (is_tax('status')) { ?>

    that did the trick, but it’s thanks to you that I finally realised the reasoning behind it.
    Thanks A LOT!!!! 😀

    Here: http://kettercat.com/raz/en/status/for-sale/

    Hi,

    Perfect, happy to hear its all sorted out. Yes, I started to think that rather then looking for your php file, we could look for the lug which the end was /for-sale/ but the parent is /status/ … it would of been my next suggestion. 🙂

    Ahh perfect day that worked out.

    You are welcome and happy new year 🙂

    Thread Starter Kettercat

    (@kettercat)

    Perfect indeed. Thank you so much, it’s been nagging me for a week now.
    Happy New Year! ♥

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Header title problem’ is closed to new replies.