WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wordpress 2.5 gallery with albums (25 posts)

  1. Neil Guevara
    Member
    Posted 6 years ago #

    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.

  2. Kalon
    Member
    Posted 6 years ago #

    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.

  3. Neil Guevara
    Member
    Posted 6 years ago #

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

    Neil

  4. Kalon
    Member
    Posted 6 years ago #

    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.

  5. Neil Guevara
    Member
    Posted 6 years ago #

    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!!!

  6. Kalon
    Member
    Posted 6 years ago #

    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.

  7. Neil Guevara
    Member
    Posted 6 years ago #

    http://php.pastebin.com/f5ee4c0ef

    anything you can do is really sppreciated

  8. Kalon
    Member
    Posted 6 years ago #

    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>
  9. Neil Guevara
    Member
    Posted 6 years ago #

    nothing happened :(

  10. Kalon
    Member
    Posted 6 years ago #

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

    (around line 17)

  11. Neil Guevara
    Member
    Posted 6 years ago #

    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!!!

  12. Neil Guevara
    Member
    Posted 6 years ago #

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

  13. Neil Guevara
    Member
    Posted 6 years ago #

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

  14. Kalon
    Member
    Posted 6 years ago #

    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.

  15. Neil Guevara
    Member
    Posted 6 years ago #

    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

  16. Kalon
    Member
    Posted 6 years ago #

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

  17. Neil Guevara
    Member
    Posted 6 years ago #

    i removed the hack to see if it was interfering but it wasnt...so no idea

  18. Kalon
    Member
    Posted 6 years ago #

    Try this:

    <div style="display: block;"><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: 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>
    
    				</div>
  19. Neil Guevara
    Member
    Posted 6 years ago #

    I actually like it the way it is, so kool we are done thanx soooooooooooooooooooo much for your help, your going to be a 1st class wordpress user.

  20. Kalon
    Member
    Posted 6 years ago #

    no prob.

  21. Neil Guevara
    Member
    Posted 6 years ago #

    it would be great if one piece of code could be created that worked with every theme and inabled the same functions. I know this guy came up with a piece of easy to install code for creating asides so if thats possible then so is this. There are a number of people who are trying to create the same thing and achieve what this gallery code does.

  22. paraksaber
    Member
    Posted 6 years ago #

    very much code, visit http://wordpress.org/support/topic/165921?replies=3 and use a category-#ID.php file to make a Loop

  23. shaneholden
    Member
    Posted 6 years ago #

    Quick question with this setup, how would the post be displayed if you created a post and included it into 2 categories, one for the gallery and an additional one?

    Thanks

  24. shaneholden
    Member
    Posted 6 years ago #

    Ok, nevermind my previous question. I've got the coded added in and it's working great except the posts are pulling the same image. So I've got 2 different posts with different images, but they both are pulling the first image out of the newer post. Any ideas?

    Here's my code:

    <div class="post">
    <?php
    				if(in_category(4)) {
    				$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 style="clear: both;"></div>
    				<div class="post">
    
    				<div style="float: right; width: 185px; clear: right; margin-top: 0px; margin-bottom: 0px; padding-top: 0px;  margin-left: 0px;">
    					<h2>Album:<br /><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_time('F jS, Y') ?></a></h2>
    <br />
    <div>This album contains <?php echo $picCount; ?> photos.</div>
    
                                         </div>
    
    					<div style="float: left;"><a href="<?php the_permalink(); ?>"><?php echo $thePic; ?></a></div>
    					<?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    
    <div class="post"><p class="divide">
    		<?php if ('open' == $post-> comment_status) : // kommentare erlaubt, dann ?>
    
    		<?php else : // wenn kommentare deaktiviert, dann ?>
    		<?php endif; ?>
    Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    	</p></div>
    			</div>
    <?php } else { ?>
    
    	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2><?php the_time('F jS, Y') ?>
    	<?php the_content(__("Read the rest of this entry &raquo;")); ?>
    	<p class="divide">
    		<?php if ('open' == $post-> comment_status) : // kommentare erlaubt, dann ?>
    
    		<?php else : // wenn kommentare deaktiviert, dann ?>
    		<?php endif; ?>
    Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    	</p>
    
    <?php } ?>
    
    	</div>
    	<?php endwhile; ?>
    	<?php else : ?>
    
    	<div class="post">
    <img src="<?php bloginfo('template_directory'); ?>/images/404error.gif">
    <h2 align="center">Sorry, but this page does not exist.</h2>
    	</div>
    
    	<?php endif; ?>
    	<div class="post" align="center">
    <?php posts_nav_link('&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;','&laquo; Latest Entries','Previous Entries &raquo;'); ?>
             </div>
  25. Anonymous
    Unregistered
    Posted 6 years ago #

    The code Kalon gave on comment#2 worked very well till I upgraded to WP 2.6.
    Now $picCount always shows 3 even if there are more pics...
    Any idea ?

Topic Closed

This topic has been closed to new replies.

About this Topic