• Resolved tobiasfeltus

    (@wordpresstobiasfeltuscom)


    Hi there,
    I am working on my first custom theme, which is very simple, purposefully. I am trying to link to Categories with a menu of buttons in the header. I had it working fine in the initial local tester using the standard syntax

    <a href="index.php?cat=7">Category Title</a>

    However for practical or visual reasons I would prefer for the permalink structure to be

    /%category%/%postname%/

    But what I have found, now, is that I am not sure how to link to the Category.

    I thought it might be something like this

    <a href="../index.php/Diary/">

    but have found this to not work, as the address hierarchy does not represent physical directories on the server.

    Can anyone help please?

Viewing 13 replies - 1 through 13 (of 13 total)
  • <a href="index.php?cat=7">Category Title</a>
    No! That’s really bad practice. You need to grab the permalink for the relevant category. Why are you hard coding a menu anyway?

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    The menu is hard-coded because the site is built graphically, and the link buttons to the categories are images (with text on them). Beside the fact that I am not any good at coding, and trying to understand dynamic coding is far beyond my meagre brain.

    The above code that you despise is what the Codex recommends. It did work, but does not with the new permalink structure.

    But I am still not clear what I need to do. Right now I am moving the WP core to a subdirectory, to eliminate conflicts with the Index.htm “splash page”.

    Thanks Esmi.

    The above code that you despise is what the Codex recommends.

    Where? Url?

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    Hmm… that page hasn’t been touched for 2 years and might need revising. However, it’s talking about creating links within a live site – not a theme. A theme has to be flexible and deal with multiple different situations effectively. So you need to use inbuilt WordPress core functions to generate the appropriate permalinks.

    The menu is hard-coded because the site is built graphically, and the link buttons to the categories are images (with text on them).

    It is still possible to use a dynamic menu function such as wp_list_pages, wp_page_menu or wp_nav_men and apply the graphics using CSS.

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    I am not building a theme to be used for anything other than this specific site. I know this may seem strange to you, but my intent is to have a site that can be fully maintained by the user, and not me, but has the same structural feel to an html site.

    Using a permalink structure of

    /%category%/%postname%/

    is there not a way to link to the categories from within the Header?

    my intent is to have a site that can be fully maintained by the user, and not me

    Then the theme needs to be able to cope with whatever the user throws at it. I’ve seen hard-coded sites like these and, trust me, they cause no end of trouble longer term.

    /%category%/%postname%/

    You want individual posts in your menu?

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    No, I don’t want the individual posts to be linked to by the menu, just the link categories.

    It is a site for a band, and the menu has links to categories that function like html pages, for things like

    Diary, Lyrics, Gigs, Bio, etc.

    So the hard links should work. What kind of issue do you expect to occur in the longer term?

    If they decide to add a new category. Or get rid of an old one. Why not just use wp_list_categories to generate the menu items, CSS to push the menu text off screen and replace it with a graphic and build in a default, text-less graphic if they add a new category.

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    I can deal with changes of that kind, if necessary. This is the kind of change that, if it were an HTML site, would need a massive overhaul anyway. So this is not my worry.

    If you look at the holder splash page (www.lipsyncforalullaby.com) then you may see why I don’t want to work in that manner. the graphics are to look like a booklet of old sheet music, or were based on this, therefore the text is “distressed”, etc.

    Tobais, esmi is absolutely right. If you can avoid hard coding it, there will far less problems in the future. Also, the text really isn’t that distressed and you could easily find some web fonts and you html text rather than a big image. You can then change CSS page to page so that you could have a splash page that looks similar to what you have, but with live text, links, etc.

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    :-~

    I hear both of your recommending that I go about trying to code this dynamically, but I would end up spending another couple of weeks of trial and error to figure out how to do this, as I have no budget to subcontract the coding. But more to the point, I am comfortable with the limitation of my approach. The visual element is tied into the printed media of the band, and thus should remain as it is.

    If either or any of you do know how to write the hard-coded links, I would be most obliged, as this will allow me to move on with other tasks.

    Thread Starter tobiasfeltus

    (@wordpresstobiasfeltuscom)

    in conclusion, it seems that my server was possibly displaying a cached copy of the header. linking like this

    a href=”../lyrics/”

    seems to work, once one is in one of the category directories. I resolved it on my localhost, and overwrote the remote copy and it now works. On to the next task.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘how to link to a category with custom permalinks…’ is closed to new replies.