Call a 2nd slideshow based upon page id

Hi,

I’m new to PHP and would like some help on which is probably has a very easy solution!

I have added part of the header.php file of a Wordpress site below which I have been asked to edit. Towards the bottom of the code it calls a slideshow (Royal Slider) if the id of the parent page matches that in the code (page id 664). My question is, how can I call another slide show for a page with a different id (id 6096) leaving the current slideshow in place for page id 664?

Many thanks for your help!


<?php if (in_category(array('careers', 'case-studies'))) { ?>
      <?php } elseif (in_category('courses'))  { ?>
          <img src="http://inside-industry.org.uk/wp-content/uploads/courses.jpg" alt="slider image"/>

      <?php } elseif (in_category('experts'))  { ?>
          <img src="http://inside-industry.org.uk/wp-content/uploads/experts.jpg" alt="slider image"/>

      <?php } elseif (in_category('resources'))  { ?>
          <img src="http://inside-industry.org.uk/wp-content/uploads/resources.jpg" alt="slider image"/>

      <?php } elseif (in_category('news-and-events'))  { ?>
          <img src="http://inside-industry.org.uk/wp-content/uploads/news.jpg" alt="slider image"/>

      <?php } elseif (in_category('companies'))  { ?>
          <img src="http://inside-industry.org.uk/wp-content/uploads/companies.jpg" alt="slider image"/>

      <?php } elseif ('664' == $post->post_parent)  { ?>
          <?php 
            //664 is the id of the subsea page, any pages that have this as their parent should have the slider
            echo get_new_royalslider(1);
          ?>  
		  
	<?php } else { ?>
          <?php echo get_the_post_thumbnail( $post->ID, 'banner' ); ?>
      <?php }?>
	  
	   
	        </div>

I personally don’t like all the <?php ?> included.
[php]<?php
if (in_category(array(‘careers’, ‘case-studies’))) {
echo ‘

’;
} elseif (in_category(‘courses’)) {
echo ‘’;
} elseif (in_category(‘experts’)) {
echo ‘’;
} elseif (in_category(‘resources’)) {
echo ‘’;
} elseif (in_category(‘news-and-events’)) {
echo ‘’;
} elseif (in_category(‘companies’)) {
echo ‘’;
} else {
//664 is the id of the subsea page, any pages that have this as their parent should have the slider
echo get_new_royalslider(1,$post->post_parent);
} else {
echo get_the_post_thumbnail( $post->ID, ‘banner’ );
}
?>[/php]

But why not
[php] } else {
//664 is the id of the subsea page, any pages that have this as their parent should have the slider
echo get_new_royalslider(1,$post->post_parent);
} else {
echo get_the_post_thumbnail( $post->ID, ‘banner’ );
}[/php]

Send the post_parent to get_new_royalslider. Process all your sliders inside the function.

Depending on how the function get_new_royalslider works you will change it to how you want.
If 664 display this, if 6096 display that etc.

Thanks for your reply.

This is code that i’ve inherited in a website i’m editing.

I’m a complete newbie to PHP so the resolution you gave to solve the problem does not mean anything to me!

I just want to add another section to the code to call another slide show for a page with a different id (id 6096) leaving the current slideshow in place for page id 664.

Can I add a similar call to the end of the code? If so, would you please be able to tell me what this would be?

Thanks for your help.

So are you wanting a different slider based on the id? or just the same standard slider but for a specific id set?

For the same slider you could just
[php]<?php
$post_parent = $post->post_parent;

if (in_category(array('careers', 'case-studies'))) {
      echo '<img src="http://inside-industry.org.uk/wp-content/uploads/careers.jpg" alt="slider image"/>';
} elseif (in_category('courses'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/courses.jpg" alt="slider image"/>';
} elseif (in_category('experts'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/experts.jpg" alt="slider image"/>';
} elseif (in_category('resources'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/resources.jpg" alt="slider image"/>';
} elseif (in_category('news-and-events'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/news.jpg" alt="slider image"/>';
} elseif (in_category('companies'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/companies.jpg" alt="slider image"/>';
} elseif ($post_parent == 664 || $post_parent == 6096)  {

//664 is the id of the subsea page, any pages that have this as their parent should have the slider
echo get_new_royalslider(1);
} else {
echo get_the_post_thumbnail( $post->ID, ‘banner’ );
}
?>[/php]

Depending on how many id’s you are wanting to check you could also use an array.

It would be a different slider based on a different page id. The slider id is 2 and the page id is 6096.

Thanks!

Well if thats the case my first suggestion is best.

Then within get_new_royalslider(1,$post->post_parent); change the function.
If you post the get_new_royalslider(); function I will change it so it works for you

Ok, thanks.

This is the code in the royalslider.php file:

[php]<?php
/*
Plugin Name: RoyalSlider
Plugin URI: http://dimsemenov.com/plugins/royal-slider-wp/
Description: Premium jQuery slider plugin.
Author: Dmitry Semenov
Version: 2.1
Author URI: http://dimsemenov.com
*/

if (!class_exists(“RoyalSliderAdmin”)) {

require_once dirname( __FILE__ ) . '/RoyalSliderAdmin.php';	
$royalSlider =& new RoyalSliderAdmin(__FILE__);		

function get_royalslider($id) {
	global $royalSlider;		
	return $royalSlider->get_slider($id);
}

}
?>[/php]

Ok, what you need to do is use the included royalslider admin, see http://dimsemenov.com/plugins/royal-slider/wordpress/ and its the first youtube video.

After you have created a slider, get its id number.

get_new_royalslider(1) where 1 is the id of the slider you create.

[php]<?php
// $slider_array = array(post_parent => slider_id); Used like this
$slider_array = array(2 => 1, 6096 => 2);
$post_parent = $post->post_parent;

if (in_category(array('careers', 'case-studies'))) {
      echo '<img src="http://inside-industry.org.uk/wp-content/uploads/careers.jpg" alt="slider image"/>';
} elseif (in_category('courses'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/courses.jpg" alt="slider image"/>';
} elseif (in_category('experts'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/experts.jpg" alt="slider image"/>';
} elseif (in_category('resources'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/resources.jpg" alt="slider image"/>';
} elseif (in_category('news-and-events'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/news.jpg" alt="slider image"/>';
} elseif (in_category('companies'))  {
	echo '<img src="http://inside-industry.org.uk/wp-content/uploads/companies.jpg" alt="slider image"/>';
} elseif (array_key_exists($post_parent, $slider_array))	{ 
	echo get_new_royalslider($slider_array[$post_parent]);           
} else {
echo get_the_post_thumbnail( $post->ID, 'banner' );
}

?>[/php]

The array is built to match the post_parent to the slider id.
$post_parent is then set so the post->post_parent; is called 1 less time than it needs to be.
Checks to see if the post_parent key exists in the array, if it does, it runs the slider function

Sponsor our Newsletter | Privacy Policy | Terms of Service