How to edit slider in WordPress template

Hope someone can help me with this!

My blog is in wordpress and when you look at the default category page it looks empty, just plain post list so i figured it would be nice to have last few category posts before the content.

With the theme which I’m using silverOrchid i already have front page slider which i like so i would like to copy that slider in the category.php which i created earlier and change it to show and change latest posts per category which users are reading.

Here is slider code from index.php
[php]//include slider
if ( $gazpo_settings[‘gazpo_show_slider’] == 1 ) {
get_template_part(‘includes/slider’);
}[/php]

So my question is how i change this code (if possible) to show latest posts from category which users are reading. I tried a few different forum threads but non of them seams understandable enough for me so i would appreciate help … thanx

In order to achieve this, you will need to create a custom loop in your category.php file. This loop will query the database for the latest posts in the category that the user is currently viewing. You can then add the slider code to the loop so that it displays the latest posts in the category in the slider.

Here is an example of what the code might look like:

[php]// Get the current category
$category = get_queried_object();

// Create the custom loop query
$query_args = array(
    'cat' => $category->term_id,
    'posts_per_page' => 5,
    'orderby' => 'date',
    'order' => 'DESC'
);
$category_posts = new WP_Query( $query_args );

// Include the slider
if ( $gazpo_settings[‘gazpo_show_slider’] == 1 ) {
    get_template_part(‘includes/slider’);
    if( $category_posts->have_posts() ) {
        while( $category_posts->have_posts() ) {
            $category_posts->the_post();
            the_title();
        }
    }
}

// Reset the query
wp_reset_postdata();[/php]

This code will get the current category and create a custom loop to query the database for the latest posts in that category. The slider code is then included in the loop so that it displays the latest posts in the category in the slider.

@darkfreaks , the op is over 10 years old. Stop going through the forum and reseructing every post you see.

Sponsor our Newsletter | Privacy Policy | Terms of Service