Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6092121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:24:22+00:00 2026-05-23T12:24:22+00:00

I am building a gallery in WordPress and I’m trying to grab a specific

  • 0

I am building a gallery in WordPress and I’m trying to grab a specific part of my URL to echo into the id of a div.

This is my URL:

http://www.url.com/gallery/truck-gallery-1

I want to isolate the id of the gallery which will always be a number(in this case its 1). Then I would like to have a way to print it somewhere, maybe in the form of a function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:24:23+00:00Added an answer on May 23, 2026 at 12:24 pm

    You should better use $_SERVER['REQUEST_URI']. Since it is the last string in your URL, you can use the following function:

    function getIdFromUrl($url) {
        return str_replace('/', '', array_pop(explode('-', $url)));
    }
    

    @Kristian ‘s solution will only return numbers from 0-9, but this function will return the id with any length given, as long as your ID is separated with a - sign and the last element.

    So, when you call

     echo getIdFromUrl($_SERVER['REQUEST_URI']);
    

    it will echo, in your case, 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code: http://blogswizards.com/plugin-development/sliding-boxes-and-captions-with-jquery On a simple gallery site I am building. Specifically
Background: I'm building this photo gallery in AS3, when user clicks a thumbnail is
I am building a picture gallery, that uses this code to display each product
I am building my own image gallery, Like fancybox . See: http://snabbdesign.com/stack/stack.html I am
I'm trying to figure out how imgur.com is building their gallery (the one on
I am building a simple image gallery based on the following markup: <div id=image-list>
Bit stuck with this one. I'm building a product image gallery for a Shopify
I'm building a Joomla 1.7 website and I'm using a gallery plugin. This works
I'm building a simple image gallery with jquery but running into an annoying problem.
I've run into a weird quirk. The website I'm building for Escondido Arts Gallery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.