• Resolved neil-guevara

    (@neil-guevara)


    Hey guys, wondering if i can get some help. Im trying to add galleries to my wordpress blog using the category function. That is when you add the relevant CSS/PHP to the loop in your index file you can insert all galleries under the category “gallery” that you create. An example of this can be seen on matt’s page.

    Heres what matt said about it :

    I put the intro text, and then the more page split, and the gallery shortcode after that. Here’s the snippet of my index template that does asides and the gallery posts:

    http://php.pastebin.com/m5d433a57

    Obviously the category IDs need to match whatever you’re using. It’s the same technique I wrote about a few years ago for asides:

    http://ma.tt/2004/05/asides/

    I hope that helps! I’ll write more on my blog about this at some point.

    The problem is i cant get the code to work on my index.php file and im wondering if there is some wicked php’er out there that could help me.

    Matt sent me the snippet of the code from his index file so im hoping that someone knows how to add it to my index file to get it to work.

    Thanx everyone for taking the time.

Viewing 15 replies - 1 through 15 (of 24 total)
  • kalon

    (@kalon)

    If I understand correctly, you want do display posts you made in the gallery category differently to those posted in the other categories? Like where Matt displays an image from the gallery post on the index page & how many pictures it contains (also when viewing his gallery category)?

    Below gives you a general idea on how I do it. It has been adapted form posts I have seen on this forum.
    Note that category 12 is the id of my gallery category 🙂

    (loop has started)

    <?php
    if(in_category(12)) {
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => 1,
    	'order' => 'ASC',
    	'post_status' => null,
    	'post_parent' => $post->ID
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    		$thePic = wp_get_attachment_image($attachment->ID);
    	}
    }
    
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => null,
    	'post_status' => null,
    	'post_parent' => $post->ID
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	$picCount = count($attachments);
    }
    ?>
    
    <?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
    <?php the_category() ?><?php the_tags(); ?>
    
    <div class="entry">
    <?php echo $thePic; ?>
    <?php the_content('View &raquo;');  ?>This album consists of  <?php echo $picCount; ?> pictures.
    </div>
    
    <?php } else { ?>
    
    Here you would put what is displayed if the post's category isn't that of the gallery.
    
    <?php } ?>

    You then do the same in your archive.php (the category) page.

    Where I say “Here you would put what is displayed if the post’s category isn’t that of the gallery.” I mean what is currently used in your template to display posts.

    Thread Starter neil-guevara

    (@neil-guevara)

    Thank you mate, but im having problems finding the exact place where i put it into the loop…any ideas?

    Neil

    kalon

    (@kalon)

    The code I posted above starts directly after the following:

    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">

    Note that <div id=”content” class=”narrowcolumn”> is just part of the layout for my template.

    Directly after the code posted in my previous post:

    `</div>

      <li class=”comments”><?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?>

    <?php endwhile; ?>

    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(‘« Older Entries’) ?></div>
    <div class=”alignright”><?php previous_posts_link(‘Newer Entries »’) ?></div>
    </div>

    <?php else : ?>

    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>

    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    The </div>` before the get sidebar bit closes my <div id=”content” class=”narrowcolumn”> bit.

    Obviously your theme will be a bit different to mine but it gives you the general idea.

    There isn’t an exact place it needs to go into the loop… just in it.
    The loop (what I understand of it; I’ve only been using WordPress for a week or so) is basically a post. Anything within the loop becomes part of each post. My code above is actually processed in each post (its in the loop), but depending if the post is under my gallery category determines what is actually be displayed.

    If the loop returns FALSE, it means that there aren’t any posts to be displayed, and none of the code within the loop is displayed. Only the ‘<h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>’ bit will be shown.

    Thread Starter neil-guevara

    (@neil-guevara)

    Thank you man for all your help but sadly that f**ked everything up in my index file, it basically posted the post two times with a picture that was not “clickable”. This gallery feature seems to one thing that will always evade me, ive been trying for weeks now. Like i said that you mate!!!

    kalon

    (@kalon)

    Can you post your whole index file from before you messed with it? (If not, the f**ked version is good) Then I will make it gelleryable.

    Thread Starter neil-guevara

    (@neil-guevara)

    http://php.pastebin.com/f5ee4c0ef

    anything you can do is really sppreciated

    kalon

    (@kalon)

    I don’t know how the website you linked to works, so I’m going to put my version of your page here. Obviously you will want to edit it & style it so it looks nice… I have put comments around things that you will want to edit/do stuff with.

    <?php get_header(); ?>
    	<div id="wrapper">
    
    		<div id="content-wrapper">
    
    			<div id="content">
    
    				<?php if (have_posts()) : ?>
    
    			<?php while (have_posts()) : the_post(); ?>
    
    				<div class="post-wrapper">
    
    				<!--  If you want to copy and paste this into your archive.php page (when viewing categories, START COPY FROM HERE  -->
    
    				<?php
    				if(in_category(12)) {
    				$args = array(
    					'post_type' => 'attachment',
    					'numberposts' => 1,
    					'order' => 'ASC',
    					'post_status' => null,
    					'post_parent' => $post->ID
    					);
    				$attachments = get_posts($args);
    				if ($attachments) {
    					foreach ($attachments as $attachment) {
    						$thePic = wp_get_attachment_image($attachment->ID);
    					}
    				}
    
    				$args = array(
    					'post_type' => 'attachment',
    					'numberposts' => null,
    					'post_status' => null,
    					'post_parent' => $post->ID
    					);
    				$attachments = get_posts($args);
    				if ($attachments) {
    					$picCount = count($attachments);
    				}
    				?>
    
    				<!-- $$$$$$$$$$$$$$$$$$ This is the gallery post bit $$$$$$$$$$$$$$$$$$$$$$$$$$$ -->
    
    				<div class="date">
    					<span class="month"><?php the_time('M') ?></span>
    					<span class="day"><?php the_time('j') ?></span>
    				</div>
    
    				<div style="float: right; width: 592px; clear: right; margin-top: 10px; margin-bottom: 15px; padding-top: 10px;  margin-left: 5px;">
    					<span class="titles"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></span>
    					<div><img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon1.gif" alt="icon1" /> <?php the_author() ?> | <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon2.gif" alt="icon2" /> <?php the_category(', ') ?> | <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon4.gif" alt="icon4" /> <?php the_time('m jS, Y') ?><strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon3.gif" alt="icon3" /><?php comments_popup_link('No Comments &raquo;', '1 Comment &raquo;', '% Comments &raquo;'); ?></div>
    				</div>
    				<div style="clear: both;"></div>
    
    				<div class="post">
    
    					<div style="float: right;"><a href="<?php the_permalink(); ?>"><?php echo $thePic; ?></a></div>
    					<?php the_content('Read the rest of this entry &raquo;'); ?> <br />
    					<small>This album consists of  <?php echo $picCount; ?> pictures.</small>
    
    				</div>
    
    				<!-- $$$$$$$$$$$$$$$$$$ This is the end of the gallery post bit $$$$$$$$$$$$$$$$$$$$$$$$$$$ -->
    
    				<?php } else { ?>
    
    				<!-- %%%%%%%%%%% This is the normal post bit %%%%%%%%%%%%%% -->				
    
    				<div class="date">
    					<span class="month"><?php the_time('M') ?></span>
    					<span class="day"><?php the_time('j') ?></span>
    				</div>
    
    				<div style="float: right; width: 592px; clear: right; margin-top: 10px; margin-bottom: 15px; padding-top: 10px;  margin-left: 5px;">
    					<span class="titles"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></span>
    					<div><img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon1.gif" alt="icon1" /> <?php the_author() ?> | <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon2.gif" alt="icon2" /> <?php the_category(', ') ?> | <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon4.gif" alt="icon4" /> <?php the_time('m jS, Y') ?><strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon3.gif" alt="icon3" /><?php comments_popup_link('No Comments &raquo;', '1 Comment &raquo;', '% Comments &raquo;'); ?></div>
    				</div>
    
    				<div style="clear: both;"></div>
    
    				<div class="post">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				<!--%%%%%%%%%%%%%%%%%%%%% This is the end of the normal post bit %%%%%%%%%%%%%%%%%%%%%% -->
    
    				<?php } ?>
    
    				<!-- STOP COPYING HERE...  -->
    
    			</div>
    
    			<?php comments_template(); ?>
    
    			<?php endwhile; ?>
    
    			   <p class="pagination"><?php next_posts_link('&laquo; Previous Entries') ?> <?php previous_posts_link('Next Entries &raquo;') ?></p>
    
    			<?php else : ?>
    
    			<h2 align="center">Not Found</h2>
    
    			<p align="center">Sorry, but you are looking for something that isn't here.</p>
    
    			<?php endif; ?>
    
    			</div>
    
    		</div>
    		<?php get_sidebar(); ?>
    		<?php get_footer(); ?>   
    
    </body>
    </html>
    Thread Starter neil-guevara

    (@neil-guevara)

    nothing happened 🙁

    kalon

    (@kalon)

    Did you change my id of 12 in if(in_category(12)) to the id of your gallery category? 🙂

    (around line 17)

    Thread Starter neil-guevara

    (@neil-guevara)

    Dude!!!!!!!! you nearly have it perfect!!! Sweet…

    The one prob is that the pics show up on the wrong side, that is they show up on the right side..

    take a look : http://img27.picoodle.com/img/img27/4/4/19/f_screenshotgm_63a94a2.jpg

    is there anything little change can be done to switch it over the other way?

    Thank you soo much man!!!

    Thread Starter neil-guevara

    (@neil-guevara)

    plus the titles got a little messed up if you can see it, they dont line up with the date badges.

    Thread Starter neil-guevara

    (@neil-guevara)

    actually they are only messed up in Firefox, IE is showing the titles well, damm i use mozilla

    kalon

    (@kalon)

    Try:

    <div style="display: block;">
    <div style="float: left;"><a href="<?php the_permalink(); ?>"><?php echo $thePic; ?></a></div>
    <div style="width: 510px; float: right;"><?php the_content('Read the rest of this entry &raquo;'); ?><br /><small>This album consists of  <?php echo $picCount; ?> pictures.</small>
    </div>
    </div>

    Instead of:

    <div style="float: right;"><a href="<?php the_permalink(); ?>"><?php echo $thePic; ?></a></div>
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <small>This album consists of  <?php echo $picCount; ?> pictures.</small>

    in the gallery post bit.

    I cant see anything wrong with the gallery post titles (they look the same as the other titles) when I visited your site using Firefox.

    Thread Starter neil-guevara

    (@neil-guevara)

    yo because i fixed them, sort of a dirty hack!

    i added that new code you gave me and it really messed up the blog, the pics did though go on the other side just messed stuff up : http://img34.picoodle.com/img/img34/4/4/19/f_screenshotm_4414a89.jpg

    getting super close to having it perfect.

    dude im flipping out with excitement

    kalon

    (@kalon)

    by messed up, do you mean the date bit gone wrong? If so… what is your dirty hack?

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘wordpress 2.5 gallery with albums’ is closed to new replies.