WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Random Post Link] Add specific Category (4 posts)

  1. blpinferno
    Member
    Posted 4 years ago #

    Hi,

    I would love to be able to limit the results to a specific category. Is this possible with this plug in?

    Thank you in advance!!

  2. scribu
    Member
    Posted 4 years ago #

    Sure. Just add this to your theme's functions.php:

    function my_random_post_args($args) {
        $args['category_name'] = 'my-category-slug';
    
        return $args;
    }
    add_filter('random_post_args', 'my_random_post_args');

    Of course, replace 'my-category-slug' with your category slug.

  3. doodleface
    Member
    Posted 3 years ago #

    hey,

    any chance of specifying the category for each random link? basically i have 'music' and 'videos' as categories and it would be great if i could have a separate random post link for each cat :/

  4. ishotr
    Member
    Posted 3 years ago #

    @scribu I tried posting in the code into the functions.php. However, it ended up disabling my blog b/c it caused an error in the functions file. Do you replace the "my-category-slug" only? Or do you change anything else? I think I may be implementing this code incorrectly in my functions.php file.

    this is my code:

    <?php
    if ( 
    
    function_exists('register_sidebar') ) {
        register_sidebar(array(
    		'name' => 'Wide Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Left Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Right Sidebar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Left Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Mid Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name' => 'Right Footbar',
    		'before_widget' => '<div class="block %1$s %2$s">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3 class="boxedin">',
    		'after_title' => '</h3>',
        ));
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic