WordPress.org

Ready to get started?Download WordPress

Forums

Modifying a Template, PHP help? (8 posts)

  1. novice21
    Member
    Posted 7 years ago #

    Hey guys!

    A member in my last topic refereed me to this template to get me started on viewing my categories in a specific way on the index page.

    I need to modify the code in the template so that I can provide alternate div wrappers around the post divs, unfortunately, this needs a little more php handling than I can manage.

    I figure an if statement would work, IF categoryid=1 then use this, if its not, use default. But I have no idea how to nest it or how to target the category I want it to check for, can anyone with php expertise help me out?

    If you can help me fix this, it'll make my day, hey I'll even help you with graphics to make this worthwhile.

    The Full Template Code.
    The snippet that needs editing:

    <?php
    /* post loop for each category listing */
       foreach($posts as $post) :
       the_post();
       $category = get_the_category();
    // if post is in correct category
       if($current_cat == $category[0]->cat_ID) : ?>
    <div class="post" id="post-<?php the_ID(); ?>">
       <div class="entry"><?php the_content(); ?></div>
    </div>
    <?php
                endif; // end 'if post in correct category'
            endforeach; // end post loop
    
            rewind_posts(); // reset loop for next category
        endforeach; // end 'display by category' loop
    ?>
  2. novice21
    Member
    Posted 7 years ago #

    where would be the best place to go to hire someone to do something like this?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    First, describing what it is that you're actually trying to do might get better responses. I read your post and the associated code half a dozen times, but still can't understand what it is that you actually want it to do.

    As for hiring somebody, the general place to look is the wp-pro mailing list: http://lists.automattic.com/mailman/listinfo/wp-pro

  4. Bodhipaksa
    Member
    Posted 7 years ago #

    Sounds like you want to put a different div around the post depending on what category it is? it would be good to know exactly why so that people can tell you whether that's the best way to achieve what you want to do.

    But ... a few weeks ago I crafted my first conditional statement that allows for different background images in the headers over different blog categories, and I think that code could easily be modified to do what you want to do. The post explaining what i did is at http://wordpress.org/support/topic/108768

    I think all you'd have to do is to change the bit that says h3 class="entrytitle so that it referred to a div rather than an h3 tag and change "entrytitle" to match the class you want to use. You'd probably also want to use "id" instead of "class." And all of that code would replace the opening "div" tag that you're putting around the posts. You also have to set up the styles in your stylesheet, of course.

    I'd be happy to answer questions about how this works -- it's simpler than it looks.

  5. novice21
    Member
    Posted 7 years ago #

    Sorry guys, got carried away with exams so I couldn’t check my post sooner, wish I did!

    What the template basically does is output the categories in groups, right?

    That’s perfect, except that my different categories must be displayed differently.

    This is because I have a category called Art, another called Photography and the last one is Post.

    I’m going to use the template for my index page, it’s going to display the excerpts for my categories, so when you hit my front page you’ll see;

    Art
    [thumb] [thumb] [thumb]

    Photo
    [thumb] [thumb] [thumb]

    Posts
    [title] – post snippet
    [title] – post snippet
    [title] – post snippet

    (where [thumb] and [title] link to the original post)

    To achieve the above result, I have to call different things depending on the category displayed, does that make more sense? I might add a fourth category that needs a different display style all together, so I wish the solution is scalable and not limited to just outputting two or three different styles per category.

    I hope this makes it much clearer. Sorry about that.

  6. Bodhipaksa
    Member
    Posted 7 years ago #

    That's a *totally* different question from the first one! And I have to say I have no experience of photoblogs so I can't be of help.

    Presumably you'll be using some kind of plugin, and until you tell people what that is I can't imagine you're going to get much help from the forum.

  7. novice21
    Member
    Posted 7 years ago #

    I'm not really looking to add more plugins, heh. I'm managing pretty good so far, my only tummble is with displaying a dynamic index page instead of just the most recent 10 in my categories.

    I'm pretty sure I can do it with this template code, I only need to figure out how provide alternate viewing styles for each category. erk. who knows, maybe it is really tough?

  8. charle97
    Member
    Posted 7 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic