Not signed in ( Sign In)

Categories

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthorsjaeger
    • CommentTimeFeb 26th 2010
     permalink
    Hello everyone,

    I would like to have an individual static text placed above each category entries. Now I don't know how to realize that? Create a static page and integrate the category entries? Or -the other way 'round- insert a static/widget into the category pages somehow? So far, I wasn't able to make that work.
    Would it be possible to hack the default.tpl to insert a text stored somewhere in a .txt file? I think it could be possible to insert a variable inbetween these layers...
    <div id="main">

    <div class="entry">

    ...but how to? I have to admit, my knowledge in php is only rudimentary; I'm just able to copy&paste snipplets :-D
    I hope my inquiry is comprehensible. Any hints are apprecciated.

    Cheers

    Stefan
    •  
      CommentAuthorStanley
    • CommentTimeFeb 27th 2010
     permalink
    You mean show a different text for each category?

    Try adding this to your index.tpl file right after the opening of the "main" div, like so:


    <div id="main" class="main">

    {php}
    $catpage = $_GET["x"];
    if ($catpage=="cat:1") {
    echo "Welcome to category 1";
    }
    if ($catpage=="cat:2") {
    echo "Welcome to category 2";
    }
    {/php}


    Obviously add/change the category ID's to suit what you use.

    Also it doesn't have to go there - you can put it whichever tpl file you want (e.g. header.tpl or footer.tpl etc.)

    I haven't tried it like it's shown here, but it's basically what I do to include a category-specific sub-menu, so it should give you a start.

    Hope this helps.
    •  
      CommentAuthorsjaeger
    • CommentTimeFeb 27th 2010
     permalink
    Hi Stanley, showing a different text for each category was exactly what I meant. Thanks for your reply!
    I've put your code into the index.tpl but unfortunately it doesn't work. The echoed part doesn't show up. I had a look into the source code - there isn't anything inserted as well. ...and I didn't forget to save and upload the index.tpl ;-)
    Any ideas what could be wrong?
    •  
      CommentAuthorStanley
    • CommentTimeFeb 27th 2010 edited
     permalink
    Nothing that springs to mind - I just did a quick test to see if I'd goofed but it worked perfectly for me.

    First make sure that the url in your address bar is showing as http://[your-fp-blog-address]/?x=cat:[category number]

    You could try going into the maintenance section of the admin area and flushing out the theme & templates cache, then try it again. Just make sure you have the category number correct and that you surround the code with the {php}{/php} tags instead of normal PHP ones when you want to add PHP to a template file.
    •  
      CommentAuthorsjaeger
    • CommentTimeFeb 28th 2010
     permalink
    First make sure that the url in your address bar is showing as http://[your-fp-blog-address]/?x=cat:[category number]

    Aaah, that could be the problem. I have my URLs rewritten (PrettyURL activated) like this: http://myblog.com/category/myfirstcategory
    Is there any possibility to adapt the code to fit this?
    •  
      CommentAuthorStanley
    • CommentTimeFeb 28th 2010
     permalink
    Just one of the reasons I prefer not to use PrettyURLs is that it makes life just that little bit harder for myself!

    You could try something like this, to get at whatever's on the end of your URL:

    {php}
    $file = $_SERVER["SCRIPT_NAME"];
    $break = Explode('/', $file);
    $catpage = $break[count($break) - 1];

    if ($catpage=="MyFirstCategory") {
    echo "Welcome to category 1";
    }
    if ($catpage=="MySecondCategory") {
    echo "Welcome to category 2";
    }
    {/php}


    This is the same code I use to determine what the filename of the current page is (e.g. index.php, contact.php etc.), so it should work - though I don't use PrettyURLS so I can't test it. You may need to hack the above code a little.

    Good luck.
    •  
      CommentAuthorsjaeger
    • CommentTimeFeb 28th 2010
     permalink
    Hi Stanley, I made it work.
    I found a solution based on the approach you initially posted. Tried out the second and found out that the file name of the category page always is "index.php." So that didn't work.
    Here's the code that works with my configuration:

    {php}
    $catpage = $_GET["x"];
    if ($catpage=="y:/MyFirstCategory") {
    echo "Welcome to category 1";
    }
    if ($catpage=="y:/MySecondCategory") {
    echo "Welcome to category 2";
    }
    {/php}


    I don't know where the y:/ comes from, but since it works I'm satisfied.
    Many thanks for your help!

    Cheers

    Stefan
    •  
      CommentAuthorlugano
    • CommentTimeMar 4th 2010
     permalink
    Great code Stanley.
    Although I could not get it to work with pretty url.
    You could guide me to find the solution?.
    Note: sjaeger, your code works with the active PrettyURLs, I do not work
    Any advice?

    Thanks
    •  
      CommentAuthorStanley
    • CommentTimeMar 4th 2010
     permalink
    Posted By: StanleyJust one of the reasons I prefer not to use PrettyURLs is that it makes life just that little bit harder for myself!


    I think, if you hack around with things long enough, you'll get somewhere near. Share your results and check your source code on your generated pages for any tell-tale clues about where it might be going wrong and maybe someone can help you fix it.

    Also take a read of this thread and see if it helps you to find a solution in a different way.
    •  
      CommentAuthorsjaeger
    • CommentTimeMar 4th 2010 edited
     permalink
    Note: sjaeger, your code works with the active PrettyURLs, I do not work
    Any advice?

    So, you work with a different version of PrettyURLs?
    I found the correct syntax through "echoing" the $catpage like this:
    {php}
    $catpage = $_GET["x"];
    echo "$catpage";
    {/php}

    Thereby you should find out what syntax is used for your configuration. For me, I always had to put the "y:/" before each category in this string:
    if ($catpage=="y:/MyCategory")
    Hope that was understandable.
    •  
      CommentAuthorlugano
    • CommentTimeMar 4th 2010
     permalink
    Working on the thread. I really appreciate your help

    Thanks!.