Afterpost widget for different category

Community Forums Forums Design Tips and Tricks Afterpost widget for different category

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  Victor 1 year ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #50386

    Victor
    Participant
    Post count: 13

    I am using the after post widget. I would like to be able to display different content depending on the post category.

    Example: Post category 1 displays content 1
    Post category 2 displays content 2

    Thanks in advance

    #50390

    braddalton
    Participant
    Post count: 8875

    You can do this at least 2 ways.

    1. Using a custom field
    2. Creating multiple widgets.

    https://gist.github.com/braddalton/5985827


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #50411

    Victor
    Participant
    Post count: 13

    Brad

    Thanks very much. Could you please clarify.

    I can cut and paste code but this is a bit confusing for me.

    The code above would create a new after post widget for category. Correct?

    Place this at the bottom of my child theme PHP file?

    Cheers

    This is the child theme php showing my existing after post widget

    http://screencast.com/t/vJeXd1slH

    #50412

    braddalton
    Participant
    Post count: 8875

    Victor

    Please copy the PHP code from the view raw link and paste it at the end of your child themes functions.php file.

    You will need to edit this part of the code with the slug or category i.d for one category.
    [php]
    if ( in_category(007)
    [/php]

    or

    [php]
    if ( in_category(web-design)
    [/php]

    In the above example, 007 is the category i.d. and web-design is the category slug.

    This will create a widget which displays content after all posts in that specific category.

    Duplicate the solution for each category or use the other option which is to create a custom field.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #50426

    Victor
    Participant
    Post count: 13

    Ok that worked great

    But I must be missing something to duplicate the widget for another category.

    I tried duplicating it and it created an error.

    Do I have to rename or something?

    Thanks

    #50436

    braddalton
    Participant
    Post count: 8875

    Here’s an example:

    https://gist.github.com/braddalton/5987428


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #50453

    Victor
    Participant
    Post count: 13

    ok

    Thanks

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

You must be logged in to reply to this topic.