<p>I’m not sure if those Tumblr URLs are just an incrementing ID (so each new post is +1 greater than the last one), or if it’s a randomly-generated string of numbers.</p>

<p>If you just want yours to be the entry ID, all you’d have to do is go into your section’s settings, and set the following:</p>

<ul>
<li><strong>Do entries in this section have their own URLs?</strong> [check]</li>
<li><strong>Entry URL Format:</strong> <code>post/{id}</code></li>
</ul>

<p>If you want it to be random, that’s a little more difficult. You would need to create a custom text field that stores the random number, attach it to your section, and start entering random numbers into it when creating new entries (or you could write a custom <a href="http://buildwithcraft.com/docs/plugins/field-types" rel="nofollow">field type</a> that handles this for you). Then your <strong>Entry URL Format</strong> would get set to <code>post/{customFieldHandle}</code> instead of <code>post/{id}</code>.</p>

<p>As for the image URL, if you have an Assets field that’s responsible for storing the entry’s main image, you can set it to restrict uploads to a single directory, and give it a subfolder based on the entry’s ID/random number custom field handle. (See <a href="http://buildwithcraft.com/docs/assets-fields#restricting-uploads-to-a-single-folder" rel="nofollow">http://buildwithcraft.com/docs/assets-fields#restricting-uploads-to-a-single-folder</a>)</p>

CC BY-SA 3.0
2014-09-18T13:45:13.330Z
2014-09-18T13:45:13.330Z
Brandon Kelly
<p>Entries have the <strong>url</strong> attribute, which you can access like so:</p>

<pre><code>&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
</code></pre>

<p><a href="http://buildwithcraft.com/docs/templating/craft.entries" rel="nofollow">See example in the docs</a></p>

<p>If you upload an image through Assets, you can get the url for the image by doing something like this:</p>

<pre><code>&lt;img src="{{ entry.imageHandle.first().getUrl() }}" alt="" /&gt;
</code></pre>

<p>Note that the getUrl takes an optional transform name, if you have added any <a href="http://buildwithcraft.com/docs/image-transforms" rel="nofollow">transforms</a>.</p>

<p>See more in the <a href="http://buildwithcraft.com/docs/templating/craft.assets" rel="nofollow">docs on craft.assets tag</a>.</p>

CC BY-SA 3.0
2014-09-18T10:17:25.580Z
Hi Fred, sorry I meant auto URLs like "95032257420" instead of the URL title...
rey
CC BY-SA 3.0
2014-09-18T23:53:14.863Z
I wrote a plugin that allows you to generate strings like that: https://github.com/sjelfull/Craft-Randomm
Fred Carlsen
CC BY-SA 3.0
2014-09-18T08:27:47.067Z
2014-09-18T08:27:47.067Z
Fred Carlsen
<p>How to auto-generate URLs in Craft? For example when we upload images on Tumblr, an URL to the post is created:</p>

<p><a href="http://twotimeselliott.tumblr.com/post/95032257420" rel="nofollow">http://twotimeselliott.tumblr.com/post/95032257420</a></p>

<p>And an URL for the image is created:</p>

<p><a href="http://31.media.tumblr.com/2142197f5273865770be44723c2a5df0/tumblr_nagyr9INCE1r6ky2bo1_500.jpg" rel="nofollow">http://31.media.tumblr.com/2142197f5273865770be44723c2a5df0/tumblr_nagyr9INCE1r6ky2bo1_500.jpg</a></p>

<p>How can we do that in Craft?</p>

<url>
How to auto-generate URLs in Craft?
# How to auto-generate URLs in Craft?

(Asked by: username_0 on 2014-09-18)

How to auto-generate URLs in Craft? For example when we upload images on Tumblr, an URL to the post is created:

<http://twotimeselliott.tumblr.com/post/95032257420>

And an URL for the image is created:

<http://31.media.tumblr.com/2142197f5273865770be44723c2a5df0/tumblr_nagyr9INCE1r6ky2bo1_500.jpg>

How can we do that in Craft?

**Tags:** url


---

## 2 answers

### Answer by username_1 on 2014-09-18. Score: 3 | Accepted answer

I’m not sure if those Tumblr URLs are just an incrementing ID (so each new post is +1 greater than the last one), or if it’s a randomly-generated string of numbers.

If you just want yours to be the entry ID, all you’d have to do is go into your section’s settings, and set the following:

* **Do entries in this section have their own URLs?** [check]
* **Entry URL Format:** `post/{id}`

If you want it to be random, that’s a little more difficult. You would need to create a custom text field that stores the random number, attach it to your section, and start entering random numbers into it when creating new entries (or you could write a custom [field type](http://buildwithcraft.com/docs/plugins/field-types) that handles this for you). Then your **Entry URL Format** would get set to `post/{customFieldHandle}` instead of `post/{id}`.

As for the image URL, if you have an Assets field that’s responsible for storing the entry’s main image, you can set it to restrict uploads to a single directory, and give it a subfolder based on the entry’s ID/random number custom field handle. (See <http://buildwithcraft.com/docs/assets-fields#restricting-uploads-to-a-single-folder>)


---

### Answer by username_2 on 2014-09-18. Score: 0

Entries have the url attribute, which you can access like so:
{{ entry.title }}

See example in the docs
If you upload an image through Assets, you can get the url for the image by doing something like this:


Note that the getUrl takes an optional transform name, if you have added any transforms.
See more in the docs on craft.assets tag.

> **Comments:**
> **username_0**: Hi Fred, sorry I meant auto URLs like "95032257420" instead of the URL title...  
> **username_2**: I wrote a plugin that allows you to generate strings like that: https://github.com/sjelfull/Craft-Randomm  

---

