Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I’m using Wordpress as a CMS for this site

http://www.seadragon.co.uk/new_site/portfolio.html

...and it’s the first time I’ve ever used wordpress so sorry if I get the terminology wrong....

My client needs to be able to add new projects (case studies) to the portfolio section, and each of them can have it’s own slideshow.

I thought they could create a new post category for each project slideshow, and then a new page for each project.

The problem I have is how to get my client to associate the post category with the project page (so I can pull the correct category posts in to the slideshow dynamically). I thought maybe I could try and get them to use the same naming convention for the category she creates (for the project sildeshow) and the page she creates (for the project)? Does this sound like it’ll work? Is there a better way I can do this, or another plugin that would be better suited.

Here’s the code from my portfolio template... currently the categoryID is hard coded in the query.

<div id="slider">
            <?php
            //Reset Query
            //wp_reset_query();
            global $wp_query;
            $query = "post_type=post&cat=5";
            $wp_query = new WP_Query( $query );

            if ( have_posts() ) : while ( have_posts() ) : the_post(); 

                echo get_the_post_thumbnail($post->ID, 'large');
                ?>

            <?php 
            endwhile; endif;
            ?>
              </div>

            <script type="text/javascript">
            $(window).load(function() {
            $('#slider').nivoSlider();
            });
            </script>

Hope that makes some sense?

Many thanks.

Edit: Fixed formatting so embedded code sample would display

share|improve this question
    
Sorry, code didn't copy: –  Lucy Dec 2 '10 at 18:58
    
<div id="slider"> <?php //Reset Query //wp_reset_query(); global $wp_query; $query = "post_type=post&cat=5"; $wp_query = new WP_Query( $query ); if ( have_posts() ) : while ( have_posts() ) : the_post(); echo get_the_post_thumbnail($post->ID, 'large'); ?> <?php endwhile; endif; //Reset Query //wp_reset_query(); ?> </div> <script type="text/javascript"> $(window).load(function() { $('#slider').nivoSlider(); }); </script> –  Lucy Dec 2 '10 at 18:58
    
Please add the code inside your question not into the comments. –  hakre Dec 2 '10 at 22:55
    
Her code was there she just didn't have the backticks around it. I fixed it for her. –  Chris_O Dec 3 '10 at 8:09
add comment

2 Answers 2

up vote 1 down vote accepted

A better solution would be to create a "Project" post type and a custom taxonomy to separate the different types of projects.

I recently did this on my own website because I wanted a way to keep my projects separate from the rest of my content. I used jQuery cycle instead of Nivo but the concept is the same.

Custom post types have a built in user interface so it wont be confusing for your client to add new projects.

It will also allow you to customize the way the "Projects" are displayed using a single-project.php template file.

I won't go into how to register post types because The Codex explains this very well but I will show you how to get all the attached images to the post and display them in the slider.

<?php   
//The following code is for a sample single-post_type.php
?>
<?php get_header(); ?>
<div id="content">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <h1 class="project-title"><?php the_title(); ?></h1>

        <div class="entry">
            <div id="slider">

                <?php
                // This gets all the images attached to the current post inside the loop
                    $args = array(
                    'post_type' => 'attachment',
                    'posts_per_page' => -1,
                    'post_status' => null,
                    'post_parent' => $post->ID
                    ); 
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {

                echo wp_get_attachment_image($attachment->ID,'medium', false);
                }
                    } ?>

            </div> <!-- /slider -->

        <?php the_content(); ?>

    </div> <!-- /post -->   

    <?php endwhile; else: ?>
    <p><?php _e('Not Found','your_theme_name'); ?></p>

    <?php endif; ?>

</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
share|improve this answer
    
Thanks Chris, I've almost got this working and it's does seem a better solution :-) Should I ask the client to attach the images to the post (which makes them display in the content?) and then exclude them when I get echo the content? (I've found a function to do this). Or is there a better way of attaching images to a post without displaying them in the content? Lucy –  Lucy Dec 9 '10 at 12:38
    
To attach without showing in the content upload and click save changes instead of insert. –  Chris_O Dec 9 '10 at 15:30
    
I just tried clicking save changes instead but then the images don't appear in the slider (they do if I insert them)? –  Lucy Dec 9 '10 at 17:06
    
To verify they are attached go to the gallery tab. If they are listed then they are attached. If the query is working correct then should get 2 copies of each image if they have been added to the content. –  Chris_O Dec 9 '10 at 18:31
add comment

i solved it another way. It's very simple open your wp-nivo-slider.php file

replace the part after Row: 213

<?php 
    $category = get_option('wpns_category');
    $n_slices = get_option('wpns_slices');
?>

with

<?php 
$category = get_option('wpns_category');
$url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
if($url == "website.com/project1") {
     $category = 6;
    }
    if($url == "website.com/project2") {
     $category = 7;
    }
$n_slices = get_option('wpns_slices'); ?>

Make a category for example slider2 and take the id and initialize the $category with this Id. After that choose the Url where you want to use your slider. give it like the example website.com/project1 in the url.

So you can easily add pictures to posts and choose the wished category. ;)

if you have more sliders than 2 i recommend to make a switch case

share|improve this answer
1  
Now you cannot update the plugin anymore. Bad. –  toscho Feb 4 '12 at 22:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.