WordPress.org

Forums

A little query help please. (3 posts)

  1. Roy
    Member
    Posted 1 year ago #

    Argh, me and PHP. Could somebody give me a hand?

    I'm querying a custom post type in a widget using the following query:

    <?php
        query_posts(array(
            'post_type' => 'blog',
            'showposts' => 10
        ) );
    ?>
    <?php while (have_posts()) : the_post(); ?>
            <P STYLE="font-size: 14px; font-weight: bold;"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></font>
    <p><?php echo get_the_content(); ?></p>
    <?php endwhile;?>

    So far so good, were it not that I crop the content using the more tag and that does not work on single posts and pages. So I figured I'd just add a little if-statement, but it doesn't do the trick.

    I've got this:

    <?php
        query_posts(array(
            'post_type' => 'blog',
            'showposts' => 10
        ) );
    ?>
    <?php while (have_posts()) : the_post(); ?>
            <P STYLE="font-size: 14px; font-weight: bold;"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></font>
    <p><?php if ( is_single() ) {
    	echo get_the_excerpt();
    } else {
    	echo get_the_content();
    } ?></p>
    <?php endwhile;?>

    I have tried a few variations, like without the echo_get, but the result remains the same: full blog-posts on single posts.

    Any help is appreciated.

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    try to apply what is described in http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages

    btw:
    please do not use query_posts() for secondary queries; use WP_Query() instead;
    http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts

    http://codex.wordpress.org/Class_Reference/WP_Query

    also, 'showposts' is deprecated - use 'posts_per_page'

  3. Roy
    Member
    Posted 1 year ago #

    When I use 'wp_query' the widget breaks and all widgets that come after it (in both sidebars).

    I've been looking a bit further and am now looking at Widget Logic which relatively easily allows to me to have more differences between single post and the rest.

    Thank you for you answer though.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.