Forums

[resolved] How to show category slug(nicename) in path? (6 posts)

  1. PuNK
    Member
    Posted 3 years ago #

    Hi...
    i m setting up a new blog.
    i want to put all the content(images) of a particular categ in separate folder. which is named as categ-slug name
    Path is wp-content/uploads/categ-slug/

    how can i get the slug name in the image path?
    i want to use this code
    <textarea rows="2" cols="80"><img src="http://www.mysite.com/wp-content/uploads/<category slug folder>/imagename.jpg"></textarea>

    i want to use this in the loop for each post
    so that it get each post's categoery & display dat category-slug in the image src path.

    how can i do that?
    thanks in advance

  2. PuNK
    Member
    Posted 3 years ago #

    I used with in the loop
    <?php $category = get_the_category( ); ?>

    & in the image path
    <img src="http://www.mysite.com/wp-content/uploads/<?php echo $category[0]->cat_name; ?>/imagename.jpg">

    but it returns category name
    i want category slug
    so try to use
    <img src="http://www.mysite.com/wp-content/uploads/<?php echo $category[0]->category_nicename; ?>/imagename.jpg">

    but its not returning category name
    plz HELP !!!

  3. What is it returning?

  4. PuNK
    Member
    Posted 3 years ago #

    i was waiting from long time
    in this "support forum" for Support which was missing
    thanks for replying [:)]

    its returning path as
    <img src="http://www.mysite.com/wp-content/uploads//imagename.jpg">

  5. It's a volunteer support forum. And 20 hours isn't all that bad.

    1) Are you using this in The_loop?
    2) Does cat_ID spit out anything?

    It also helps if you toss your URL out there :) Sometimes looking at a site gives people hints.

    This is a stab at trying to keep it all together based on the suggestion from the codex:

    <?php
    $category = get_the_category();
    echo '<img src="http://www.mysite.com/wp-content/uploads/' . $category[0]->category_nicename . 'imagename.jpg" />';
    ?>
  6. PuNK
    Member
    Posted 3 years ago #

    thanks

    code which i used working now

    i think sum page refresh or cache problem !!!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.