0

At this moment I am developing a custom gallery which has a constant changing layout. Because of this, it's hard to write a loop file, cause depending on how many items the style keeps changing, meaning it flips arround the style depending on how many items are in the gallery.

So I was thinking of doing a part manually (the html part that is) (i am a terrible programmer) however, to query each post with an offset is kind of annoying, so i was thinking of adding a function with a query of 14 items (thats how many items should be shown) and store that within a function that i can call with a simple number (so for example display_post(2) which will show the second post ).

So before I reinvent the wheel, does wordpress have already such function? I know there is a lot available but sometimes you cant find the forest through the trees.

--edit--

Alright, let me rephrase this quickly, i am trying to write a function that retrieves a specific wpquery that i can match in my gallery frame.

<?php if (is_page ( array ( 'hotspots' , 'sleep' , 'interior' ) ) ) {  

    // beveiligingscheck voor het plaatsen van items

    $count_posts = 0 ; 

    if (is_page ( 'hotspots' ) ) {

        $type = 'trends';

        $count_posts = wp_count_posts( 'trends' )->publish ;

    }

    if ( $count_posts > 0 ) {

        function display_imagepost($type, $number) {

             $args = array(
                'post_type' => $type,
                'offset' => $number,
                'post_status' =>'publish',
                'posts_per_page' = 1
             );

            $item = new WP_Query ($args) ; 

            while ($item->have_posts() ) { 

                echo "<a href='".."'>";
                echo "<img src='".."'>";
                echo "</a>";

            }

       }

?>

<!-- HTML in the IF statement - Markup for the gallery -->

and then i am trying to call it like

<div class="element-row m-all t-all d-all">

    <?php display_imagepost($type, 1); ?>

</div>

The type is the post type i am adding to it, stored in the variable type, while the number should be the number of post i want via the query. Then it should generate the link and img (still need to seek that out). My original question was if such function already existed, but I figured i need to write it myself. Now this aint finnished yet (duh) but i could use the help, since i am struggling with this.

-- edit 2 --

The passing is correctly, i tested it. Getting closer, but seem to have an error in the function.

  • Your question is not very clear. Could you describe more precisely what you are trying to achieve (for instance sample desired output)? "Changing layout" sounds like you need css instructions depending on how many items there are in the gallery. – cjbj Jun 5 '17 at 10:34
  • @cjbj i altered my question and updated the post, my apologies. The css aint the problem, its the query to get it all loaded in within the function. – Dorvalla Jun 5 '17 at 10:43
  • If you want $number to contain the amount of posts to be returned by the query you must parse it to posts_per_page, not offset – cjbj Jun 5 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.