ThemeShaper Forums » Thematic

[closed]

Add code between post title and post content

(14 posts)
  • Started 3 years ago by mrc2407
  • Latest reply from mrc2407
  • This topic is resolved
  1. mrc2407
    Member

    Hi!

    I modified The Events Calendar plugin so that I can use Thematic's templates, but now I want to put some code between the post title (under post meta) and the post content. So the structure would be like that:

    -Post title
    -Post meta
    -My code
    -Post content

    I tried this: add_action('thematic_singlepost', 'showEventInfo', 10);

    But if I put a 10 or lower, my code appears over the post title, and if I put 11 or higher then it appears after the content... And I want it in the middle :)

    Any idea?

    Thanks!

    Posted 3 years ago #
  2. mrc2407
    Member

    Anyone, please?

    Posted 3 years ago #
  3. <removed, sorry.>

    Posted 3 years ago #
  4. mrc2407... I'm no expert, but this helped me.

    In your child theme open functions.php add something like the following [by helga]:

    'if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name'=> 'Name Sidebar Widget',
    'id' => 'name-of-your-widget',
    'description' => 'This is where your header widgets go',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }

    function show_new_widget_area(){
    if (function_exists('dynamic_sidebar')){
    dynamic_sidebar('name-of-your-widget');
    }
    }
    add_action('thematic_extension','show_new_widget_area');'

    ...in the main theme folder, go to library > extensions > content-extensions.php

    experiment/find the right extension for you & replace it in the add_action line above.

    *Edit: might have spoken too soon... these just add above/below the post ...not in it. Most posts of this nature go unanswered, not sure what up.

    Posted 3 years ago #
  5. these are tough b/c there is no "hook" there for you to add a function to. instead you will have to filter the post content

    try something like:

    function add_code($post) {
    	if (is_single()){
    		$old_post = $post;
    		$post = "wow bacon!<br />";
    		$post .= $old_post;
    	}
    		return $post;
    		}
    add_filter ('thematic_post', 'add_code');

    this should add "wow bacon!" to the beginning of the content on every page that meets the is_single() condition.

    Posted 3 years ago #
  6. mrc2407
    Member

    @matius: that would create a dynamic sidebar, but as helgatheviking says, there's no hook to add it...

    @helgatheviking: thanks for the code! I'll try it ASAP! :)

    Posted 3 years ago #
  7. Yea I appreciate that helga - and mrc2407, hope you don't mind me asking this here but...

    would it be best for me to consider revising my design if I'd like to chop one post into 3 div/columns? I need to add sections in each post - one above the header, and one after the last element & display them in their own div floated left.

    ...and that it stay uniform between the index and single pages...

    Posted 3 years ago #
  8. mrc2407
    Member

    @helgatheviking: I've trie your code and it is exactly what I needed :) Thank you!

    Posted 3 years ago #
  9. @matius- i am not sure i follow. but if you are trying to add things to your $post then the code i have above will work... just wrap the 3 columns in div tags. of course, then you will need some CSS magic.

    Posted 3 years ago #
  10. Thanks Helga, actually doing pretty decent with just CSS at the moment... but what I was saying was your code works but only on a single post page (after clicking the title of the post)...

    maybe it's my css, will check.

    Posted 3 years ago #
  11. hmmm... well if you check my code there is definitely a conditional (if (is_single()) so it intentionally only applies to single posts. you can change the logic to suit your needs.

    Posted 3 years ago #
  12. gotchya, just that there's no is_post i've been scrambling to find what to use :p, but i think i have it.

    thx for your help-

    Posted 3 years ago #
  13. For the record, still not sure what to use in place of is_single (and it's probably easy but it's late). This post though is definitely getting me where I want to go in conjunction with CSS.

    http://themeshaper.com/customize-blog-posts-touching-theme-files/

    Posted 3 years ago #
  14. mrc2407
    Member

    The is_single conditional only gives "true" when the page you're viewing is a single post. If you want to use it everywhere, just take the conditional out:

    function add_code($post) {
    	$old_post = $post;
    	$post = "wow bacon!";
    	$post .= $old_post;
    	return $post;
    }
    add_filter ('thematic_post', 'add_code');

    This way, $post will always be filtered and changed.

    Then, looking at this thread you started, you could just try something like this:

    function add_code($post) {
    	$old_post = $post;
    	$post = "<div id='post-date'>" . the_time('l, F jS, Y') . "</div>";
    	$post .= "<div id='post-content'>";
    	$post .= $old_post;
    	$post .= "</div>";
    	$post .= "<div id='other-info'>blablabla</div>"
    	return $post;
    }
    add_filter ('thematic_post', 'add_code');

    Hope this helps :)

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.