• Hi, i am in a situation where im i need of getting the post id of my homepage but onto wordpress > dashboard > pages this current theme doesn’t have a home page. How can i get it?

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hello,

    Your home page displays the list of posts, so it doesn’t have any post ID. This is archive of your posts.

    Thread Starter salave

    (@salave)

    @chouby i now getting the picture, you brought up new idea as to why i was facing some problems. I wish to have my homepage into my pages. How can i do it?

    Moderator bcworkz

    (@bcworkz)

    In reading settings, for “Your homepage displays” option, select the static page option. Select your desired home page from the pages listed in the dropdown. Do the same for your desired posts page.

    Of course the pages need to exist before you can select them. For the posts page, it needn’t have any content, it can be a blank page with just the title. WP will populate it with your most recent posts. You should create a posts page even if you don’t intend to use it.

    If you still want a posts archive listing on your home page as a static page, you’ll need to alter your home page template code to display the desired posts, unless the Query Loop block in the page’s content will suffice.

    Thread Starter salave

    (@salave)

    I created an empty page with title “homepage.”

    I assigned it as homepage in reading settings, but checking it in Pages, its defined as front-page.

    Now the homepage hasn’t populated any posts.

    Home: https://sopriza.com/ to appear like: https://sopriza.com/category/family-and-community/

    Thread Starter salave

    (@salave)

    Tested with Query loop, adding in page, it shows the latest posts, but few posts with no style.

    Moderator bcworkz

    (@bcworkz)

    The lack of styling is likely because the block places content within a DOM element that your theme had not anticipated. Your theme’s CSS may need modification so its styles are applied whether posts are in a traditional archive listing or within a query loop block.

    Is your theme a “classic” type (.php templates) or “block” type (.html templates)? Placing a secondary query in the front page template could have posts appear as a traditional archive listing so you wouldn’t need to modify the CSS.

    Thread Starter salave

    (@salave)

    @bcworkz for sure I’ve been waiting for your reply, as i had left the homepage empty since yesterday.

    I attempted to copy the content.php to a new created page “front-page.php” but it also didn’t work. The way i will continue to do these trials, i know i would come up with something incorrect. Here is my theme, help me to make me work.

    Moderator bcworkz

    (@bcworkz)

    IMHO, as a developer, using query loop to display archive posts is kind of annoying. I don’t have nearly the control over it that I would have by using a custom query. My theme can then have complete control over content and appearance. There won’t be any block settings getting in the way of my theme’s styling.

    But custom queries are so “old skool”. Going forward, WP is all for blocks everywhere. You have a classic style theme, not a block theme, so I think a custom query is entirely appropriate. Here’s what you could do (the pagination part does get rather involved):

    Create whatever front page content you want that will appear over the post archive listing. Do not include a query loop.

    On /template-parts/content-page.php, between the main loop and sidebar sidebar area, add a conditional along the lines of

    if ( is_front_page()):
      // do stuff
    endif;

    For the “do stuff” part, make a custom query similar to the examples found for WP_Query class.

    Alter the loop code to output what you want for archive listings, making it a better fit for your theme so the desired CSS can be applied. You might start with a copy of the main loop code, but output an excerpt and no comments.

    For pagination, use paginate_links(). All other WP pagination functions are inappropriate for custom queries like this. Many of the examples you’ll find documenting paginate_links() use the $paged query var for which page to query for. I advise you do not do this. $paged belongs to the main query, not your custom query. Instead use your own unique paging query var. It can be passed as an URL query string, for example: https://example.com/?pg-num=3

    Then instead of 'paged' => $paged, for the query args, do this:
    'paged' => (int) $_GET['pg-num'],

    Thread Starter salave

    (@salave)

    <?php if ( is_front_page() ) : ?>
        Code
    <?php endif; ?>
    

    Do you remember the day you corrected syntax error which was shared for us to use on profile image alt? Now imagine me trying to create if ( $the_query->have_posts( . . except and pagination. It’s not simple thing for me

    Moderator bcworkz

    (@bcworkz)

    As much as I try, I cannot keep track of every forum member’s relative coding skill level. In any case, my answers are often tailored to not only address your specific question, but to also maybe provide information for others who might land here via search. If you don’t like my suggestion, feel free to ignore it ??

    If it’s a given that your home page be listed in the pages list table, there are really only two ways to list recent posts on such a page: template code or block code. Query loop block is nice because no coding is necessarily involved. But then you’re stuck with its limited options. And additional CSS may need to be developed for posts to be styled appropriately.

    Template code does require some PHP coding skills, but then your theme’s normal styling will be applied if you output HTML the same way your theme does with its index.php template.

    One way to decide which approach is best for you is where are you more comfortable with what limited coding skills you do have? CSS or PHP?

    Thread Starter salave

    (@salave)

    Most of the time i deal with pre-made PHP and CSS pages, so I guess you could say that my coding ability is little.

    If I understand this correctly, the homepage at the moment is an archive, and we occasionally exclude archives from indexing, so I needed my homepage to be prominently shown on a page.

    Once again, I believed that writing everything down on a page would make rewriting simpler, but that was not the case.

    It’s somehow a surprise how hard it was for me to use my limited coding skills to make it seem that way. I might give it a shot again later.

    • This reply was modified 1 year, 3 months ago by salave.
    Moderator bcworkz

    (@bcworkz)

    m

    the homepage at the moment is an archive, and we occasionally exclude archives from indexing, so I needed my homepage to be prominently shown on a page.

    It looks like you’ve reverted the setting back to latest posts, so yes, an archive. Exclude from indexing? As in search engine indexing? You could exclude it from indexing if you wanted to, but it seems counterproductive to exclude your homepage. It should be your most important page that you’d want indexed.

    I don’t understand “homepage…shown on a page”. It is a webpage, but not a WP page post type. Whether it’s a page post type or archive page doesn’t have anything to do with indexing. Do you mean search results page? (“page” can have so many different interpretations) Search ranking is not influenced by whether it’s an archive page or page post type. Ultimately it’s the quality of the content that matters, not how you and WP decides to organize and serve the page.

    I’m left being uncertain what you wanted to achieve here. I hope after some time for thought you will be able get there without too much effort. Best of luck.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Getting the Post ID’ is closed to new replies.