WordPress.org

Ready to get started?Download WordPress

Forums

static text below category archives tag (10 posts)

  1. babelianquest
    Member
    Posted 1 year ago #

    Hi,
    I'm working on the Twenty Ten theme / WP 3.4.2 and I need to add a static text below the category archives title.

    Let me explain:
    if I click on one category (e.g. named "cats"), i'm landing on a page containing all articles linked with the "cats" category. Just below the title: "Category Archives: Cats", I'd like to add a quotation.

    For that purpose, I added a div block in the category.php file just after </h1>. After refreshing the page, it works, BUT the same quotation appears for any category and not only for the "cats" category.

    After some researches on google, i came accross this piece of php code, that i adapted:


    <?php $post = $wp_query->post;
    if (in_category('categ-1')) {
    include('category_templ1.php')):
    }
    elseif (in_category('categ-2')) {
    include('category_templ2.php'));
    }
    else{
    include{'categoy.php');
    }
    ?>

    I created two files: one per category with one different quotation on each. These files are located in the same directory as the category.php file which will remain the same (id est without the quotation).

    My question is: where should I put this? In the "function.php" file?

    Thanks in advance for you help

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Are you using a child theme?

  3. babelianquest
    Member
    Posted 1 year ago #

    I am, but i only put the "child" css file in the other directory (i called it 20-10-child): wp-content/themes/20-10-child/style.css.

    The two files category_templ1.php and category_templ2.php are still located along the other php files of the Twenty Ten Theme (wp-content/themes/twentyten).

    I did it so as to see them in the admin panel.

    Maybe that's the wrong method?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Yes - that's wrong. Your custom template files should be in the child theme's folder.

  5. babelianquest
    Member
    Posted 1 year ago #

    Ok, it's now fixed! The files are in the right folder.

    What should be done now with the php code to redirect the category page?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    Sorry? What code?

  7. babelianquest
    Member
    Posted 1 year ago #

    Well a code used to change the template of each category.

    I need to let a quotation appear below the "category archives" title which depends on the category selected.

    I found on the net this one (adapted for the context):


    <?php $post = $wp_query->post;
    if (in_category('categ-1')) {
    include('category_templ1.php')):
    }
    elseif (in_category('categ-2')) {
    include('category_templ2.php'));
    }
    else{
    include{'categoy.php');
    }
    ?>

    But i do not know where i should insert this? Inside function.php?

    Any help is appreciated !

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    Are you referring to categories or archives? What do these _templx files contain?

  9. babelianquest
    Member
    Posted 1 year ago #

    Let's imagine i'm clicking on one category, then i'm landing on a page with links to all articles related to this category.

    I'm referring to this kind of pages!

    And the _templ files contain almost the same content as the category.php file: i just added a <div> after the title, which includes a quotation.

    So i have one file per category, in the child theme folder

    <--Sorry for my lame english-->

  10. esmi
    Forum Moderator
    Posted 1 year ago #

    Then you don't need multiple category template files. Something like:

    <?php if( is_category( 'foo' ) $quote = '<div class="quote>[Quote A here ]</div>';
    elseif( is_category( 'bar' ) $quote = '<div class="quote>[Quote B here ]</div>';
    else $quote = '';
    echo $quote;?>

    in the main category.php template file should be enough.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags