Support » Fixing WordPress » Featured Image Slider – Want to display one category

  • Hi all,

    I’m quite new to WordPress and would like help with restricting a part of my site to showing only a certain product category.

    I have a ‘Featured Post Slider’ on my site and would like it to only display one category, I have the ID – just have no idea where to edit the code..

    <?php
    
    				 $querydetails = "
    				   SELECT wposts.*
    				   FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    				   WHERE wposts.ID = wpostmeta.post_id
    				   AND wpostmeta.meta_key = 'omc_featured_post'
    				   AND wpostmeta.meta_value = '1'
    				   AND wposts.post_status = 'publish'
    				   AND wposts.post_type = 'post'
    				   ORDER BY wposts.post_date DESC
    				 ";
    
    				 $pageposts = $wpdb->get_results($querydetails, OBJECT)
    
    			?>
    			<?php 
    
    			$i = 0;
    			if ($pageposts):
    			foreach ($pageposts as $post):
    			setup_postdata($post);
    			$category = get_the_category();
    			$omc_is_video = get_post_meta(get_the_ID(), 'omc_is_video', true);
    			$i++;
    			$format = get_post_format();
    			if ($i <9) {
    			?>

    Any help would be greatly appreciated.

    Many thanks,

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Try changing this [untested]:

    $querydetails = "
    				   SELECT wposts.*
    				   FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    				   WHERE wposts.ID = wpostmeta.post_id
    				   AND wpostmeta.meta_key = 'omc_featured_post'
    				   AND wpostmeta.meta_value = '1'
    				   AND wposts.post_status = 'publish'
    				   AND wposts.post_type = 'post'
    				   ORDER BY wposts.post_date DESC
    				 ";
    
    				 $pageposts = $wpdb->get_results($querydetails, OBJECT)

    to this:

    $category_ID = 25;
    $querydetails = "
    				   SELECT wposts.*
    				   FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    				   INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id)
    				   INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
    				   WHERE wposts.ID = wpostmeta.post_id
    				   AND wpostmeta.meta_key = 'omc_featured_post'
    				   AND wpostmeta.meta_value = '1'
    				   AND wposts.post_status = 'publish'
    				   AND wposts.post_type = 'post'
    				   AND tt.taxonomy = 'category'
    				   AND tt.term_id = '$category_ID'
    				   ORDER BY wposts.post_date DESC
    				 ";
    
    				 $pageposts = $wpdb->get_results($querydetails, OBJECT);

    Change the category ID in

    $category_ID = 25;

    Hi Kessiemeijer,

    Many thanks for your reply – it hasn’t seemed to have worked though. Is there a way to changed SELECT wposts.* to select category ID ’55’? I just dont know the code :\

    Thanks again,

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    it hasn’t seemed to have worked though

    Did it return posts or not, or the wrong posts?

    Oh sorry, it returned no posts at all.

    Thanks,

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Do you still want to use the custom field “omc_featured_post” or only use posts of category 55 for the featured posts?

    Correct, I only want category 55 to show in the slider.

    My idea is to be able to then choose which posts are visible on my homepage.

    Many thanks,

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Then try changing this:

    $category_ID = 25;
    $querydetails = "
    				   SELECT wposts.*
    				   FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    				   INNER JOIN {$wpdb->term_relationships} tr ON ($wpdb->posts.ID = tr.object_id)
    				   INNER JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
    				   WHERE wposts.ID = wpostmeta.post_id
    				   AND wpostmeta.meta_key = 'omc_featured_post'
    				   AND wpostmeta.meta_value = '1'
    				   AND wposts.post_status = 'publish'
    				   AND wposts.post_type = 'post'
    				   AND tt.taxonomy = 'category'
    				   AND tt.term_id = '$category_ID'
    				   ORDER BY wposts.post_date DESC
    				 ";
    
    				 $pageposts = $wpdb->get_results($querydetails, OBJECT);

    to this:

    $pageposts = get_posts('cat=55&posts_per_page=10');

    change posts_per_page=10 to how many posts you want to use.

    Awesome 😀

    It works – thank you!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    You’re welcome. I’m glad you got it resolved 🙂

    Hi keesiemeijer,

    Sorry for dropping in like this.
    But my problem is some what similar to what wbarsby has faced.

    I am trying to show the next and previous button in my website for single post navigation.
    For this I have used a plugin “WP Single Post Navigation Within Category”.

    However, I want this previous and next buttons to appear in only a single category and not in all categories.

    I found in the style.css file of the plugin that the buttons can be removed for anyone accessing my website through a handheld device.

    The code lines were as follows…………….
    ———————————————-

    @media screen and (max-width: 1024px) {
    .wpspn-area,
    #wpspn-nextpost,
    #wpspn-prevpost {
    display: none;
    }
    }

    ———————————————–

    I guess the line ” @media screen and (max-width: 1024px) ” can be replaced with a proper code to hide the buttons for all other categories except one.

    I am a complete novice and doesn’t have any idea about coding.

    Can you be kind enough to tell me what will be the code, I wish to use my category ID = 21 for showing the buttons.

    Hi experts.

    Any one?

    any idea?

    Can someone help on this?
    I tried to create the plugin support forum also
    But it seems they have withdrawn support for this plugin — ‘WP Single Post Navigation’.

    WOULD REALLY APPRECIATE HELP ON THE TOPIC FROM ANYONE WHO KNOWS ABOUT THE SUBJECT.

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    @satyaki
    Your question has nothing to do with a featured image slider, please continue here: http://wordpress.org/support/topic/interesting-reversal-of-options

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Featured Image Slider – Want to display one category’ is closed to new replies.