• Hello,

    This is the first time I am creating wordpress theme from scratch… I am not much experienced with wordpress development and php too.

    Here everything is going quite okay but stuck now at the point where I need you experts help. I want to add some post from different category on the home page and did that with below code and works just fine.
    <?php query_posts('category_name=interviews, photography, uncategorized&showposts=4'); ?>

    But as a theme developer I want to allow user to add category name and even post count from either admin panel or through custom field. So can any one please help me to solve this how can I add the code where user can add them category name through custom field or from admin panel as well as post count too.

    Looking for reaply.

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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).

    Thread Starter pixelandgrain

    (@pixelandgrain)

    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.

    Thread Starter pixelandgrain

    (@pixelandgrain)

    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.

    Thread Starter pixelandgrain

    (@pixelandgrain)

    Hello please anyone can guide me to do this pls

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hoe yo make this with custom field’ is closed to new replies.