Forums

[resolved] Multiple Tags Pages (6 posts)

  1. clicknathan
    Member
    Posted 3 months ago #

    I'm wondering if there's a URL string that can represent multiple tags.

    Something like:

    website.com/?tag=cigarettes&addiction

    This doesn't work, it only returns the cigarettes tag result.

    Any ideas?

  2. Kafkaesqui
    Moderator
    Posted 3 months ago #

    ?tag=cigarettes,addiction

    returns posts with the tags cigarettes OR addiction

    ?tag=cigarettes+addiction

    returns posts with the tags cigarettes AND addiction

  3. clicknathan
    Member
    Posted 2 months ago #

    Thanks Kaf. I had tried all combinations of ampersands, some slash combos.

    Good ol' commas and plus signs. In this day and age of space pirates and Wii remotes how often we forget the simple things.

  4. 11Mystics
    Member
    Posted 1 week ago #

    Thanks for this tip - exactly what I needed too, but now I have another problem related to this.

    I display wp_title() on all my pages which works great and looks really nice. But when you generate a page with two tags, the title only shows the first tag specified and NOT the second one. It's creates a misleading visual.

    I found a php tag for single tag title, but no multiple tag title. Is there any way to do this?

  5. Viper007Bond
    Member
    Posted 6 days ago #

    &'s are reserved for splitting up parameters. In your original code, tag is set to cigarettes and addiction is set, but blank. ;)

  6. scribblerguy
    Member
    Posted 5 days ago #

    This is for 11Mystics (and anyone else curious). The following is how I'm currently grabbing the tag query string for display purposes. Inside my functions.php file is the following:

    function my_get_the_tag_query() {
     $nice_tag_query = $_SERVER['REQUEST_URI'];
     $nice_tag_query = str_replace('/tag/','', $nice_tag_query);
     $nice_tag_query = str_replace(',', ', ', $nice_tag_query);
     $nice_tag_query = str_replace('/','', $nice_tag_query);
     return $nice_tag_query;
    }

    Quick explanation: The above assumes a permalink structure where the base for all tag pages is "/tag/" (e.g. "www.example.com/tag/"). The function grabs part of the URL/URI string and then uses the str_replace() function to clean up the output by removing the "tag" and slashes. Right now, I'm leaving the plus signs as is and just adding a space after any comma.

    For the web page title, just echo the output of this function. If you're using a common header file, then add an extra conditional statement for the title section, using WordPress' is_tag() function.

Reply

You must log in to post.

About this Topic