WordPress.org

Ready to get started?Download WordPress

Forums

Customise posts within a category (8 posts)

  1. jimmy1234678
    Member
    Posted 2 years ago #

    Okay so I've created a category-news.php file. This is okay, I can edit this category page how I want it.

    Now how do I edit posts that are assigned this category? I've tried creating the following;
    - post-category-news.php
    - post-news.php
    - post-categorynews.php

    But none seem to work. Maybe I'm going about this the wrong way, would be great if someone could point me in the right direction. Tired of trying to do it and I'm getting nowhere quick.

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    Are you talking about the single post?

    Twenty Eleven: the single post is rendered in single.php and content-single.php, as you have not said what theme you are using it is hard to help.

    A single post could belong to a number of categories, news,sport,tennis, so it might not work the way you want it to, unless you take the first category:

    single.php (outside the loop)

    <?php
    global $post;
    $category = get_the_category( $post->ID );
    $class = isset($category[0]) ? $category[0]->cat_name : '';
    ?>

    Then use this:

    body_class( $class )

    content-single.php (inside the loop)

    <?php
    $category = get_the_category();
    $class = isset($category[0]) ? $category[0]->cat_name : '';
    ?>

    Then use this:

    post_class( $class )

    Then in syle.css add the category styles

    .news .entry-title a {
        color: #444444;
    }
    .weather .entry-title a {
        color: #CCCCCC;
    }

    HTH

    David

  3. jimmy1234678
    Member
    Posted 2 years ago #

    I'm using a theme called techfront. My site is http://gotmixtapes.org.

    Basically I want to be able to display all my mixtapes on the hot mixtape page and then display any news/blog articles on the news pages.

    I thought the best way to do this would be to create 2 category pages, then simply assign a post to either category to place it on a certain page. I'm not fussed about the front page displaying everything, I'm pretty happy with it this way.

    The main thing I would like to change is the "Get It" button text. Obviously this applies to the mixtape post, however on the news posts I would like to alter this.

    Hope this makes sense!?

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    The main thing I would like to change is the "Get It" button text. Obviously this applies to the mixtape post, however on the news posts I would like to alter this.

    The text GET IT! for this button is set in the theme options, it will change it globally.

    We need to change it just for the news page?
    the category-news.php you created calls the template part:

    get_template_part('post', 'category');

    Change this to:

    get_template_part('post', 'news');

    The file post-news.php does not exist so it will use post.php, you will need to create it, open the file post.php and save it as post-news.php

    Find these lines:

    <div class="readmore">
                <a href="<?php the_permalink(); ?>#more-<?php the_ID(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php $theme->option('read_more'); ?></a>

    Replace this part:

    <?php $theme->option('read_more'); ?>

    With:

    <?php echo __( 'Read More!', 'themater' ); ?>

    Now the news category page will say Read More!

    HTH

    David

  5. jimmy1234678
    Member
    Posted 2 years ago #

    Cheers for the help so far David.

    I've tried implementing what you said, but nothings changed? Pretty sure I did it all right, so not sure what's up?

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    If you are using a cache plugin clear the cached pages.

    Put a screen echo in both the files somewhere and see if they are loading!

    If not review the code above!

    <?php echo 'This is the category-news.php file!' ; ?>
    <?php echo 'This is the post-news.php file!' ; ?>

    HTH

    David

  7. jimmy1234678
    Member
    Posted 2 years ago #

    Right it has worked on the 'news' category page fine! :) But on the home page in my post feed it still has the 'get it' text.

    Is there anyway of removing these posts that are assigned the 'news' category from the main post feed. So that only the mixtape posts show on the main page and the mixtape page, whilst the 'news' posts show only on the news page.

    Thanks so much for all your help so far David!

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    The theme supports custom menus, do you need the news mixed in with the mixtapes, it looks like you are only using a single category?

    If not then create a top level category assign all the mix tapes to that category.

    Make the home page the parent category and leave the news on its own menu item.

    I think you are already using custom menus, if not go to Admin > Appearance > Menus

    Create two menus and assign them in the Theme Locations box

    Example:

    HTH

    David

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.