• Hi there, I am trying to hard code some dynamic content in my sidebar.php page, and it doesn’t seem to be working correctly. Please see below for my code to see if I am formatting something incorrectly?

    When I just have the one php statement for page 89 it works, once i add a second in it breaks it.

    (page 89 is my about page, and page 105 pulling posts in the ‘Calendar’ category)

    <?php if( is_page('89') ):?>
    	<h4 class="widgettitle">Donate to Angora Gardens</h4>
    	<a href="donate" style="margin-bottom:10px; color:#676767">Click Here >></a>
    <?php endif;?>
    
    <?php if( is_page('105') ):?>
    	<h4 class="widgettitle">Contact Us</h4>
    	<a href="contact" style="margin-bottom:10px; color:#676767">Click Here >></a>
    <?php endif;?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Exactly what do you mean by “breaks it”? Does it just not show up, or does it show fatal errors, warnings, or something else?

    Without knowing anything more… from your small description there I am going to guess that “105” is a category archive listing? Is this a page with a shortcode on it or is it an actual archive page?

    Thread Starter noslenwerd

    (@noslenwerd)

    Sorry.. the page with is 89 still shows the sidebar correctly as its coded above, but when i add the code for page 105, the sidebar content for page 105 does not show at all (89 still shows).

    They are both actual pages. 105 is querying a category of posts via a panel in my interface (It is a theme from themify.me, and they give you an option to query certain categories within the page)

    link to is_page89
    https://angoragardens.org/angoragardens/about/

    and is_page105
    https://angoragardens.org/angoragardens/classes/schedule/

    And here is my entire sidebar.php page

    <aside id="sidebar">
    	<div style="height:120px">?</div>
    	<input type="text" onblur="if (this.value == '') {this.value = 'Search...';}" onfocus="if (this.value == 'Search...') {this.value = '';}" id="s" name="s" value="Search...">
    	<div style="height:5px">?</div>
    
    	<?php if( is_page('89') ):?>
    		<h4 class="widgettitle">Donate to Angora Gardens</h4>
    		<a href="donate" style="margin-bottom:10px; color:#676767">Click Here >></a>
    		<h4 class="widgettitle">Hold Your Business or Social Event at Angora Gardens</h4>
    		<a href="event-venue" style="margin-bottom:10px; color:#676767">View Event Venue Page >></a>
    		<h4 class="widgettitle">View Upcoming Classes</h4>
    		<a href="#" style="margin-bottom:10px; color:#676767">Click Here >></a>
    		<h4 class="widgettitle">Take a Virtual Tour</h4>
    		<a href="#" style="margin-bottom:10px; color:#676767">Click Here >></a>
    		<h4 class="widgettitle">Learn More About Mon Yough Community Services</h4>
    		<a href="https://mycs.org" target="_blank" style="margin-bottom:10px; color:#676767">Click Here >></a>
    	<?php endif;?>
    
    	<?php if( is_page('105') ):?>
    		<h4 class="widgettitle">Have An Idea for a Class? Let us Know</h4>
    		<a href="contact" style="margin-bottom:10px; color:#676767">Click Here >></a>
    		<h4 class="widgettitle">Contact us to Hold a Private Class</h4>
    		<a href="contact" style="margin-bottom:10px; color:#676767">Click Here >></a>
    		<h4 class="widgettitle">Become an Instructor</h4>
    		<a href="contact" style="margin-bottom:10px; color:#676767">Click Here >></a>
    	<?php endif;?>
    
    	<div style="font-size:1.6em; font-color:#222; text-align:center;  line-height:25px; background-color:#ececec; padding:12px; margin-top:25px; width:100%">Angora Gardens is open to the public Tues-Sat 9am to 5pm</div>
    
    </aside>

    I’d try adding in some (temporary) debugging code like:

    <p>This page ID is '<?php echo $post->ID; ?>' and this is a '<?php echo get_post_type ($post->ID); ?>'</p>

    This will tell you the page ID and the post-type, which should be “page”.

    Seeing as how this is done through a theme’s back end it’s possible that it’s not being seen as a “page” type, so it’s worth checking.

    check, if that page 105 is using a page template with custom query, that the query loop is terminated properly with wp_reset_postdata() or wp_reset_query()

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘php if else is_page… need some help’ is closed to new replies.