WordPress.org

Forums

Display Posts Shortcode
[resolved] Request: Control Content Length and Title Link (5 posts)

  1. ZaLiTHkA
    Member
    Posted 2 years ago #

    So, I've got a site with two custom post types, but they need to be listed differently. I've tried about 6 different plugins for this, and this one comes the closest to what I need.

    One custom post type (workshops) needs to display the title without a link and with full content, while the other (media) needs to display the title with a link and only the excerpt..

    This snippet modifies the 'include_excerpt' parameter to use get_the_content() instead of get_the_excerpt(), which is helpful but not quite what I need. Is it possible to add a new parameter to the shortcode called something like "include_content"?

    Also, is it possible to disable the title link for the displayed posts using a shortcode parameter?

    This is rather urgent, I've been fighting with this for about 2 days now, but I still haven't found a viable solution.

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. ZaLiTHkA
    Member
    Posted 2 years ago #

    Ok, looking through the source for the plugin, I see it does actually have an 'include_content' parameter that uses get_the_content()... I'm sure I did try that option in the shortcode and it didn't work for me. I'll check this again just now.

    For the title link, I've modified the plugin code as mentioned below.

    New entry in the $atts array:

    'title_link' => true,

    Then this in the next section:

    $title_link = (bool)$atts['title_link'];

    And lastly, I wrapped the loop's title output in an if() statement:

    if ( $title_link ) {
    	$title = '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
    } else {
    	$title = '<span class="title">' . get_the_title() . '</span>';
    }

    Bill, unfortunately I haven't fixed my test WP install on my webserver and I'm not near my main dev machine at the moment, so before I go install this on a client's website... This won't break anything in your plugin, will it? I only had time to skim through the code, I haven't been able to read through all functions thoroughly yet.

  3. ZaLiTHkA
    Member
    Posted 2 years ago #

    Ok, weird.. I decided to try edit the plugin file through the WP editor directly, I altered it slightly to rather use 'post_title_link' instead of 'title_link', and the output loop has this instead:

    if ( $post_title_link == false ) {
    	$title = '<span class="title">' . get_the_title() . '</span>';
    } elseif ( $post_title_link == true ) {
    	$title = '<a class="title" href="' . get_permalink() . '">' . get_the_title() . '</a>';
    }

    It hasn't broken anything, but it also hasn't changed anything either.. Am I missing something here?

  4. ZaLiTHkA
    Member
    Posted 2 years ago #

    Ok, back again.. Last post for now, promise. :) I got it working, but not the way I would like it to.

    I have no idea why, but setting the default value for 'post_title_link' to false and then setting it to true in the shortcode works. Problem with this is that any time my modified shortcode is used, unless the user explicitly sets post_title_link="true", it will not create a link.

    I can work with this for now, but I'm still open to any other suggestions.

  5. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    I don't recommend making any changes to the plugin itself since they will be overwritten when the plugin is updated.

    You should use an output filter to modify the post's output. You can pass your own attributes to the shortcode and see if that has a value before actually modifying it.

    Hope that helps (sorry for the delay, I only check these forums every so often)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.