Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2879

    Hi,

    I hope all of You do well,

    Like in the topic, I just want to display list of posts in random order, which come from specific category. I decided to add Exec-PHP widget (which make me able to add executable php code to the particular page made in wordpress admin) and make, using wordpress admin, page and put there some code. I could do this just by using such simple code:

    <?php $recent = new WP_Query("showposts=10&orderby=rand");
    while($recent->have_posts()) : $recent->the_post(); ?>

    <li><a>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>

    But that’s not the point. I need to display those posts in way that newcast theme does.

    Can You help me ?

    The website is http://www.boogiestomp.info . Here You can see on the right there is “Kluby Taneczne” – this is the site i mentioned above.

    Thanks in Advance

    BR

    Maciej Kifer

    #39652

    Hey,

    check out the plugin directory: http://wordpress.org/extend/plugins/search.php?q=random+post+shortcode

    There are tons of plugins which allow you to display random posts via shortcode. You even don’t need Exec-PHP to use these plugins..

    #39653

    Thank You Sir. You’re obviously right but what if I would like to display those posts in graphic way that newcast generally does? i mean when basically open some category, you see post listed with pictures (post icons) and some text. How Can I do it with thing that is already done on my website? Here is link:

    http://boogiestomp.info/index.php/kluby-taneczne/

    Thanks in Advance

    MK

    #39654

    You can find the “category display code” in archive.php. The post loop begins with:

    if (have_posts()) :
    while (have_posts()) : the_post();

    You need some wp/php coding skills to display the posts like Newscast does. It’s not just a small code snippet that’s why I would use a widget or a plugin.

    To understand the wp loop a bit better you can have a look at this page: http://codex.wordpress.org/The_Loop

    #39655

    Thanks,

    I downloaded the “show-posts-shortcode” plugin and change some code, taking from the newcast. Now the show-posts-shortcode.php looks like this:

    function showMyPosts( $atts )
    {

    extract( shortcode_atts( array(
    'category' => '',
    'num' => '5',
    'order' => 'ASC',
    'orderby' => 'date',
    ), $atts) );

    $out = '';

    $query = array();

    if ( $category != '' )
    $query[] = 'category=' . $category;

    if ( $num )
    $query[] = 'numberposts=' . $num;

    if ( $order )
    $query[] = 'order=' . $order;

    if ( $orderby )
    $query[] = 'orderby=' . $orderby;

    $posts_to_show = get_posts( implode( '&', $query ) );

    echo '<div id="pozycja_klubow">';

    foreach ($posts_to_show as $post_to_show) {

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => '_prev_image_link','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    $permalink = get_permalink( $post_to_show->ID );

    echo '<div class="entry-previewimage rounded preloading_background">';
    echo $preview_image;
    echo '</div>';

    }
    echo '</div>';
    }

    add_shortcode('showposts', 'showMyPosts');

    So I added the:

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => '_prev_image_link','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    code and the display code:

    echo '<div class="entry-previewimage rounded preloading_background">';
    echo $preview_image;
    echo '</div>';

    Now it works almoust good, I only need to make those displayed posts icons as links. Right know (I dont know why) when I click the particular image its redirecting me to the same page. Maybe ‘permalink’ variable is being taken from the site instead of the post ?

    Any help will be appriecated,

    Thanks,

    MK

    #39656

    And the link to the example is:

    http://boogiestomp.info/index.php/kluby-taneczne/

    #39657

    Try to change:

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => '_prev_image_link','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    $permalink = get_permalink( $post_to_show->ID );

    to:

    $permalink = get_permalink( $post_to_show->ID );

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => 'permalink','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    If that doesn’t work you need to modify kriesi_post_thumb.php (located under newscast/framework/helper_functions a bit.

    Search for:

    // permalink
    if($display_link == 'permalink') $linkwrap[0] = '<a '.$link_attr_string.' href="'.get_permalink().'" title="'.get_the_title().'" >';

    and replace it with:

    // permalink
    if($display_link == 'permalink_custom') $linkwrap[0] = '<a '.$link_attr_string.' href="'.get_permalink( $post_to_show->ID ).'" title="'.get_the_title( $post_to_show->ID ).'" >';

    and change:

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => '_prev_image_link','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    $permalink = get_permalink( $post_to_show->ID );

    to:

    $permalink = get_permalink( $post_to_show->ID );

    $preview_image = kriesi_post_thumb($post_to_show->ID, array('size'=> array('M'),'display_link' => 'permalink_custom','linkurl'=>array ('L','_preview_big'),'wh'=>$k_option['custom']['imgSize']['M']));

    Hope this hack works :)

    #39658

    Yes, the second option with “modifying kriesi_post_thumb.php” works. I also added to shortcode plugin the line:

    echo $preview_image;

    to

    echo '<a href="'.$permalink.'">'.$preview_image.'</a>';

    It works fine :). Thank You – You’ve got good support.

    #39659

    Glad that I could help you :)

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Random Post listing in specific category but in newcast style’ is closed to new replies.