WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page of posts Twenty Twelve (13 posts)

  1. ameliegale
    Member
    Posted 1 year ago #

    Hi there
    We have created a custom template, however does anyone know what the code would be for the twentytwelve theme to create a A Page of Posts?

    The existing help on pages gives the code but for twentyeleven http://codex.wordpress.org/Pages#A_Page_of_Posts

    Any help greatly received!!!

    R
    Amelie
    Blog still...Work in Progress

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    start by creating a child theme http://codex.wordpress.org/Child_Themes if you haven't done already.

    for the 'page of posts' code, see my latest article:
    http://www.transformationpowertools.com/wordpress/page-of-posts-template-for-twenty-twelve

  3. ameliegale
    Member
    Posted 1 year ago #

    Thanks for prompt response Achymyth!

    The child theme was there.

    Created a new folder pageofposts.php in child theme with code as website. Only changed category.

    Created new page "Trial" and selected page of posts template.

    Page does not show, gives server error.

    Any ideas?

    R

    Amelie

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    apologies - the code got somehow partialy parsed in my site;

    here is the (hopefully working) 'page of posts' code in a pastebin:

    http://pastebin.com/yeGnRkbR

  5. ameliegale
    Member
    Posted 1 year ago #

    Amazingly quick reply Alchymyth!

    All working now on http://www.ameliegale.com/offers/

    Will go trough som eof your tips as they migght save some heartache http://www.transformationpowertools.com/wordpress/tips

    R
    Amelie
    Still work in Progress

  6. ameliegale
    Member
    Posted 1 year ago #

    Next step, is it possible to NOT show Posts from the offers category on main page?
    http://www.ameliegale.com/

    R
    Amelie

  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Example:_Exclude_categories_on_your_main_page

    in functions.php of your child theme, add:

    function main_page_exclude_category_offers( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
    	$cat_offers = get_term_by('slug','offers','category');
    //exclude posts of the category 'offers' from the main page//
            $query->set( 'cat', '-'.$cat_offers->term_id );
        }
    }
    add_action('pre_get_posts','main_page_exclude_category_offers');

    http://codex.wordpress.org/Function_Reference/get_term_by

  8. ameliegale
    Member
    Posted 1 year ago #

    Marvellous!

    Thanks very much

    R

    Amelie

  9. mazumi
    Member
    Posted 1 year ago #

    This thread was a massive help, thanks so much!

    Is there a way to display the page content in addition to the posts? I'm trying to create a page template that will display the contents of the page next to the list of posts.

  10. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    @mazumi

    please start a new topic - your question is considerably different from the original topic.

  11. ameliegale
    Member
    Posted 1 year ago #

    That was going to be my next question, please can you let me know the answer Mazumi/Alchymyth.

    R
    Amelie

  12. brookebot
    Member
    Posted 10 months ago #

    @alchymyth

    When I excluded 1 category this worked great:

    /* Exclude category'viewer-video-requests' from the Blog Page */
    function main_page_exclude_category_offers( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
    	$cat_offers = get_term_by('slug','viewer-video-requests','category');
            $query->set( 'cat', '-'.$cat_offers->term_id );
        }
    }
    add_action('pre_get_posts','main_page_exclude_category_offers');

    Now, I want to exclude 2 categories & tried this, but it didn't work:

    /* Exclude category'viewer-video-requests' from the Blog Page */
    function main_page_exclude_category_offers( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
    	$cat_offers = get_term_by('slug','viewer-video-requests','category');
            $query->set( 'cat', '-'.$cat_offers->term_id );
        }
        else if ( $query->is_home() && $query->is_main_query() ) {
    	$cat_offers = get_term_by('slug','closed-viewer-video-requests','category');
            $query->set( 'cat', '-'.$cat_offers->term_id );
        }
    }
    add_action('pre_get_posts','main_page_exclude_category_offers');

    I'm a PHP dummy. Can anyone offer any help? I need to exclude 2 categories. Thank you!!!

  13. alchymyth
    The Sweeper & Moderator
    Posted 10 months ago #

    @brookebot

    please start a new topic in the theme's support section http://wordpress.org/support/theme/twentytwelve (scroll down to the input form)

Topic Closed

This topic has been closed to new replies.

About this Topic