Display WP Gallery by default - wordpress

I'm creating a custom post type for creating gallery posts. One of the things I took out was the 'editor' section since I have my own uploader. Since the HTML editor is gone (can't use shortcodes now), is there a wp function which is the equivalent of the [gallery] shortcode?

As per the Codex recommendation for outputting the [gallery] shortcode content directly in a template file, I would use do_shortcode():
<?php do_shortcode( '[gallery]' ); ?>
You can even pass accepted parameters:
<?php do_shortcode( '[gallery columns="4" size="medium"]' ); ?>

Got it. Here's the code for anyone else who wants to do the same thing. Throw this baby in your theme template file and try it out.
$images = get_children(array('post_parent'=>$post->ID, 'post_type'=>'attachment', 'post_mime_type' => 'image'));
foreach($images as $image){
echo wp_get_attachment_link($image->ID);
}

You can use the wordpress function make for this purpose
gallery_shortcode(array('orderby'=>ID));
by sure to call this after you setup the post

Related

How to Display Page Excerpts in WordPress Themes

my search result doesn't show excerpt content of pages on WordPress it only show for the post
advise please
Taken from http://codex.wordpress.org/Function_Reference/add_post_type_support
<?php
add_action('init', 'my_custom_init');
function my_custom_init() {
add_post_type_support( 'page', 'excerpt' );
}
?>
Adds excerpt support for the 'Page' post type. Paste this code into your themes functions.php file (ref http://codex.wordpress.org/Functions_File_Explained)

the_post_thumbnail not working with me

I'm not super familiar with wordpress, but I've been working on getting my layout written as a theme so I can use the wordpress platform. For some reason I can't get the_post_thumbnail function working.
so when use this
the_post_thumbnail(array(100,100));
its show me this error
Illegal offset type in
Have you enabled thumbnails in the functions.php?
In your functions.php, you should add this in order to enable featured thumbnails:
add_theme_support( 'post-thumbnails' );
And then call inside your loop, or inside your while:
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large', true);
echo $image_url[0];
?>
It will return your featured image URL and then you can echo the $image_url[0] wherever you want.

Create a wordpress page with archives of a category

I'm a bit stumped on this one. I'd like to create a page that is an archive of all posts of a certain category - and show excerpts. However, Reading through the Wordpress docs, they say a page cannot be a post or associated with categories.
So, I'm now wondering if this is possible or if there is a work around. I'd really like to put this on a page as I'd like to have a custom sidebar as well. Is this possible with a custom page template? Any other ways this can be done that I am not thinking of?
Thanks!
You can add this function to functions.php and then you can call it from any page template.
If you need to create a new page template for the sidebar.
FTP, download page.php
rename page.php to page-custom.php (custom can be anything, just make sure its page-whatever.php
In the page-custom.php
Replace the comments section with (Custom Template Name can be anything you want)
/**
* Template Name: Custom Template Name
*
*/
replace the loop in your new template with a call to get_posts_custom('catSlug');
then add this to your functions.php
if(!function_exists('get_posts_custom')){
function get_posts_custom($catSlug){
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => $catSlug,
'ignore_sticky_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<article class="post">
<time class="date"><?php the_time('m.d.y') ?></time>
<p><strong><?php the_title(); ?></strong>
<?php the_excerpt(); ?>
</p>
</article>
<?php
endwhile;
}
wp_reset_query();
}
}
Reference http://codex.wordpress.org/Class_Reference/WP_Query
I didn't fully test the function, but I am using a modified version of the same code. Mine doesn't filter on the category slug, so that may need tweaking, but I did test to make sure it didnt break functions.php
Create a page, lipsum for example.
Create a PHP file with the page-[the title].php, page-lipsum.php for this example.
Write your loop in that file.
FTP that file to the directory of your theme.
When you go to the URL for that page, the results should be what you're looking for.

Pulling all Wordpress pages into one page with page templates

I would like to be able to pull all of the pages from my custom theme into one page template, but still allow all of the pages to be displayed according to the selected page template.
In other words, if I have a page template called 'Main' where I pull all of the page data into, and I create a page called 'Home', I would like this page to display on the 'Main' template according to the page template I have selected for the 'Home' page. Is this possible to do?
Thanks,
JW
Alright, so I am going to answer my own question here. I did some research on my own and modified some code from an tutorial to Ajaxify a theme. What needs to happen is this.
In your page.php file, or whatever template you want to use as your main page template, add this.
<?php query_posts( array('post_type'=>'page', 'posts_per_page' => 1000, 'orderby' => 'menu_order', 'order' => 'ASC') ); ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
<?php
global $post;
$slug = $post->post_name;
locate_template(
array(
"template-$slug.php",
'template-main.php'
), true
);
?>
<?php endwhile; endif; ?>
Then add your page templates to the theme, and name according to the page slug i.e. template-about.php, or template-home.php. You can then have all of your content displayed dynamically in a one page site and be able to use the default Wordpress pages. I hope I was clear on this, and if not, feel free to let me know, and I'll do my best to clarify.
use in all your page templates this:
include 'page.php';
and then in page.php you can use this:
if (is_page_template('page_temp_one.php')) { ... }

How to show tag/skill type to a dynamic post in Wordpress theme Classica

I use this theme:
http://demo.themezilla.com/?theme=classica
Under the "recent projects" i want each posted portfolio post to display what kind of tag/skill-type it is connected to. This can be checked in the wp-admin page when you create a new portfolio post. I don't know what function i need to write in php to make this work.
Is there any easy way to solve this like when you show a posts excerpt?
<?php the_excerpt(); ?
I think you can use like this.
<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
If it's stored as a custom variable (appears below the post content when editing it in the admin panel), you can usually access it like so:
get_post_meta($post->ID, 'key_name_here', true);
Check out the get_post_meta() Code Page for more details on the function.
Use get_the_term_list() to get the skill-type and strip_tags() to remove the links
$terms = get_the_term_list( $post->ID,'skill-type', '', ', ','' );
$terms = strip_tags( $terms );

Resources