• Resolved codecottage

    (@codecottage)


    I’m using WP for a traditional website and have written an events page using a custom query. The query pulls out all pages that have a “calendar” custom field providing me with event titles and event dates. I want to format the output like this:

    March 23, 2008
    Town Hall Meeting

    The text would be plain and not bolded. There would be no more tag as in my current output.

    At this time, I’m making due with the output of “the_content” function but can’t figure out how to modify the output to my liking.

    The page is:
    http://test2.handcraftedsites.com/calendar.php

    Here’s my code:

    $querystr ="
      SELECT $wpdb->posts.* FROM $wpdb->posts
      LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
      WHERE $wpdb->postmeta.meta_key = 'calendar'
      AND $wpdb->posts.post_status = 'publish'
      AND $wpdb->postmeta.meta_value = 'yes'
      ORDER BY $wpdb->posts.menu_order ASC";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
    
    //in here is some year and month formatting but this is
    //simply for displaying year and month titles and doesn't
    //have anything to do with displaying each page.
    
    setup_postdata($post); ?>
    
    <?php the_title(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
             <?php the_content() ?></a>
     // more month and year code here
      <?php endforeach; ?>
      <?php else : ?>
        <strong>Please check back for calendar listings!</strong>
    <?php endif; ?>

    I guess I need to be able to get into the “guts” of the “the_content” function unless there is code provided already that exposes the functionality I need.

    Thank you for your help!

    Codecottage

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter codecottage

    (@codecottage)

    I’ve been doing some research in the past several hours since I posted and wonder if I should abandon trying to get at the internals of the “the_content” function and try using custom fields exclusively? Would that be easier and allow me more flexibility?

    Thank you,

    Codecottage

    Thread Starter codecottage

    (@codecottage)

    I did a Google search and found the codex page explaining how to pass parameters to the “the_content” function. I was relying on WordPress’s search function which had come up empty. I forgot that Google is more efficient. I was able to get close to the formatting I wanted with this code:

    setup_postdata($post); ?>
    
    <strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
      <?php the_content(the_title('', '', true)); ?></a>
    </strong>  <?php endforeach; ?>
      <?php else : ?>
        <strong>Please check back for calendar listings!</strong>
    <?php endif; ?>

    The information is at:

    http://codex.wordpress.org/Template_Tags/the_content

    Codecottage

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Wow. Okay, Geez, where to begin.

    1. Why are you running your own SQL? That seems like massive overkill. WordPress has functions to do all that for you.

    2. What is it that you want to change about the output of the_content() specifically? You can use a filter on it if needed, but it’s hard to help without specific information about what you are trying to do.

    3. the_content(the_title('', '', true)); really doesn’t make any sense at all. What the heck are you trying to do with this code?

    In short, tell us what you have and what you want and we’ll tell you how to get there.

    As near as I can figure, you have a bunch of posts of events. You’re looping through them and displaying their dates and titles. When clicked on, each one takes you to that posts page. Close? If so, why are you using the_content() at all? Use just the_title(). You don’t *have* to use the content, especially when you don’t want to display the content.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Modify “the_content” Function’s formatting’ is closed to new replies.