WordPress.org

Ready to get started?Download WordPress

Forums

Category dropdown that links to first post in category (1 post)

  1. skaymus
    Member
    Posted 1 year ago #

    I'm working on a comic book reader for a client's web comic.
    I'm only just getting in to WordPress, so this has really stumbled me.

    I am dividing the chapters of the comic using categories.
    At the head of the website I want a select box that displays all the chapters (categories) and will bring them to the first post in each chapter (category) on click.
    I've pretty much got it, I just don't know how to direct them to the permalink of the first post in the category.

    <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
    
        <?php
            $categories=  get_categories('child_of=3');
            foreach ($categories as $category) {
                $option = '<option value="/pdcomic/chapter/'.$category->category_nicename.'">';
                $option .= $category->cat_name;
                $option .= '</option>';
                echo $option;
            }
        ?>
    </select>

Topic Closed

This topic has been closed to new replies.

About this Topic