First, do not use query_posts() for adding secondary loops. From the Codex:
It is meant for altering the main loop. For creating secondary loops, you should make a new instance of WP_Query and use that instead
I would recommend using get_posts() for your purpose. You can pass a user-defined variable to it in the arguments array, to specify which category to return.
Assuming the category is a Theme option:
$mytheme_options = get_option( 'theme_mytheme_options' );
$getpostscat = $mytheme_options['second_loop_cat'];
$getpostsargs = array(
'category' => $getpostscat;
'numberposts' => 5 // assuming you want to return 5 posts
);
$second_loop = get_posts( $getpostsargs );
Now you can output your secondary loop, stored in the $second_loop
variable (as an object).
Hello Chip Bennett,
Thank you so much for your instant reply. But as I have mentioned above I am not much familiar with php and wordpress development. I understand a bit what you said. One thing I would mentioned here bit specifically that I may be use this in page/post custom field using More Field plugin.
Or may be if I can do I would be happy to use it in theme option also in some case. But I don’t know how to implement this code with my theme option.. I am embedding my thing code below to give you an idea what I am using for my theme.
array( "name" => "Homepage featured category",
"desc" => "Choose a category from which featured posts are drawn",
"id" => $shortname."_feat_cat",
"type" => "select",
"options" => $wp_cats,
"std" => "Choose a category"),
Above code I am using for my theme option panel. So can you please help me to find the solution for both admin panel and with More Field plugin as well custom field too.
Thanks again..
I don’t think that using a Post custom field would be helpful at all for this implementation.
If you implement it in your Theme Options, then you should be able to reference my code above, changing the option names to suit your specific use case.
Can you please do one more help?
Can you please write few codes which fits with my theme option panel format what I have posted in above post and what I should put in my theme file as well.
Also I need to use it with either custom field or More Field plugin as I want to allow user to select category for some other custom page template.
Can you please help me above.
Hello please anyone can guide me to do this pls