Support » Plugins » is_single() help

  • Resolved DaBlizz

    (@dablizz)


    The code is below. I can’t seem to get this to work right. If I am logged out, this works fine. However if I am logged in…this doesn’t show up at all.

    <?php
    if (is_single())
    { ?>
    <div class="title bg10">
    							<h2 class="text1">Article Information</h2>
    						</div>
    						<div class="content">
    Something
    		</div> <?php } ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Nobody?

    Not sure what you’re asking. If you’re asking whether is_single checks whether you’re logged in, no, it doesn’t.

    It should work fine. What code is above that.

    If you stay logged out, the block displays fine when on single.php. It does what it is supposed to. Only display on single posts.

    However if I am logged in, the block doesn’t display on single posts, it doesn’t display at all.

    http://dashboardtalk.com

    Go there and visit a single post page. YOu will see “Article Information” on the right hand sidebar at the top. then if you go back to the home page it will be gone. Thats the way it should be, :).

    But if you login in, it won’t show at all.

    Login with the following…

    Username: wordpress
    Password: testing

    Below is that sidebar’s entire file.

    <div id="menu" class="bg3">
    		<ul>
    			<li class="first"><a href="http://www.dashboardtalk.com" id="menu1" accesskey="1" title="Home" class="link1">Home</a></li>
    			<li><a href="#" id="menu2" accesskey="2" title="Tip Us" class="link1">Tip Us</a></li>
    			<li><a href="http://www.dashboardtalk.com/contact-us" id="menu3" accesskey="3" title="Contact Us" class="link1">Contact Us</a></li>
    			<li><a href="#" id="menu4" accesskey="4" title="Advertise" class="link1">Advertise</a></li>
    		</ul>
    	</div>
    	<!-- end #menu -->
    	<div id="page" class="bg4">
    		<div class="bg5">
    			<div class="bg6" style="padding: 0px 0px 50px 0px;">
    				<div id="rightbar">
    					<div id="login">
    <?php
      global $user_ID, $user_identity;
      get_currentuserinfo();
      if (!$user_ID):
    ?>
    <?php
    if (is_single())
    { ?>
    <div class="title bg10">
    							<h2 class="text1">Article Information</h2>
    						</div>
    						<div class="content">
    Something
    		</div> <?php } ?>
    						<div class="title bg10">
    							<h2 class="text1">Community Login</h2>
    						</div>
    						<div class="content">
    							<form name="loginform" id="loginform" action="<?php echo get_settings('siteurl'); ?>/wp-login.php" method="post">
    								<table width="213" border="0" cellspacing="0" cellpadding="0">
    									<tr>
    										<td><label for="inputtext2" class="text1">Username:</label></td>
    										<td align="right"><input id="inputtext2" type="text" name="log" class="input2" /></td>
    									</tr>
    									<tr>
    										<td colspan="2"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/spacer.gif" alt="" width="1" height="9" /></td>
    									</tr>
    									<tr>
    										<td><label for="inputtext3" class="text1">Password:</label></td>
    										<td align="right"><input id="inputtext3" type="password" name="pwd" class="input2" /></td>
    									</tr>
    									<tr>
    										<td colspan="2"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/spacer.gif" alt="" width="1" height="9" /></td>
    									</tr>
    									<tr>
    										<td colspan="2"><input id="inputsubmit2" type="submit" name="inputsubmit2" value="Login" class="submit2" />
    											<p class="text2" style="padding: 1px 0px 0px 0px;"><a href="http://localhost/wordpress/wp-login.php?action=lostpassword">Lost Password</a> &nbsp;|&nbsp; <a href="#">Register</a></p></td>
    									</tr>
    								</table>
    							</form>
    <?php
      else:
    ?>
    						<div class="title bg10">
    							<h2 class="text1">Welcome <?php echo $user_identity; ?>!</h2>
    						</div>
    						<div class="content">
        <ul>
        <?php wp_register(); ?>
        <li><a href="<?php echo get_settings('siteurl') . '/wp-login.php?action=logout&amp;redirect_to=' . $_SERVER['REQUEST_URI']; ?>"><?php _e('Logout'); ?></a></li>
        </ul>
    <?php
      endif;
    ?>
    
    						</div>
    					</div>
    					<!-- end #login -->
    					<div id="articles">
    						<div class="title bg10">
    							<h2 class="text1">Latest Reviews</h2>
    						</div>
    						<div class="content">
    							<table width="213" border="0" cellspacing="0" cellpadding="0" class="table1">
    								<tr>
    									<td class="top" style="height:3px;"></td>
    								</tr>
    
    	<?php $oddcomment = 'class="light" '; ?>
    	<?php $my_query = new WP_Query('showposts=10&cat='.sb_cat1()); ?>
    	<?php if ($my_query->have_posts()) : ?>
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    								<tr>
    									<td <?php echo $oddcomment; ?>><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></td>
    								</tr>
    			<?php $oddcomment = ( $oddcomment=='class="dark" ' ) ? 'class="light" ' : 'class="dark" '; ?>
    		<?php endwhile; ?>
    	<?php endif; ?>
    								<tr>
    									<td class="bottom" style="height:3px;"></td>
    								</tr>
    							</table>
    							<p><a href="?cat=<?php echo sb_cat1() ?>" class="link2">Browse All Reviews</a></p>
    						</div>
    					</div>
    					<!-- end #articles -->
    					<div id="downloads">
    						<div class="title bg10">
    							<h2 class="text1">Latest Dashcasts</h2>
    						</div>
    						<div class="content">
    							<table width="213" border="0" cellspacing="0" cellpadding="0" class="table2">
    								<tr class="top">
    									<td style="height:0px;"></td>
    								</tr>
    
    	<?php $oddcomment = 'class="light" '; ?>
    	<?php $my_query = new WP_Query('showposts=10&cat='.sb_cat2()); ?>
    	<?php if ($my_query->have_posts()) : ?>
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    								<tr <?php echo $oddcomment; ?>>
    									<td><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></td>
    								</tr>
    			<?php $oddcomment = ( $oddcomment=='class="dark" ' ) ? 'class="light" ' : 'class="dark" '; ?>
    		<?php endwhile; ?>
    	<?php endif; ?>
    
    								<tr class="bottom">
    									<td style="height:0px;"></td>
    								</tr>
    							</table>
    							<p><a href="?cat=<?php echo sb_cat2() ?>" class="link2">Browse All Dashcasts</a></p>
    						</div>
    					</div>
    					<!-- end #downloads -->
    
    				</div>
    				<!-- end #rightbar -->

    Post your sidebar.php at http://wordpress.pastebin.ca and reply with the uri.

    if (!$user_ID):

    … in other words, if there’s no userid… in yet other words… if you’re not logged in…

    I got it to work! Thanks. As soon as I put this into that pastebin, I saw it….

    <?php
      global $user_ID, $user_identity;
      get_currentuserinfo();
      if (!$user_ID):
    ?>

    I needed to move that a bit lower, :). It all works now.

    The code says: display stuff up till line 55 ONLY if the user is not logged it, and for logged in users
    line 55# – else >
    display what comes below.
    And it does that.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘is_single() help’ is closed to new replies.