Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Arash Emadi
10,002 PointsHow can I add my slideshow to the page.php template on my website?
I've been working with the "GAZETI" template for WordPress on a new website I'm working on. My client has asked me for the following:
He wants the slider which appears on the homepage, on three different pages, each showing posts related to the category of that page. So, for example, If he's on home, he'll show the latest featured posts, but if he goes to design, he'll see the featured posts for "design" category and so on.The thing is, the template doesn't have the slider as a widget. It's hard coded into the index.php template and when I try to use it on the page.php template, I can't get it. I have to make some edits to the code but I don't know where to start and how to do this! Please assist me with this. I've added the codes below.
The SLIDER php Code:
<?php
$loop = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1
) );
?>
<div id="slider"<?php if (option::get('featured_full') == 'on') echo ' class="full"';?>>
<div id="slides">
<?php
$i = 0;
if ( $loop->have_posts() ) : ?>
<ul class="slides">
<?php rewind_posts();
while ( $loop->have_posts() ) : $loop->the_post(); $i++;
$video = get_post_meta( $post->ID, 'wpzoom_post_embed_code', true ); ?>
<li class="post-<?php the_ID(); ?>">
<?php
if (option::get('featured_full') == 'on') {
if ( strlen( $video ) > 1 ) {
echo '<div class="video_cover">' . embed_fix( $video, 800, 475 ) . '</div>';
}
else {
get_the_image( array( 'size' => 'slider-full', 'width' => 800, 'height' => 475) );
}
} else {
if ( strlen( $video ) > 1 ) {
echo '<div class="video_cover">' . embed_fix( $video, 520, 293 ) . '</div>';
}
else {
get_the_image( array( 'size' => 'slider', 'width' => 520, 'height' => 475) );
}
}
?>
<div class="slide_content<?php if ( strlen( $video ) > 1 ) { echo "_video-enabled"; } ?>">
<div class="slide_content_holder">
<span class="date"><?php echo get_the_date(); ?></span>
<div class="clear"></div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>
</div>
</li><?php endwhile; ?>
<div class="clear"></div>
</ul><!-- /.slides -->
<?php else : ?>
<div class="notice">
There are no featured posts. Start marking posts as featured, or disable the slider from <strong><a href="<?php echo home_url(); ?>/wp-admin/admin.php?page=wpzoom_options">Theme Options</a></strong>. <br />
For more information please <strong><a href="http://www.wpzoom.com/documentation/gazeti/">read the documentation</a></strong>.
</div><!-- /.notice -->
<?php endif; ?>
</div><!-- /#slides -->
<?php
$i = 0;
if ( $loop->have_posts() ) : ?>
<div id="slider_nav">
<div class="tiles">
<?php
$first = true;
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="item<?php echo $first ? ' current' : ''; ?> post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
<?php if( has_post_format('video')){ echo '<span class="video-icon"></span>'; }?>
</a>
<div class="clear"></div>
</div>
<?php
$first = false;
endwhile; ?>
</div>
</div>
<?php endif; ?>
<div class="clear"></div>
</div><!-- /#slider -->
<div class="clear"></div>
<?php wp_reset_query(); ?>
the INDEX template
<?php get_header(); ?>
<div id="main" role="main">
<?php if (is_home() && $paged < 2 && option::get('featured_enable') == 'on' && option::get('featured_full') == 'on' ) { get_template_part('wpzoom-slider'); } ?>
<div id="content">
<?php if (is_home() && $paged < 2 && option::get('featured_enable') == 'on' && option::get('featured_full') == 'off' ) { get_template_part('wpzoom-slider'); } ?>
<?php if(is_home() && $paged < 2) { ?>
<div class="home_widgets">
<?php dynamic_sidebar('home-main') ?>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="home_widgets three-columns">
<?php dynamic_sidebar('home-columns') ?>
<div class="clear"></div>
</div>
<div class="clear"></div>
<?php } ?>
<?php if ( $paged > 1 || option::get('recent_posts') == 'on') { ?>
<div class="archiveposts">
<h3 class="title"><?php echo option::get('recent_title'); ?></h3>
<?php
global $query_string; // required
/* Exclude categories from Recent Posts */
if (option::get('recent_part_exclude') != 'off') {
if (count(option::get('recent_part_exclude'))){
$exclude_cats = implode(",-", (array) option::get('recent_part_exclude'));
$exclude_cats = '-' . $exclude_cats;
$args['cat'] = $exclude_cats;
}
}
/* Exclude featured posts from Recent Posts */
if (option::get('hide_featured') == 'on') {
$featured_posts = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1
) );
$postIDs = array();
while ($featured_posts->have_posts()) {
$featured_posts->the_post();
global $post;
$postIDs[] = $post->ID;
}
$args['post__not_in'] = $postIDs;
}
$args['paged'] = $paged;
if (count($args) >= 1) {
query_posts($args);
}
?>
<?php get_template_part('loop'); ?>
</div> <!-- /.archiveposts -->
<?php } ?>
</div><!-- /#content -->
<?php get_sidebar(); ?>
</div><!-- /#main -->
<?php get_footer(); ?>
the PAGE template
<?php get_header(); ?>
<div id="main">
<div id="content">
<h1 class="archive_title">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'wpzoom' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<?php while (have_posts()) : the_post(); ?>
<div class="post clearfix">
<div class="entry">
<?php the_content(); ?>
<div class="clear"></div>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'wpzoom' ) . '</span>', 'after' => '</div>' ) ); ?>
<div class="clear"></div>
<?php edit_post_link( __('Edit', 'wpzoom'), '', ''); ?>
</div><!-- / .entry -->
<div class="clear"></div>
</div><!-- /.post -->
<?php if (option::get('comments_page') == 'on') {
comments_template();
} ?>
<?php endwhile; ?>
</div><!-- /#content -->
<?php get_sidebar(); ?>
</div><!-- /#main -->
<?php get_footer(); ?>
How can I change the codes above to have the slider on my PAGES with the categories I want to be shown? Thanks for your help in advance.
6 Answers

udslwxmrlw
8,196 Pointshmmm i never used wpzoom slide before. So it's a bit difficult for me to find the problem. The Gazeti Theme seems to be a premium theme. So maybe the best way to find a quick solutions is to contact their support.
Just out of curiosity try this and see what happens:
<?php
$loop = new WP_Query($args);
$args = array();
if (is_page(1887)) {
$args[] = 'cat' => 'tajik';
}
elseif (is_page(1885)) {
$args[] = 'cat' => 'afghan';
}
?>

udslwxmrlw
8,196 PointsHi!
I took a glance at your code and would take this approach (Not sure if this suites your exact needs, but maybe worth a try)
1.) Install Custom Post-type UI Plugin ( https://wordpress.org/plugins/custom-post-type-ui/)
2.) Go to the Custom Post-type UI Interface and set your 3 post-types, one post-type for each page.
3.) Create 3 new pages in the wordpress backend and write the page IDs down. (This nice plugin reveals every ID in your page overview -> https://wordpress.org/plugins/reveal-ids-for-wp-admin-25/)
4.) Include the Slider template in page.php without the "if conditional"
<?php get_template_part('wpzoom-slider'); ?>
5.) Open up the code of the slider (i guess wpzoom-slider.php ) and add a" if else" condition that checks the page ID and changes the correspondent and adds a post type parameter to the array in $loop.
<?php if (is_page(ID_01)) {
$loop[] = 'post_type' => 'post_type_01';
} elseif (is_page(ID_02)) {
$loop[] = 'post_type' => 'post_type_02';
} elseif (is_page(ID_03)) {
$loop[] = 'post_type' => 'post_type_03';
}
?>

udslwxmrlw
8,196 PointsForget the post types. Should work with post categories too.
<?php if (is_page(ID_01)) {
$loop[] = 'cat' => 'e.g. design';
} elseif (is_page(ID_02)) {
$loop[] = 'cat' => 'e.g. business';
} elseif (is_page(ID_03)) {
$loop[] = 'cat' => 'e.g. news';
}
?>

Arash Emadi
10,002 PointsHi Selwyn,
Thanks for your response. I think this should work.. However, I should know where to add the code you've kindly typed for me above. I should also mention that, I don't want the Slideshow on the homepage to change. I want the slideshow on the homepage to show all the categories (all featured articles from all categories. Just like it's doing right now.). So I think the if/else statements will change having this in mind. Could you please tell me how to write the code? I tried the code below, but the page didn't load.. The IDs I've used are the real ones from the pages I've added. I also don't know how to write the IDs in the parentheses.. So I guessed the mistake was mine:
<?php
$loop = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1,
'cat'
) if (is_page(ID_1887 )) {
$loop[] = 'cat' => 'tajik';
}
elseif (is_page(ID_1885 )) {
$loop[] = 'cat' => 'afghan';
});
?>

udslwxmrlw
8,196 PointsHi!
The slider on the frontpage should not change with the code i pasted before, as the if statements just are applied if the specified page IDs are met.
You don't need to write "ID_" before the number. Correct would be e.g. :
<?php if (is_page(1887)) { ... ?>

Arash Emadi
10,002 PointsOK! I tried the codes below, but the page won't load:
1:
<?php
$loop = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1,
'cat'
)
if (is_page(1887)) {
$loop[] = 'cat' => 'tajik';
}
elseif (is_page(1885)) {
$loop[] = 'cat' => 'afghan';
});
?>
2:
<?php
$loop = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1,
'cat'
));
if (is_page(1887)) {
$loop[] = 'cat' => 'tajik';
}
elseif (is_page(1885)) {
$loop[] = 'cat' => 'afghan';
}
?>
3:
<?php
$loop = new WP_Query(
array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1,
'cat'
));
?>
<?php
if (is_page(1887)) {
$loop[] = 'cat' => 'tajik';
}
elseif (is_page(1885)) {
$loop[] = 'cat' => 'afghan';
}
?>
What am I doing wrong?!

udslwxmrlw
8,196 PointsSorry I'm not sure if the way i was trying to add a new element in the array was correct.
Try this:
<?php
$loop = new WP_Query($args);
$args = array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => option::get('featured_number'),
'meta_key' => 'wpzoom_is_featured',
'meta_value' => 1,
);
if (is_page(1887)) {
$args[] = 'cat' => 'tajik';
}
elseif (is_page(1885)) {
$args[] = 'cat' => 'afghan';
}
?>

Arash Emadi
10,002 PointsNo Luck :( I can share the links with you too if you want to know what I mean by the pages not loading. I only get my "Header"..

Arash Emadi
10,002 PointsAlso, when I remove the IF/ELSE statements from the new code, I get the error: THERE ARE NO FEATURED POSTS available...

mohamed samir
1,152 Pointsi dont understand what can i do to add slide show when i enter on the website on down nav-bar ???

Dwayne Munro
Front End Web Development Techdegree Student 13,108 PointsHow to add your own picture to the profile-image class?
Arash Emadi
10,002 PointsArash Emadi
10,002 PointsHi again!
So I had to try different things, but I finally succeeded. However, I'm now facing new problems, which I think you can help me with. The slideshow is different and unique in every page now with it's own unique articles, but now the slider won't show any picture or date to the articles. It only shows the title which is correctly linked to the article. I've added some of the codes below for you. Can you help me with this?!
My Special Slider for Afghan Page:
The NEW Page.php Template:
The Post-Options.php file:
The Options.php file:
The Functions.php file (I think the problem comes from this file):
Thanks for your help in advance. I can share the URL with you too if you want. Just let me know how I can contact you. Thanks again.