• Resolved sallywp

    (@sallywp)


    Hello,

    I’m currently using the below code snippet so I can add recent posts as well as custom content to my home page. I would like to include custom content before my recent posts. When I set it the hook to “after_header,” the custom content appears as a full-width page and excludes my sidebar. If I set it “before_content,” the content displays before every single one of my recent posts.

    Is there any way to set it so I can have custom content before my recent posts but still integrate the content according to the default layout (right sidebar)?

    My site is https://passportandplates.com

    Thanks in advance for your help!

    CODE:

    add_filter( ‘tc_default_widgets’ , ‘add_featured_page_widget’ );
    function add_featured_page_widget( $defaults ) {
    $defaults[‘fp_widgets’] = array(
    ‘name’ => __( ‘Featured Pages Widget’ , ‘customizr’ ),
    ‘description’ => __( ‘Above the featured pages area on home’ , ‘customizr’ )
    );
    return $defaults;
    }

    add_action(‘__after_header’ , ‘display_my_fp_widget’);
    function display_my_fp_widget() {
    dynamic_sidebar(‘fp_widgets’);
    }

Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter sallywp

    (@sallywp)

    Hi,

    Apologies, it was set to private. It should work now. Here it is again: https://picasaweb.google.com/109402086603161483632/January82016?authkey=Gv1sRgCM_cseDF7N7K_AE#6237597911613668898

    It is not clear what is FP Widget area. You have not enabled Featured Pages. So, where are you trying to add content? Or is this what you wanted to do first with that hook? I am slightly lost

    Thread Starter sallywp

    (@sallywp)

    On the picture I provided for you:

    I have the CSS set according to this:

    add_action(‘__before_content’ , ‘display_my_fp_widget’);
    function display_my_fp_widget() {
    if ( ! tc__f(‘__is_home’) )
    return;
    global $wp_query;
    if ($wp_query->current_post == 0) {
    dynamic_sidebar(‘fp_widgets’);
    }
    }

    The picture on the top left corner is actually the thumbnail that corresponds to the text at the bottom {the foodie guide to Turkish cuisine). That text is the title of the latest post because I have the home page set to latest posts.

    The are that says “where I’ve been” and the map underneath it is a featured pages widget. For some reason, anytime I try to add content to the FP widget, the content shows up between the title and the thumbnail of the latest post.

    What I would like is for the FP widget to stretch so that the all the latest posts (including the title and thumbnail) is below anything I insert into the FP widget. I imagine the issue has to do with customizing the widget size. I’m just not sure how to do that.

    Does that make sense?

    Oh yes.
    Then probably, you can try to hook into this filter. Something like this. I have added some text in place of the map.

    add_filter('tc_post_list_content' , 'display_my_fp_widget');
    function display_my_fp_widget($content) {
    if ( ! tc__f('__is_home') )
    return;
    global $wp_query;
    if ($wp_query->current_post == 0) {
    return "The pioneers of the teaching of science imagined that its
        introduction into education would remove the conventionality,
        artificiality, and backward-lookingness which were characteristic;
        of classical studies, but they were gravely disappointed. So, too, in
        their time had the humanists thought that the study of the classical
        authors in the original would banish at once the dull pedantry and
        superstition of mediaeval scholasticism. The professional
        schoolmaster was a match for both of them, and has almost
        managed to make the understanding of chemical reactions as dull
        and as dogmatic an affair as the reading of Virgil's Aeneid.".$content;
    } 
    
    return $content;
    
    }
    Thread Starter sallywp

    (@sallywp)

    Hi,

    I will try this out, thanks! But what do I put instead of all that text if I want to use the featured pages widget to add content?

    Oh, you are right.
    This might probably give what you want. Hook into __before_article action.

    add_action('__before_article' , 'display_my_fp_widget');
    function display_my_fp_widget() {
    if ( ! tc__f('__is_home') )
    return;
    global $wp_query;
    if ($wp_query->current_post == 0) {
    dynamic_sidebar('fp_widgets');
    }
    }
    Thread Starter sallywp

    (@sallywp)

    When you say hook into _before_article action, what does that mean, exactly? I just copied and pasted what’s in the gray area into my php file and it caused a server error.

    I mean, instead of __before_content, use __before_article. Otherwise, the code given (before I proposed the filter option with text) is the same.

    Thread Starter sallywp

    (@sallywp)

    Got it. That worked. Thanks so much for your help and patience with all of this!

    Glad that it worked for you Sally. ??

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Featured Pages Widget: "After Content" Error’ is closed to new replies.