Forums

[resolved] the_content filter issues (3 posts)

  1. cornetjr
    Member
    Posted 2 years ago #

    I am trying to use the_content tag in conjunction with the <!--main--> tag in post to extract certain amount of content from a post. The code below works fine, the main tag is respected and images are not shown:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1>" rel="bookmark"><?php the_title(); ?></h1>
    <img style="float:left;margin:0px 10px 10px 0px;" src="<?php echo get_post_meta($post->ID, "Blog", true); ?>" alt="alt text" />

    <div class="blog">
    <?php
    ob_start();

    the_content("... continue reading " .the_title('', '', false));

    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());

    ob_end_clean();

    echo $postOutput;

    ?>

    The problem is that when I want to run a query on the post to display postings from certain categories, the post does not recognize the <!--main--> tag and displays the entire text of the post. Images are not displayed below as desired.

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=10&paged=$page"); while ( have_posts() ) : the_post(); ?>

    <h1>" rel="bookmark"><?php the_title(); ?></h1>

    <img style="float:left;margin:0px 10px 10px 0px;" src="<?php echo get_post_meta($post->ID, "Blog", true); ?>" alt="alt text" width="400" height="251"/>

    <div class="blog">
    <?php
    ob_start();

    the_content("... continue reading " .the_title('', '', false));

    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());

    ob_end_clean();

    echo $postOutput;

    ?>

  2. cornetjr
    Member
    Posted 2 years ago #

    I mean the <!--more--> tag, sorry.

  3. cornetjr
    Member
    Posted 2 years ago #

    For some reason, even though I was not on the homepage I had to use this code:

    <?php
    global $more;
    $more = 0;
    ?>

    It appears that the more tag is on by default on the homepage and off on all other pages, despite the reference below:

    http://codex.wordpress.org/Customizing_the_Read_More

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.