Forum Replies Created

Viewing 15 replies - 271 through 285 (of 2,107 total)
  • The problem here is that a post can belong to a number of categories, like Sport and Basketball, if your posts have more than one category then you may have problems, if the first category is fine then something like get the first category{slug} from the post and use this as the post class:

    <?php
    /* Gets all the categories for the post as an ARRAY */
    $category = get_the_category();
    /* if we have categories get the first slug {nice_name} */
    $class = ($category) ? $category[0]->slug : '';
    ?>

    Now we add our Post_Class() name Category = “Basketball Teams” {slug} would be lowercase and no spaces basketball-teams, this code would be in the content or loop area:

    <article id="post-<?php the_ID(); ?>" <?php post_class( $class ); ?>>

    Then in the style.css you would create a style

    .basketball-teams {
       background: #e0e0e0;
    }

    If this you are using several categories per post, then you could think about ( custom field, post meta boxes, or adding a category dropdown to be selected on each post, then use get post meta to set or return the category for style class.

    <?php
    /* Has a class name been set in the posts meta */
    $class = get_post_meta( get_the_id(), 'css_class' , true );
    if(! $class ) {
    	/* Gets all the categories for the post as an array */
    	$categories = get_the_category();
    	$class = ($categories) ? $category[0]->slug : '';
    }
    ?>

    .
    ALL CODE HAS NOT BEEN TESTED

    HTH

    David

    I erase all the contents from the CSS I just copied and add the description lines as such

    You need the @import line to get the parents styles:

    * =Do not add styles before the Stylesheet import
    -------------------------------------------------------------- */
    @import url('../twentyeleven/style.css');
    
    /* =Add our custom style changes below this line
    -------------------------------------------------------------- */

    so it will apply the code from the content-staff.php to the template-staff.php correct? but why is that important?.

    That part is only required or important where you need to change the layout or code in the content (loop), your solution did not need it, so it was there for others reading this topic.

    post_class()
    Yours was one of two topics I answered, the other changed the post_class() in the loop based on a $counter, so I am writing an article over the weekend using post_class() and code to create four layouts:
    1. page: the example above page post_class()
    2. content: a magazine layout two posts above three repeating
    3. content: a thumbnail switch where the thumbnail is floated left(odd) right(even)
    4. content: with seven colored post backgrounds repeating

    I will post a link back here when done so you can have a look at what else can be done with post_class

    HTH

    David

    On the right change the staus to [ resolved [^], it will stay in the forum so other might find it in the search and resolve their issues.

    HTH

    David

    Or create a shortcode function!

    Paste this into functions.php (child theme)

    http://pastebin.com/1wAXetH6

    In a post or page just type [guestbook]

    HTH

    David

    Code snippet for content.php in a twenty eleven child theme!

    <?php
    	global $wp_query;
    	$divisor = 6;
    	$counter = ($wp_query->current_post + 1) % $divisor;
    	$class = $counter ? 'recent-' .$counter : 'recent-' .$divisor;
    ?>
    
       <article id="post-<?php the_ID(); ?>" <?php post_class( $class ); ?>>

    Based on your posts per page $wp_query->current_post will start at zero, so ten posts returns 0 – 9

    Set the $divisor to the number of styles, you want 6 others might want two for columns.

    % $divisor; will return 0 if the counter is divisable.
    So we get 1, 2, 3, 4, 5, 0, 1, 2, 3, 4

    $class = $counter ? 'recent-' .$counter : 'recent-' .$divisor;

    This will concatenate 'recent-' and $counter if $counter != 0, if $counter == 0 it will concatenate 'recent-' and $divisor

    recent-1, recent-2, recent-3, recent-4, recent-5 and recent-6

    Last we set our class with the post class post_class( $class );
    WordPress will append our class to the post classes!

    <article id="post-1" class="post-1 post type-post status-publish format-standard hentry category-uncategorized recent-1">

    Then in the style.css

    .recent-1 {
    
    }
    
    .recent-2 {
    }

    Pretty Neat!

    HTH

    david

    The Appearance > Header > Uploded Header Images, details are stored in the wp-post and wp-post-meta table, these are used by wordPress, they are theme specific, so your child theme will not show uploded header images from the parent.

    Upgrading the parent will not affect your child theme code, uploaded images and headers, howevere changing the theme to parent or another child theme will not transfer the headers.

    HTH

    David

    Use get_post_meta($post_id, $key , $single )

    <img class="film" src="<?php echo get_post_meta( $post_object->ID, 'img_actor', true); ?>" alt="" />

    HTH

    David

    Just a footnote to this, which could help other people searching the topics, we can create a Page Template as described above, then in the page code look for the Post Class.

    Lets say we wanted a page template for ‘Our Staff’, or a page to dispaly a custom content loop, in a custom layout, we open page.php and save this as template-staff.php

    Open the template-staff.php file and add our template code:

    <?php
    /*
    Template Name: Our Staff
    */

    Now we find the Body Class, in twenty eleven it would be this line

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    We can add a custom class to this page template.

    <article id="post-<?php the_ID(); ?>" <?php post_class('our-staff'); ?>>

    Now our-staff will be added as a class for our page template!

    In style.css we can add our styles, something like.

    .our-staff {
       background: #e0e0e0;
       border solid 1px #ccc;
    }

    Apply the Template to our page, add the content and publish.

    If we can code a little and we are using custom post types or a category for our staff, for the content or loop, in twenty eleven we would create a file content-staff.php with the custom loop, then in the page template find.

    <?php get_template_part( 'content', 'page' ); ?>

    Change this to:

    <?php get_template_part( 'content', 'staff' ); ?>

    That’s it!

    HTH

    David

    EDITED looks like the answer ^^^^

    I just tested this and it works, just remove the spaces after the &.

    This is a HTML Degree & #176; or this & deg;

    This is a HTML Degree ° or this °

    Paste your bit of code so we can see, if this is not resolved.

    HTH

    David

    I can see it is now working with the 560px image width, so it was not what I suggested, what was the problem?

    Regards

    David

    Try an echo!

    ="<?php echo the_field('img'); ?>"

    HTH

    David

    A quick look at the website images, the linked images are all 630px wide, but the studio shot full size ( /thisISsilly.jpg ) is only 560px wide.

    From the pastebin code!

    // checking if the file size is larger than the target size
    // if it is smaller or the same size, stop right here and return

    At a guess I would think that function looks for an image at least 630px wide, the main image needs to be at least 631px wide so it can be sized?

    Replace the image with a larger one and see if it still errors.

    HTH

    David

    If they are custom post types why not just use the featured image for each post, this way the images are cropped and sized by WordPress.

    Then you can just return the get_post_thumbnail() in the actors loop?

    HTH

    David

    Can you put the code in the file thshpr_image_resize.php up on http://pastebin.com and paste a link back to this topic.

    Also if you know the code that is calling the function, paste that in a second pastebin.

    David

Viewing 15 replies - 271 through 285 (of 2,107 total)