I’m making a child theme from this theme (limo) and I am trying to do two things without success, so here’s my questions:
- How can I get a permalink from a post_type?
As you can see on this demo (the “Our Works” part), I would like to get the link of this post. So you would click on this image/post title and it would open the post page. Using the get_permalink() function nothing happens.
The function is this:
function ccr_our_works() {
$labels = array(
'name' => __( 'Our works', 'codexcoder' ),
'singular_name' => __( 'Our work', 'codexcoder' ),
'add_new' => _x( 'Add New Work', 'codexcoder', 'codexcoder' ),
'add_new_item' => __( 'Add New Work', 'codexcoder' ),
'edit_item' => __( 'Edit Our Work', 'codexcoder' ),
'new_item' => __( 'New Our Work', 'codexcoder' ),
'view_item' => __( 'View Our Work', 'codexcoder' ),
'search_items' => __( 'Search Our works', 'codexcoder' ),
'not_found' => __( 'No Our works found', 'codexcoder' ),
'not_found_in_trash' => __( 'No Our works found in Trash', 'codexcoder' ),
'parent_item_colon' => __( 'Parent Our Work:', 'codexcoder' ),
'menu_name' => __( 'Works', 'codexcoder' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'description',
'taxonomies' => array(),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => null,
'menu_icon' => null,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'supports' => array(
'title', 'editor', 'thumbnail'
)
);
register_post_type( 'work', $args );
}
add_action( 'init', 'ccr_our_works' );
And I’m doing this to get the post link:
<!-- Slider items -->
<div class="carousel-inner">
<div class="item active">
<?php
$loop = new WP_Query('post_type=work&posts_per_page=4');
while ($loop->have_posts()) {
$loop->the_post();
?>
<div class="col-sm-3">
<figure>
<?php the_post_thumbnail(); ?>
<figcaption>
<h4><a href="<?php get_permalink(); ?>"><?php the_title(); ?></a></h4>
</figcaption>
</figure>
</div>
<?php } ?>
</div> <!-- /.active /.item -->
<div class="item">
<?php
$loop = new WP_Query('post_type=work&posts_per_page=4&offset=4');
while ($loop->have_posts()) {
$loop->the_post();
?>
<div class="col-sm-3">
<figure>
<?php the_post_thumbnail(); ?>
<figcaption>
<h4><a href="<?php get_permalink(); ?>"><?php the_title(); ?></a></h4>
</figcaption>
</figure>
</div>
<?php } ?>
</div> <!-- /.active /.item -->
</div> <!-- /.carousel-inner -->
<!--/.carousel -->
</div> <!-- /#work-slide -->
How can I do this?
- How can I build a page template to join all this post of a specific post_type in one page?
What I tried:
<?php
/*
Template Name: Our Works
*/
?>
<?php get_header(); ?>
<!-- begin colLeft -->
<div id="colLeft">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'post_type' => 'our_works',
'paged' => $paged
);
query_posts($args);
?>
<h1><?php the_title(); ?></h1>
<div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Read more â</a>
<br><br>
<?php endwhile; ?>
<?php if (function_exists("emm_paginate")) {
emm_paginate();
} ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Not found'); ?></p>
<?php endif; ?>
</div>
</div>
<!-- end colleft -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Any help? I would like to understand how to deal with this.
Come on.
1) Permalinks use
2) To your page, try this