Return to Support

Conditional Formating

Home Forums Graphene WordPress theme Support Conditional Formating

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2949
    Manasse
    Member

    Hey! As anything comes to an end, this’ll be one of the last threads I’m starting. Not that I don’t want to talk to you guys, but because I’m almost done setting up my Graphene WordPress Site. There’s just two more things though…

    I have a category.php in my child theme because of some sidebar issues, solved with help from mr. Khairul Syahir himself. So there’s some code in the child’s category.php. Basically this code says I want to get the header and that I want just one column and no sidebars. This is the code:

    <?php
    global $graphene_settings;
    $graphene_settings['column_mode'] = 'one-column';
    get_template_part('loop', 'category');

    ?>

    Although I like the titlebar (in original Graphene it is the blue bar), I don’t really like the text: “Category Archive: [name]”. So I’m thinking of a way to change this, but with conditions, because some categories are different then others…

    Anyway. I need to put this in the category.php and I guess this has to be done before the loop kicks in. (Right???)

    Well, what I came up with is this:

    <h1 class="page-title">
    <?php
    if (is_category(12, 13, 14, 15)) : printf(__('<span>%s</span>', 'graphene'), single_cat_title('', false));
    if (is_category(4,5,6)) : printf(__('<span>%s</span>’s Blog', 'graphene'), single_cat_title('', false));
    elseif (printf(__('Category Archive: <span>%s</span>’s Blog', 'graphene'), single_cat_title('', false))):
    ?>
    </h1>

    Next (problem no. 2) I want to have conditional descriptions. I guess again, I want to have this done before the loop kicks again (Am I right??)

    This is what my brain made:

    <?php /* The category description and The Conditional Category Description */

    if (is_category(4)) :
    ?><p>Hij heeft belooft alles in het Nederlands te doen, maar het zou best kunnen dat er wel eens wat Bosnisch doorheen komt, kortom Muco's!</p>

    <?php if (is_category(5)) :
    ?><p>Dit is de pagina van Emo Jaap. Als hij huilt, dan lees je het hier. En natuurlijk schrijft hij hier alles over zijn Bas</p>

    <?php if (is_category(6)) :
    ?><p>Dit is Dimitry's pagina. Hier kun je alles lezen over zijn leven als muzikant.</p>

    <?php if(is_category(12, 13, 14, 15)) :
    ?><p> Dit deel van de site is van jou! Hier vind je de %s. Heb je zelf ook iets voor ons? Laat het even weten, grote kans dat je het hier terug gaat vinden!</p>

    <?php
    $cat_desc = category_description();

    elseif($cat_desc) : ?>
    <div class="cat-desc">
    <?php echo $cat_desc; ?>
    </div>
    <?php endif;

    After this comes the loop and the get_footer:

    <?php
    /* Run the loop for the category page to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-category.php and that will be used instead.
    */
    get_template_part('loop', 'category');
    ?>
    <?php get_footer(); ?>

    Thought I would have some errors (and did get some) but now I get an error I just don’t understand…

    Parse error: syntax error, unexpected $end in /URL/wp-content/themes/graphene-child/category.php on line 59

    Found on some forums about PHP that this could mean i forgot a “;”, a “<?php”, or a “?>”

    Maybe I forgot something else or my coding’s just too stupid..

    Any suggestions (or the answer??)

    Cheers

    #22671
    Manasse
    Member

    Making progress: on the conditional format of category description. Made some functions where i wrote some descriptions.

    This is that part of the code. Haven’t tried it yet, but it seems to be good.

    <?php
    /* Conditional Category Descriptions*/

    $s_cat_desc = category_description();
    $s_cat_muco = category_muco ();
    $s_cat_jaap = category_jaap ();
    $s_cat_dimi = category_dimi ();
    $s_cat_fans = category_fans ();
    $id = is_category ();
    $ifans = array(12, 13, 14, 15);

    switch ($id)
    {
    ?><div class="cat-desc"><?php
    case $id == 4 :
    echo $s_cat_muco;
    break;
    case $id == 5 :
    echo $s_cat_jaap;
    break;
    case $id == 6
    echo $s_cat_dimi
    break;
    case $id == $ifans
    echo $s_cat_fans
    default :
    echo $cat_desc
    ?></div><?php
    }
    ?>

    #22672
    Manasse
    Member

    Ok. Trimmed it a bit, got rid of the functions. Now i get an error that I didn’t expected..

    $s_cat_desc = category_description();
    $id = is_category ();
    $ifans = array(12, 13, 14, 15);

    switch ($id)
    {
    case $id == 4 :
    echo 'First text';
    break ;
    case $id == 5 :
    echo 'Second text' ;
    break ;
    case $id == 6
    echo 'Third text';
    break ;
    case $id == $ifans
    echo 'Fourth text';
    break ;
    default :
    echo $cat_desc;

    If I go to category 6 i get this error: Parse error: syntax error, unexpected T_ECHO in /URL/graphene-child/category.php on line 14

    Does it mean it can’t show “Third text” while I’m on category 6??? I don’t understand…

    Maybe I’ll just put in descriptions in the Admins Category Menu…

    #22673
    Prasanna SP
    Member

    There is a missing ?> tag in the third code you’ve entered in your first post, right after the <?php endif; (At the end of the code). Fix it.

    #22674
    Manasse
    Member

    Yeah I changed it already. I’m filling in descriptions in the admin’s category menu. It’s the easiest way to do it. Still I don’t understand why it gave an unexpected ‘echo’ error while being on the right category… Must get a book on PHP i guess (and read it..).

    Anyway, that part is solved, now on to the last part;

    Same with that “band” or “Bio” issue… I have to rename the category, and then change the Navigation Label in the custom menu thing… BUT! That leaves me with “Category Archive:” which is written in the core-file (Graphene’s category.php). So I must find a way to change it in my Child’s theme..

    this is original:

    <h1 class="page-title">
    <?php
    printf(__('Category Archive: <span>%s</span>', 'graphene'), single_cat_title('', false));
    ?>
    </h1>

    This is what I placed in my child’s theme:

    <h1 class="page-title">
    <?php
    printf(__('<span>%s</span>', 'graphene'), single_cat_title('', false));

    ?>
    </h1>

    But doing that just doesn’t change it, so I looked at what the Graphene’s function.php says about the Archive:

    // Archive
    $grad_top = $graphene_settings['bg_archive_left'];
    $grad_bottom = $graphene_settings['bg_archive_right'];
    if ( $grad_bottom != $graphene_defaults['bg_archive_left'] || $grad_top != $graphene_defaults['bg_archive_right']) {$style .= '.page-title {
    -pie-background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ' );
    background: ' . $grad_top . ';
    background: -moz-linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ' );
    background: -webkit-linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ' );
    background: linear-gradient(left top, ' . $grad_top . ', ' . $grad_bottom . ' );
    }';}
    if ( $graphene_settings['bg_archive_label'] != $graphene_defaults['bg_archive_label']) {$style .= '.page-title{color:'.$graphene_settings['bg_archive_label'].';}';}
    if ( $graphene_settings['bg_archive_label'] != $graphene_defaults['bg_archive_text']) {$style .= '.page-title span{color:'.$graphene_settings['bg_archive_text'].';}';}
    if ( $graphene_settings['bg_archive_textshadow'] != $graphene_defaults['bg_archive_textshadow']) {$style .= '.page-title{text-shadow: 0 -1px 0 '.$graphene_settings['bg_archive_textshadow'].';}';}

    And now I’m lost… Hahaha. I think I have to add a function to my child’s function.php or declare a $ in the child’s archive.php but I don’t now which one is giving it the text “Category Archive:”

    Anyone???

    #22675
    Manasse
    Member

    Nevermind;

    found this:

    function graphene_filter_gettext( $translated, $original, $domain ) {
    $strings = array(
    'Category Archive: <span>%s</span>' => '<span>%s</span>',
    );
    if ( ! empty( $strings[$original] ) ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
    }
    return $translated;
    }
    add_filter( 'gettext', 'graphene_filter_gettext', 10, 3 );

    That should do the trick 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.