Forum Replies Created

Viewing 15 replies - 61 through 75 (of 128 total)
  • Hope it works, I think the first code is only for images uploaded to your WordPress images folder from your computer, and not ‘linked images from somewhere else’ (in the editor you have both options allowed).

    The second one will retrieve all the images in the post and it should work with all kind of images (uploaded plus linked).

    @erwin, in the <!--SNIPPET--> part you must insert this code :

    <?php $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images)));
    echo "<img src=\"{$firstImageSrc[0]}\" width=\"150\" height=\"150\" />"; ?>

    You can change the size, there is set to 150×150 px.
    If you want a more dynamic size, you should check the link I provided, there you can find some variations.

    Or, you can use this instead and add it a class to style it :

    <span class="myimage"><?php
    $szPostContent = $post->post_content;
    $szSearchPattern = '~<img [^\>]*\ />~';
    preg_match_all( $szSearchPattern, $szPostContent, $aPics );
    $iNumberOfPics = count($aPics[0]);
    if ( $iNumberOfPics > 0 ) {
    for ( $i=0; $i < $iNumberOfPics ; $i++ ) {
    echo $aPics[0][$i];
    };
    };
    ?></span>
    .myimage img{
    	max-width:yoursize;
    	max-height:yoursize;
    	}
    Forum: Plugins
    In reply to: WP_query issue
    Thread Starter dunkkan

    (@dunkkan)

    Solved with get_posts.

    Here you’ll find them out !

    I guess you could do something like :

    //strating the loop
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	        the_post();
    		?>
    //first div
    		<div class="firstdivimage">
    
    		<!--SNIPPET-->
    
    		</div>
    //second div
    		<div class="seconddivtext">
    
    		<?php the_title(); ?>
    		<?php the_content(); ?>
    
    		</div>
    //finishing
    		<?php endwhile;
    		endif;
    		?>

    and then in your CSS :

    .seconddivtext img{
    	display:none;
    	}

    You should write in the editor your page normally, import and add to it the images you want, and then, automatically, the template will split the images to one side and the text to another by its own.

    So by principle you don’t have to worry about nothing, just write your page in the editor as usual.

    I’m guessing your template is made to keep separated images and text, via php or css.

    What results do you obtain by now ?

    If you’re building the template, there’s some code snippets to use in order to get the image of a post/page in one side and the text in another one.

    Forum: Plugins
    In reply to: audio files in sidebar
    Thread Starter dunkkan

    (@dunkkan)

    I got it working, thanks to this thread.

    We need to paste that in functions.php :

    <?php function postfile() {
    	if ( $files = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'order' => 'ASC',
    		'orderby' => 'ID',
    		'post_mime_type' => 'application',)))
    	{
    		foreach( $files as $file ) {
    			$attachmenturl=wp_get_attachment_url($file->ID);
    			$file_title = $file->post_title;
    			echo '<a href="'.$attachmenturl.'">'.$file_title.'</a>';
    		}
    	} else {
    		echo "No podcasts found";
    	}
    }
    ?>

    You can remove the php statements if you have them already there.

    Then, anywhere in the desired template, for instance in sidebar.php, we write a get_posts call :

    <?php
    	 $posts = get_posts('category_name=podcasts&numberposts=8');
    	 foreach($posts as $post):
    	    setup_postdata($post);
    	?>
    	<?php the_title(); ?> | <?php postfile(); ?>
    	<?php endforeach; ?>

    That will give something like the 8 last posts in the “podcasts” category, displayed as title + link to play the podcast.

    Hope that helps.

    Hi guys, thanks very much for this approach but, how do I do the same for posts in certain category, “9” for exemple, or named “music” ?

    Here I only can work with a unique fixed post parent.

    I would need to retrieve all the children from a whole category.

    Forum: Plugins
    In reply to: audio files in sidebar
    Thread Starter dunkkan

    (@dunkkan)

    Hello, I made some progress with this code found in the Codex :

    <?php
    
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => 1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $post) {
    		setup_postdata($post);
    		the_title();
    		the_attachment_link($post->ID, false);
    	}
    }
    
    ?>

    With it, I got the link to the last uploaded attachment, anywhere in my template.

    But apparently it doesn’t allow to specify the desired category (I tried to set category and category_name in the array but then nothing appears), and it will take any last attachment :/

    Any ideas ? Thanks.

    Forum: Plugins
    In reply to: audio files in sidebar
    Thread Starter dunkkan

    (@dunkkan)

    anyone ? Still fighting that πŸ˜›

    Forum: Fixing WordPress
    In reply to: Tag Cloud

    Hello blob, if you got the word “tags” it means it’s ready to display them, all you have to do is write the tags in the post editor once you have wrote the post. The cloud is modificable and stylable, I think it displays about 40 tags by default.

    If you have some problem you could write it in the sidebar’s template directly, like this:

    <?php wp_tag_cloud(''); ?>

    ,under the other calls usually in a sidebar : calendar, categories, etc.

    Thread Starter dunkkan

    (@dunkkan)

    Ok it’s really easy :

    1. Locate this directory : wp-admin.
      As you have noticed, it is just next to wp-content, where you upload plugins and themes.
    2. Open it.
    3. Find wp-admin.css, and open it in a text editor, like Notepad++ (excellent open-source editor between 8/ ). Search for this lines, at the bottom of the file.
      div.ui-tabs-panel {
      	margin: 0 5px 0 120px;
      	padding: .5em .9em;
      	height: 10em;
      	overflow: auto;
      	border-width: 4px;
      	border-style: solid;
      }
    4. Increase the height of the div. I put 40em, which is perfect if you have about 30 categories.

    So the final result is …

    div.ui-tabs-panel {
    	margin: 0 5px 0 120px;
    	padding: .5em .9em;
    	height: 40em;
    	overflow: auto;
    	border-width: 4px;
    	border-style: solid;
    }

    Save it. Come back to your blog and refresh the admin screen.

    Thanks for assisting to this micro-tutorial. πŸ˜›

    I got it linking with the article (using the second code, and inside the loop):

    <a href="<?php the_permalink(); ?>"><?php $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
    $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images)));
    echo "<img src=\"{$firstImageSrc[0]}\" width=\"150\" height=\"150\" />"; ?></a>

    I resized the image to 150×150 pixels here (to change in a custom way). Hope that helps.

    Thread Starter dunkkan

    (@dunkkan)

    Thanks guys for all the answers, I’ll try it out.

    Here there’s a quite cool code but is still in a beta phase, and the author search for contributors.

    http://wordpress.org/support/topic/219641?replies=3

    This will take 5 posts, randomly, having the specified tag associated whit them.

    I hope I don’t forget anything. It should work in the sidebar.
    In case of problems, add <?php rewind_posts(); ?> just after calling the header in the template.

    <ul>
     <?php
     $rand_posts = get_posts('numberposts=5&tag=WHATEVER&orderby=rand');
     foreach( $rand_posts as $post ) :
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
    </ul>
Viewing 15 replies - 61 through 75 (of 128 total)